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

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

问题描述

我很好奇 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() 操作.例如,您有以下设置:

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.

上面的代码为每个图像编写了一个单独的摘要,因此您的日志将包含所有图像,但它们不会在 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()

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

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