1、add saclar and histogram
tf.summary.scalar('mean', mean)
tf.summary.histogram('histogram', var)
2、 sess-op
merged = tf.summary.merge_all()
3、writer init
train_writer = tf.summary.FileWriter(FLAGS.summaries_dir + '/train',
sess.graph)
4、sess run & write to file
summary, acc = sess.run([merged, accuracy], feed_dict=feed_dict(False))
test_writer.add_summary(summary, i)
举例:
import tensorflow as tf k = tf.placeholder(tf.float32) # Make a normal distribution, with a shifting mean
mean_moving_normal = tf.random_normal(shape=[1000], mean=(5*k), stddev=1)
# Record that distribution into a histogram summary
tf.summary.histogram("normal/moving_mean", mean_moving_normal) # Setup a session and summary writer
sess = tf.Session()
writer = tf.summary.FileWriter("/tmp/histogram_example") summaries = tf.summary.merge_all() # Setup a loop and write the summaries to disk
N = 400
for step in range(N):
k_val = step/float(N)
summ = sess.run(summaries, feed_dict={k: k_val})
writer.add_summary(summ, global_step=step)
查看
tensorboard --logdir=/tmp/histogram_example
https://tensorflow.google.cn/guide/tensorboard_histograms
https://tensorflow.google.cn/guide/summaries_and_tensorboard