TensorBoard的直方图用来显示Tensorflow图中的某些Tensor随时间推移变化的分布;它可以显示不同时间点对应张量的许多张直方图图示。
正态分布变量
以正态分布变量随时间变化为例,Tensorflow的tf.random_normal
可以实现
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
tensorboard --logdir=/tmp/histogram_example
在Chrome或Firefox加载数据
【参考】
1。Tensorflow--->编程人员指南--->TensorBoard--->直方图:https://www.tensorflow.org/programmers\_guide/tensorboard\_histograms?hl=zh-cn