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
本文详细介绍了如何在TensorFlow中使用Summary记录训练过程中的各种统计数据,并通过TensorBoard进行可视化展示。从简单的标量记录到复杂的直方图生成,再到Session操作整合,最后通过Writer将数据写入文件供TensorBoard读取。通过具体代码示例,展示了如何创建占位符、生成正态分布数据并记录为直方图,以及如何设置Session和Summary Writer来运行和保存Summary数据。
2512

被折叠的 条评论
为什么被折叠?



