Search code examples
tensorflowdeep-learningtensorboard

TensorFlow: How to use tf.train.SummaryWriter inside supervisor.loop (0.12.0rc1)


I am using tf.train.Supervisor to manage my session. I am already using the summary_writer in the supervisor to write some summaries. I would however, at other intervals, like to write another set of summaries. As fare as I can see the easiest way is to use a supervisor.loop. What I was is basically:

Pseudo code:

summary_merged_valid = tf.summary.merge(summary_ops_valid)
valid_writer = tf.train.SummaryWriter(logdir + '/valid')
global_step = slim.get_or_create_global_step()

...

config = tf.ConfigProto(allow_soft_placement=True)
with sv.managed_session(config=config) as sess:

    ...

    sv.loop(validation_interval,
        valid_writer.add_summary,
        (summary_merged_valid, global_step)
        )

How should I go about this?


Solution

  • You can also provide your own summaries to Supervisor using

    sv.summary_computed(sess, summary, global_step)
    

    manually. One interesting thing that doesn't seem to be advertised too much is that you can group summaries into collections like so:

    tf.summary.scalar('learning_rate', p_lr, collections=['train'])
    tf.summary.scalar('loss', t_loss, collections=['train', 'test'])
    s_training = tf.summary.merge_all('train')
    

    and then only write the train variables by fetching s_training and giving it to the the above function.