- 使用 tf.name_scope(“name”) as scope:把需要显示的weight,biases,conv囊括进去,之后在变量下面添加 tf.summary.histogram(“name”, weight).
- 在loss下面添加tf.summary.scalar(“loss”,loss)
- 之后再使用sess.run(tf.gloable_variables_initiializer())后,使用
merged = tf.summary.merge_all()
writer = tf.summart.FileWriter("logs", sess.graph)
- 在训练过程中,添加
if i % 10 ==0:
result = sess.run(merged, feed_dict={x: x_input, y: y_input})
writer.add(result,i)
- 具体实现如下:
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# author:Dr.Shang
import tensorflow as tf
import numpy as np
input_x = np.random.rand(100)
input_y = np.multiply(3, input_x) + 1
with tf.name_scope('input_layer') as scope:
x = tf.placeholder(tf.float32, name="x")
y = tf.placeholder(tf.float32)
with tf.name_scope('weights'