Tensorboard 在 TF2.0 中显示没有 keras.fit 和估计器的标量
Tensorboard displaying scalar without keras.fit nor estimator in TF2.0
我已阅读 TF 2.0 教程:Using TensorBoard with other methods
然后我写了这个简单的代码但似乎不起作用:
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
我得到(在浏览器中):
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.
我是不是漏掉了什么?
自己回答:
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)
有效!但是,我找不到任何合适的文档。
我已阅读 TF 2.0 教程:Using TensorBoard with other methods 然后我写了这个简单的代码但似乎不起作用:
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
我得到(在浏览器中):
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.
我是不是漏掉了什么?
自己回答:
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)
有效!但是,我找不到任何合适的文档。