derek
derek

Reputation: 10207

TensorBoard does not show scalars

I am playing TensorBoard and cannot make a simple example work. The computation is simply adding two constants.

import tensorflow as tf

sess = tf.Session()

a = tf.constant(1, name = "const1")
b = tf.constant(10, name = "const2")
c = a + b

asum = tf.summary.scalar("g1" , a)
bsum = tf.summary.scalar("g2",  b)
csum = tf.summary.scalar("gsum", c)

merged = tf.summary.merge_all()


train_writer = tf.summary.FileWriter('.\logs',sess.graph)

summary, _ = sess.run([merged, c])

train_writer.add_summary(summary, 0)

Then I compiled it first:

>python filename.py

everything looks good.

Then :

>tensorboard --logdir=".\logs" --inspect

The weird thing occurred: there were no scalars!

Found event files in:
.\logs

These tags are in .\logs:
audio -
histograms -
images -
scalars -
tensor -
======================================================================

Event statistics for .\logs:
audio -
graph
   first_step           0
   last_step            0
   max_step             0
   min_step             0
   num_steps            1
   outoforder_steps     []
histograms -
images -
scalars -
sessionlog:checkpoint -
sessionlog:start -
sessionlog:stop -
tensor -
======================================================================

Version of TensorFlow is: 1.2.1

Python version: 3.5.2

Upvotes: 2

Views: 4283

Answers (2)

Changing the order of the sess.run worked for me when I faced the exact same issue.

_, summary = sess.run([c, merged])

Upvotes: 0

nessuno
nessuno

Reputation: 27042

The FileWriter object buffers the event it collects and then, once the buffer is full, write them on the disk. A single call of the FileWriter object isn't enough the fill the buffer, thus you to force the FileWriter to flush the buffer and write the content on the disk. To do that, just call .close() after the add_summary operation.

train_writer.add_summary(summary, 0)
train_writer.close()

This will close the train_writer object and you can't use it anymore.

If you, instead, want to just flush the buffer without closing the file, you can use the .flush() method.

Upvotes: 3

Related Questions