【问题标题】:Using TFX for designing image piplines使用 TFX 设计图像管道
【发布时间】:2019-04-18 03:48:23
【问题描述】:

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

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

【问题讨论】:

  • 您到底希望该管道做什么,因为据我了解,与其他数据集不同,图像数据集将仅包含像素。

标签: tensorflow tfx


【解决方案1】:

是的,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 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

【讨论】:

  • outputs[LABEL_KEY] = outputs[LABEL_KEY]这行有什么用。那只是一个无操作,什么都不做,不是吗?
猜你喜欢
  • 2020-12-08
  • 2019-11-29
  • 1970-01-01
  • 1970-01-01
  • 2021-07-31
  • 1970-01-01
  • 2019-10-31
  • 2022-06-13
  • 2021-10-26
相关资源
最近更新 更多