启动tensorflow:
cd /
cd anaconda3/
bin/jupyter-notebook
启动tensorboard:
cd /
cd anaconda3/
tensorboard --logdir=log/02
或者是启动指定的日志文件02
在python代码中需要写入log文件:
import tensorflow as tf
tf.reset_default_graph()
logdir = "/anaconda3/log/01"
input1 = tf.constant([1.0,2.0,3.0],name="input1")
input2 = tf.Variable(tf.random_uniform([3]),name="input2")
output = tf.add_n([input1,input2],name = "add")
writer = tf.summary.FileWriter(logdir,tf.get_default_graph())
writer.close()
# -*- coding: UTF-8 -*-
# 引入tensorflow
import tensorflow as tf
# 设置了gpu加速提示信息太多了,设置日志等级屏蔽一些
import os
os.environ['TF_CPP_MIN_LOG_LEVEL']='3'
# 构造图(Graph)的结构
# 用一个线性方程的例子 y = W * x + b
# 梯度下降法求w和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
# 输出#
const = tf.constant(2.0)
# 常量,不需要初始化# 定义保存日志的路径
path = "/anaconda3/log/02"
# 创建用于初始化所有变量 (Variable) 的操作
init = tf.global_variables_initializer()
# 创建Session(会话)
with tf.Session() as sess:
sess.run(init)
# 初始化变量
# 写入日志文件
writer = tf.summary.FileWriter(path, sess.graph) # 因为x是一个placeholder,需要进行值的填充
result = sess.run(y, {x: 3.0})
print("y = %s" % result) # 打印 y = W * x + b 的值,就是 7