如何平均多个批次的摘要? [英] How to average summaries over multiple batches?

查看:25
本文介绍了如何平均多个批次的摘要?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一堆摘要定义如下:

Assuming I have a bunch of summaries defined like:

loss = ...
tf.scalar_summary("loss", loss)
# ...
summaries = tf.merge_all_summaries()

我可以每隔几步对训练数据评估 summaries 张量,并将结果传递给 SummaryWriter.结果将是嘈杂的摘要,因为它们仅针对一批进行计算.

I can evaluate the summaries tensor every few steps on the training data and pass the result to a SummaryWriter. The result will be noisy summaries, because they're only computed on one batch.

但是,我想计算整个验证数据集的摘要.当然,我不能将验证数据集作为单个批次传递,因为它太大了.因此,我将获得每个验证批次的摘要输出.

However, I would like to compute the summaries on the entire validation dataset. Of course, I can't pass the validation dataset as a single batch, because it would be too big. So, I'll get summary outputs for each validation batch.

有没有办法对这些摘要进行平均,使其看起来好像是在整个验证集上计算的?

Is there a way to average those summaries so that it appears as if the summaries have been computed on the entire validation set?

推荐答案

在 Python 中对您的度量进行平均,并为每个均值创建一个新的 Summary 对象.这是我所做的:

Do the averaging of your measure in Python and create a new Summary object for each mean. Here is what I do:

accuracies = []

# Calculate your measure over as many batches as you need
for batch in validation_set:
  accuracies.append(sess.run([training_op]))

# Take the mean of you measure
accuracy = np.mean(accuracies)

# Create a new Summary object with your measure
summary = tf.Summary()
summary.value.add(tag="%sAccuracy" % prefix, simple_value=accuracy)

# Add it to the Tensorboard summary writer
# Make sure to specify a step parameter to get nice graphs over time
summary_writer.add_summary(summary, global_step)

这篇关于如何平均多个批次的摘要?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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