Search code examples
tensorflowtensorboard

there is no graph with tensorboard


I am reading a book on Tensorflow and I find this code:

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import tensorflow as tf

const1 = tf.constant(2)
const2 = tf.constant(3)
add_opp = tf.add(const1,const2)
mul_opp = tf.mul(add_opp, const2)

with tf.Session() as sess:
    result, result2 = sess.run([mul_opp,add_opp])
    print(result)
    print(result2)

    tf.train.SummaryWriter('./',sess.graph)

so it is very simple, nothing fancy and it is supposed to produce some output that can be visualized with tensorboard.

So I run the script, it prints the results but apparently SummaryWriter produces nothing.

I run tensorboard -logdir='./' and of course there is no graph. What could I be doing wrong?

And also how do you terminate tensorboard? I tried ctrl-C and ctrl-Z and it does not work. (also I am in a japanese keyboard so there is no backslash just in case)


Solution

  • The tf.train.SummaryWriter must be closed (or flushed) in order to ensure that data, including the graph, have been written to it. The following modification to your program should work:

    writer = tf.train.SummaryWriter('./', sess.graph)
    writer.close()