Search code examples
tensorflowtensorboard

How to visualize a tensor summary in tensorboard


I'm trying to visualize a tensor summary in tensorboard. However I can't see the tensor summary at all in the board. Here is my code:

        out = tf.strided_slice(logits, begin=[self.args.uttWindowSize-1, 0], end=[-self.args.uttWindowSize+1, self.args.numClasses],
                               strides=[1, 1], name='softmax_truncated')
        tf.summary.tensor_summary('softmax_input', out)

where out is a multi-dimensional tensor. I guess there must be something wrong with my code. Probably I used the tensor_summary function incorrectly.


Solution

  • What you do is you create a summary op, but you don't invoke it and don't write the summary (see documentation). To actually create a summary you need to do the following:

    # Create a summary operation
    summary_op = tf.summary.tensor_summary('softmax_input', out)
    
    # Create the summary
    summary_str = sess.run(summary_op)
    
    # Create a summary writer
    writer = tf.train.SummaryWriter(...)
    
    # Write the summary
    writer.add_summary(summary_str)
    

    Explicitly writing a summary (last two lines) is only necessary if you don't have a higher level helper like a Supervisor. Otherwise you invoke

    sv.summary_computed(sess, summary_str)
    

    and the Supervisor will handle it.

    More info, also see: How to manually create a tf.Summary()