TensorFlow之TensorBoard(5)

TensorBoard的作用:黑盒在浏览器中可视化【在浏览器中展现】

 

1.用TensorFlow保存图的信息到日志中

tf.summary.FileWriter("日志保存路径", sess.graph)

 

2.用TensorBoard读取并展示日志

tensorboard--logdir = 日志所在路径

 

▲summary:(总结)

· 用于导出关于模型的精简信息的方法

· 可以使用TensorBoard等工具访问这些信息

 

▲name_scope(命名空间)

· 类似于C++中的namespace 包含/嵌套的关系

 

示例:vim tensorboard.py

 1 #构造图(Graph)的结构
 2 #用一个线性方程的例子 y = W * x + b
 3 W = tf.Variable(2.0,  dtype=tf.float32, name="Weight")   #权重
 4 b = tf.Variable(1.0, dtype=tf.float32, name="Bias")         #偏差
 5 x = tf.placeholder(dtype=tf.float32, name="Input")         #输入
 6 
 7 with tf.name_scope("Output"):     #输出的命名空间
 8     y = W * x + b                         #输出
 9 
10 #const = tf.constant(2.0)            #不需初始化
11 #定义保存日志的路径
12 path = "./log"
13 
14 init = tf.global_variables_initializer()
15 
16 with tf.Session() as sess:
17     sess.run(init)
18     writer = tf.summary.FileWriter(path, sess.graph)
19     result = sess.run(y, {x:3.0})
20     print ("y= %s" % result)

 

posted on 2018-10-10 19:07  qiuqiu365  阅读(157)  评论(0)    收藏  举报