用tf.summary记录日志,然后tensorboard加载,浏览器中查看
#声明要查看的标量
tf.summary.scalar("loss", loss)
tf.summary.scalar("test_loss", test_loss)
merge_summary = tf.summary.merge_all()
tf_config = tf.ConfigProto()
tf_config.gpu_options.allow_growth=True
with tf.Session(config=tf_config) as sess:
sess.run(init)
#声明writer,指定日志目录,图结构
writer = tf.summary.FileWriter("tf.log", sess.graph)
coord = tf.train.Coordinator()
while not coord.should_stop():
try:
step += 1
sess.run([loss, test_loss, optimizer])
#写入文件
merge_result = sess.run(merge_summary)
writer.add_summary(merge_result, step)
except tf.errors.OutOfRangeError:
coord.request_stop()
tensorboard --logdir ./tf.log/