python - 我如何使用 tensorflow-transform 来处理图像,例如定义一个操作来降低图像的平均值
问题描述
如何使用 tensorflow-transform 来降低图像的平均值并使其在服务期间也能正常工作
解决方案
如果我正确理解你的问题,你想减少图像的平均值,即你想将图像从颜色转换为灰度(将像素的值除以 255,因此它们的平均值将减少)
我们可以将其定义为 Tensorflow 操作,tf.divide(outputs[key], 255)
在preprocessing_fn
中Tensorflow Transform
,以便这些更改可以在训练期间和服务中应用。你可以试试 Tensorflow 2.0 Alpha,这样就不需要创建会话了。
def preprocessing_fn(inputs):
"""Preprocess input columns into transformed columns."""
# Since we are modifying some features and leaving others unchanged, we
# start by setting `outputs` to a copy of `inputs.
outputs = inputs.copy()
# Convert the Image from Color to Grey Scale.
# NUMERIC_FEATURE_KEYS is the names of Columns of Values of Pixels
for key in NUMERIC_FEATURE_KEYS:
outputs[key] = tf.divide(outputs[key], 255)
outputs[LABEL_KEY] = outputs[LABEL_KEY]
return outputs
让我知道这是否回答了您的问题。
推荐阅读
- python - python中的键盘输入数据类型
- oracle - 在 oracle 中,如果另一个存储过程(在第一个过程中被调用)失败,存储过程是否无法进一步执行
- tomcat - ApacheTomcat - 301 重定向
- java - javax.net.ssl.SSLPeerUnverifiedException:对等点仅在生产服务器上未经过身份验证
- arrays - 如何实现对哈希数组的所有可能修改
- android - UnhandledPromiseRejectionWarning:错误:ENOSPC:设备上没有剩余空间,请观看
- maven - 无法让某些功能文件标签通过 TeamCity 运行
- python-install - 即使没有将 python 3.7 和启动器添加到路径中,也可以在命令行中打开 python 解释器
- javascript - Issue while converting array from one format to another
- service - UDS SID2E & SID22