I have read TF 2.0 tutorial: Using TensorBoard with other methods Then I wrote this simple code but seems not working:
import tensorflow as tf
train_loss = tf.keras.metrics.Mean('train_loss', dtype=tf.float32)
test_loss = tf.keras.metrics.Mean('test_loss', dtype=tf.float32)
train_summary_writer = tf.summary.create_file_writer('logs/tr')
test_summary_writer = tf.summary.create_file_writer('logs/ts')
for ep in range(1000):
train_loss(1*ep) # here I just want to display 1*ep...
test_loss(2*ep)
tf.summary.scalar('trloss', train_loss.result(), step=ep)
tf.summary.scalar('tsloss', test_loss.result(), step=ep)
%tensorboard --logdir logs
I get (in browser):
No scalar data was found.
Probable causes:
You haven’t written any scalar data to your event files.
TensorBoard can’t find your event files.
Did I miss something?
Answer by myself:
with train_summary_writer.as_default():
tf.summary.scalar('trloss', train_loss.result(), step=ep)
with test_summary_writer.as_default():
tf.summary.scalar('tsloss', test_loss.result(), step=ep)
It works! But, I couldn't find any proper documentation for this.