Search code examples
tensorflowtensorboard

TensorFlow, TensorBoard: No scalar data was found


I'm trying to figure out how to operate tensorboard.

I looked at the demo here:

https://www.tensorflow.org/code/tensorflow/examples/tutorials/mnist/mnist_with_summaries.py

It runs well on my laptop.

Much of it makes sense to me.

So, I wrote a simple tensorflow demo:

# tensorboard_demo1.py

import tensorflow as tf

sess = tf.Session()

with tf.name_scope('scope1'):
  y1 = tf.constant(22.9) * 1.1
  tf.scalar_summary('y1 scalar_summary', y1)

train_writer = tf.train.SummaryWriter('/tmp/tb1',sess.graph)

print('Result:')
# Now I should run the compute graph:
print(sess.run(y1))

train_writer.close()

# done

It seems to run okay.

Next I ran a simple shell command:

tensorboard --log /tmp/tb1

It told me to browse 0.0.0.0:6006

Which I did.

The web page tells me:

No scalar data was found.

How do I enhance my demo so that it logs a scalar-summary which tensorboard will show me?


Solution

  • You must call train_writer.add_summary() to add some data to the log. For example, one common pattern is to use tf.merge_all_summaries() to create a tensor that implicitly incorporates information from all summaries created in the current graph:

    # Creates a TensorFlow tensor that includes information from all summaries
    # defined in the current graph.
    summary_t = tf.merge_all_summaries()
    
    # Computes the current value of all summaries in the current graph.
    summary_val = sess.run(summary_t)
    
    # Writes the summary to the log.
    train_writer.add_summary(summary_val)