如何总结在多个小批量上计算的损失

如何总结在多个小批量上计算的损失

本文介绍了使用 tensorboard 时,如何总结在多个小批量上计算的损失?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Tensorboard 来可视化验证样本上损失的演变.但是验证集太大,无法在一个小批量中计算.因此,为了计算我的验证损失,我必须在覆盖验证集的几个小批量上多次调用 session.run.然后我总结每个小批量的损失(在 python 中)以获得完整的验证损失.

I would like to use Tensorboard to visualize the evolution of the loss over a validation sample. But the validation set is too large to compute in one minibatch. Therefore, to compute my validation loss, I have to call session.run several times over several minibatches covering the validation set. Then I sum the loss (in python) of each minibatches to obtain the full validation loss.

我的问题是 tf.scalar_summary 似乎必须附加到 tensorflow 节点.但我需要以某种方式将它附加"到多次 session.run 运行的节点值的总和.

My problem is that tf.scalar_summary seems to have to be attached to a tensorflow node. But I would need to somehow "attach" it to the sum of the values of a node over several run of session.run.

有没有办法做到这一点?也许通过直接总结包含小批量损失总和的python浮点数?但是我没有在文档中看到一种为张量板总结"计算之外的 python 值的方法.文档操作方法"部分中的示例仅涉及可在对 session.run 的单次调用中计算的损失.

Is there a way to do that? Maybe by directly summarizing the python float that contains the sum of the minibatch losses? But I have not seen in the docs a way to "summarize" for tensorboard a python value that is outside of a computation. The example in the "How-To" section of the doc is only concerned with losses that can be computed in a single call to session.run.

推荐答案

您可以添加在每次 sess.Run 调用时更新的 Variable 并具有摘要跟踪变量的值.

You could add a Variable that is updated on each sess.Run call and have the summary track the value of the Variable.

这篇关于使用 tensorboard 时,如何总结在多个小批量上计算的损失?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 10:06