TensorBoard 生成计算图

TensorBoard 生成计算图

这是一个简单的全连接网络,实现a=x * w1 + b1, y=a * w2 + b2.
只看代码不是很形象,计算图让网络变得更直观。
用 tf.summary.FileWriter() 方法生成计算图。
步骤:
1,运行代码,把计算图保存在 "/home/yuejian/Desktop/graph"

import tensorflow as tf
x = tf.constant([0.9, 0.85], shape=[1, 2])
w1 = tf.Variable(tf.constant([[0.2, 0.1, 0.3], [0.2, 0.4, 0.3]], shape=[2, 3]), name='w1')
w2=tf.Variable(tf.constant([0.2, 0.5,0.25], shape=[3, 1]), name='w2')
b1=tf.constant([-0.3, 0.1, 0.2], shape=[1, 3], name="b1")
b2=tf.constant([-0.3], shape=[1], name="b2")

init_op=tf.global_variables_initializer()
a=tf.matmul(x, w1)+b1
y=tf.matmul(a, w2)+b2
with tf.Session() as sess:
    sess.run(init_op)
    writer = tf.summary.FileWriter("/home/yuejian/Desktop/graph", sess.graph) #生成计算图
    writer.close()
    print(sess.run(y))

2,在文件夹下找到刚刚保存好的计算图

TensorBoard 生成计算图_第1张图片
3,在当前文件夹下右键打开命令行
(注意要切换到刚刚运行程序的环境)
输入 tensorboard --logdir=/home/yuejian/Desktop/graph

4,打开弹出的网址, 比如我这里是 http://0.0.0.0:6006

TensorBoard 生成计算图_第2张图片
5,进入网址,点击GRAPHS
TensorBoard 生成计算图_第3张图片
6,点击左上角下载,将计算图保存到本地,打开。
TensorBoard 生成计算图_第4张图片
结束

你可能感兴趣的:(深度学习)