【问题标题】:Image summaries with TensorFlow's Dataset API使用 TensorFlow 的数据集 API 的图像摘要
【发布时间】:2018-04-30 22:05:17
【问题描述】:

我正在使用TensorFlow's Dataset API 来加载和预处理图像。我想将预处理图像的摘要添加到 Tensorboard。

推荐的方法是什么?

到目前为止,我的代码如下所示:

def get_data():
  dataset = FixedLengthRecordDataset(...)
  dataset = dataset.map(dataset_parser, ...)
  if is_training:
    dataset = dataset.map(preprocess_for_train, ...)
  # Do shuffling, batching...
  return dataset

def preprocess_for_train(image, label):
  # Do preprocessing...
  image = tf.image.random_flip_left_right(image)
  # Add summary
  tf.summary.image('preprocessed_image', tf.expand_dims(image, 0))
  return image, label

preprocess_for_train 内,我的图像列在SUMMARIES 集合中,但在返回外部函数时,它不再是图形的一部分。我认为这是因为map 使用了不同的线程,因此引用了tf.Graph 的不同实例。

由于这不起作用,我还有哪些其他选项可以在 Tensorboard 中显示我的图像?

【问题讨论】:

    标签: api tensorflow dataset summary tensorboard


    【解决方案1】:

    我发现了一个技巧,可以使用我的迭代器的输出将预处理的图像添加到 Tensorboard:

    train_dataset = get_data()
    iterator = Iterator.from_structure(train_dataset.output_types, train_dataset.output_shapes)
    # Batch consists of [image, label]
    next_batch = iterator.get_next()
    tf.summary.image('preprocessed_image', next_batch[0])
    

    但是,这将在运行 summary_op 时第二次调用 next_batch。它有助于仅调试图像预处理,但它不是真正训练的解决方案。此外,只能观察到完全预处理的图像,而不是中间预处理阶段。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-01
      • 1970-01-01
      • 2021-12-14
      • 2018-05-11
      • 1970-01-01
      • 2014-04-14
      • 2019-04-09
      • 2019-08-20
      相关资源
      最近更新 更多