# -*- coding: utf-8 -*-
# by dl
import tensorflow as tf
# 构造graph结构
# 用一个线性方程的例子 y = W*x+b (W权重
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'
# 创建用于初始化所有变量的操作
init = tf.global_variables_initializer()
# 创建Session
with tf.Session() as sess:
sess.run(init) # 实现初始化变量
writer = tf.summary.FileWriter(path, sess.graph)
result = sess.run(y, {x: 3.0}) # 给站位符赋值 然后运行
print("y = %s" % result)
运行
tensorboard --logdir=log --host=127.0.0.1