码迷,mamicode.com
首页 > 其他好文 > 详细

7.可视化利器TensorBoard

时间:2018-07-20 11:16:39      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:div   highlight   ace   path   rap   int   python   结构   const   

import tensorflow as tf

# 构造图的结构
# 使用一个线性方程 y = w * x + b
w = tf.Variable(2.0, dtype=tf.float32, name=‘weight‘)  # 权重
b = tf.Variable(1.0, dtype=tf.float32, name=‘bias‘)  # 偏差
# 占位符,之后添加值
x = tf.placeholder(dtype=tf.float32, name=‘input‘)  # 输入
with tf.name_scope(‘output‘):
    y = w * x + b  # 输出

# 定义保存日志的路径
path = ‘./log‘

# 一旦定义Variable一定要初始化,不同于constant,定义constant自动初始化
# 创建用于初始化所有Variable的操作,而且init也同样需要run一下。
init = tf.global_variables_initializer()

# 创建session
with tf.Session() as sess:
    sess.run(init)  # 实现初始化变量,必须要run,权重和偏差就真正的被初始化了
    # 用于tensorboard展示,传入日志路径和graph
    writer = tf.summary.FileWriter(path, sess.graph)
    # run,之前的x还没赋值,所以使用feed_dict传值
    result = sess.run(y, feed_dict={x: 3.0})
    print(f‘y={result}‘)  # 打印y = w*x + b的值
    ‘‘‘
    y=7.0
    ‘‘‘

  

技术分享图片

执行程序之后,会多出一个log文件夹

用tensorboard打开

技术分享图片

 

7.可视化利器TensorBoard

标签:div   highlight   ace   path   rap   int   python   结构   const   

原文地址:https://www.cnblogs.com/traditional/p/9339430.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!