使用 TFX 设计图像管道



在阅读TFX的文档时,特别是在与数据预处理相关的部分,我认为流水线设计更适合分类特征。

我想知道TFX是否也可以用于涉及图像的管道。

是的,TFX也可用于涉及图像的管道。

特别是,据我所知,在与预处理数据相关的部分中,Tensorflow Transform中没有内置函数。

但是转换可以使用Tensorflow Ops进行。例如,可以使用 tf.image 完成图像增强,依此类推。

图像

转换的示例代码,即将图像从彩色转换为灰度,通过将每个像素的值除以 255,使用 Tensorflow 变换如下所示:

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 list of names of Columns of Values of Pixels
  for key in NUMERIC_FEATURE_KEYS:
    outputs[key] = tf.divide(outputs[key], 255)
  outputs[LABEL_KEY] = inputs[LABEL_KEY]
  return outputs

最新更新