Tensorboard可视化里面的events, graph, histogram
graph:显示整个静态图
tf.variable_scope就是用于放graph,tf.name_scope用的少了,因为w,b已经被封装了。
with tf.variable_scope('Inputs'):
tf_x = tf.placeholder(tf.float32, x.shape, name='x')
tf_y = tf.placeholder(tf.float32, y.shape, name='y')
histogram:显示权重的分布,也就是显示矩阵
with tf.variable_scope('Net'):
l1 = tf.layers.dense(tf_x, 10, tf.nn.relu, name='hidden_layer')
output = tf.layers.dense(l1, 1, name='output_layer')
# add to histogram summary
tf.summary.histogram('h_out', l1)
tf.summary.histogram('pred', output)
evens:显示loss,也就是显示标量
loss = tf.losses.mean_squared_error(tf_y, output, scope='loss')
train_op = tf.train.GradientDescentOptimizer(learning_rate=0.5).minimize(loss)
tf.summary.scalar('loss', loss) # add loss to scalar summary
这些东西需要放进一个文件里:需要建立一个问题,和建立一个放入的操作:
writer = tf.summary.FileWriter('./log', sess.graph) # write to file
merge_op = tf.summary.merge_all() # operation to merge all summary
tensorflow是一个盒子,看东西必须借助一个工具,它的名字叫session.run():
_, result = sess.run([train_op, merge_op], {tf_x: x, tf_y: y})
writer.add_summary(result, step)
去页面看图:
$ tensorboard --logdir path/to/log