gpt4 book ai didi

api - 使用 TensorFlow 的数据集 API 进行图像摘要

转载 作者:行者123 更新时间:2023-12-03 17:36:29 32 4
gpt4 key购买 nike

我正在使用 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 中显示我的图像?

最佳答案

我找到了一个 hack 方法,可以使用迭代器的输出将预处理后的图像添加到 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。它有助于调试图像预处理,但它不是真正训练的解决方案。此外,只能观察到完全预处理的图像,而不是中间预处理阶段。

关于api - 使用 TensorFlow 的数据集 API 进行图像摘要,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47345394/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com