Reputation: 41029
I'm following a simple "Hello, World" tutorial on TensorFlow and am trying to use TensorBoard to show the machine learning loss over multiple iterations of the gradient descent loss.
I think I followed everything correctly in my Jupyter (IPython) notebook, but I don't think the events are being generated saved to the file for TensorBoard to visualize.
Here is my code:
summary_y = tf.summary.scalar('output', y)
summary_writer = tf.summary.FileWriter('log_simple_stats')
sess.run(tf.initialize_all_variables())
for i in range(100):
summary_str = sess.run(summary_y)
summary_writer.add_summary(summary_str, i)
sess.run(train_step)
When I then check out TensorBoard, there is only one point. There should be a graph with a curve.
I also looked at my output file in the directory. It seems that not much has been written to the output file (only 84 bytes):
-rw-r--r-- 1 user.name group 84 Oct 29 13:00 events.out.tfevents.1509307239.mymacbookpro.local
What can I do to have TensorBoard show the events?
Upvotes: 1
Views: 1679
Reputation: 41029
In the code, the FileWriter needs to be closed so that all the data is flushed out. If the code is run as a script, the file will be closed when the script ends. However, since in this case the code is run in Jupyter, the Python process will continue to run even after that code block is completed. Thus, you have to add a close()
statement like so:
summary_y = tf.summary.scalar('output', y)
summary_writer = tf.summary.FileWriter('log_simple_stats')
sess.run(tf.initialize_all_variables())
for i in range(100):
summary_str = sess.run(summary_y)
summary_writer.add_summary(summary_str, i)
sess.run(train_step)
summary_writer.close() # <--- Add this line!
Once that is done, TensorBoard will show the effect of the decreasing loss over the number of iterations:
The output events file will also be larger:
-rw-r--r-- 1 user.name group 4638 Oct 29 13:02 events.out.tfevents.1509307332.mymacbookpro.local
Upvotes: 1