Melinda Weathers
Melinda Weathers

Reputation: 2689

Tensorflow - Conditionally writing summary to tensorboard

I am using Tensorboard to visualize Tensorflow runs, and I would like to have a summary graph that only writes a value once per epoch.

I want to do something like this:

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)

I have the feeling that I need to do something other than tf.merge_all_summaries() and manage the sets of summaries separately, but I'm not sure how that would work.

Upvotes: 2

Views: 1058

Answers (1)

user1523170
user1523170

Reputation: 393

One way to do this is to add a custom Summary protobuf to the SummaryWriter. At the end of each epoch (outside of session/graph), you can add something like:

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

This, however, requires the value (epoch_total) to be returned via the tensorflow graph (sess.run). Also, I'm not sure if this is the best way to do something like this, however you do see this used in TF examples, e.g. here and here.

Upvotes: 1

Related Questions