如何使用 tensorflow-transform 来降低图像的平均值并使其在服务期间也能正常工作
问问题
262 次
1 回答
0
如果我正确理解你的问题,你想减少图像的平均值,即你想将图像从颜色转换为灰度(将像素的值除以 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
让我知道这是否回答了您的问题。
于 2019-05-09T09:49:41.163 回答