Tensorflow - 有条件地将摘要写入张量板

Tensorflow - Conditionally writing summary to tensorboard

我正在使用 Tensorboard 来可视化 Tensorflow 运行,我想要一个每个 epoch 只写入一次值的摘要图。

我想做这样的事情:

with graph.as_default():
    tf_ending = tf.placeholder(tf.bool)
    tf.scalar_summary('Loss', loss) # Some summaries are written every time
    if tf_ending:
        # This summary should only get written sometimes.
        tf.scalar_summary('Total for Epoch', epoch_total)

我觉得我需要做一些 tf.merge_all_summaries() 以外的事情并单独管理摘要集,但我不确定这将如何工作。

执行此操作的一种方法是将自定义摘要 protobuf 添加到 SummaryWriter。在每个 epoch 的末尾(session/graph 之外),您可以添加如下内容:

summary = tf.Summary()
summary.value.add(tag='Total for Epoch',simple_value=epoch_total)
summary_writer.add_summary(summary, train_step)

但是,这需要通过张量流图 (sess.run) 返回值 (epoch_total)。另外,我不确定这是否是执行此类操作的最佳方法,但是您确实在 TF 示例中看到了它,例如here and here