如何在Tensorflow中使用image_summary查看不同批次的图像? [英] How to use image_summary to view images from different batches in Tensorflow?

查看:245
本文介绍了如何在Tensorflow中使用image_summary查看不同批次的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对image_summary的工作方式感到好奇。有一个名为max_images的参数,该参数控制要显示多少个图像。但是,摘要似乎只显示一批图像。如果我们使用max_iamges的较大值,则将只查看批处理中的更多图像。我有办法查看每批中的一张图像吗?

I am curious about how image_summary works. There is a parameter called max_images, which controls how many images would be shown. However it seems the summary only displays images from one batch. If we use bigger value of max_iamges, we will just view more images from the batch. Is there a way I can view for example one image from each batch?

推荐答案

要查看每批中的一张图像,您需要来获取 tf.image_summary() op每次您运行一个步骤时。例如,您具有以下设置:

To view one image from each batch, you need to fetch the result of the tf.image_summary() op every time you run a step. For example, it you have the following setup:

images = ...
loss = ...
optimizer = ...

train_op = optimizer.minimize(loss)
init_op = tf.initialize_all_variables()
image_summary_t = tf.image_summary(images.name, images, max_images=1)

sess = tf.Session()
summary_writer = tf.train.SummaryWriter(...)
sess.run(init_op)

...您可以设置训练循环以每次迭代捕获一张图像,如下所示:

...you could set up your training loop to capture one image per iteration as follows:

for _ in range(10000):
    _, image_summary = sess.run([train_op, image_summary_t])
    summary_writer.add_summary(image_summary)

请注意,捕获每个批次的摘要可能效率不高,您应该只捕获

Note that capturing summaries on each batch might be inefficient, and you should probably only capture the summary periodically for faster training.

编辑:上面的代码为每个图像分别编写了一个摘要,因此您的日志将包含所有im时代,但它们不会在TensorBoard中全部显示出来。如果要合并汇总以可视化多个批次中的图像,可以执行以下操作:

The above code writes a separate summary for each image, so your log will contain all of the images, but they will not all be visualized in TensorBoard. If you want to combine your summaries to visualize images from multiple batches, you could do the following:

combined_summary = tf.Summary()
for i in range(10000):
    _, image_summary = sess.run([train_op, image_summary_t])
    combined_summary.MergeFromString(image_summary)
    if i % 10 == 0:
        summary_writer.add_summary(combined_summary)
        combined_summary = tf.Summary()

这篇关于如何在Tensorflow中使用image_summary查看不同批次的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆