tensorboard可视化

inputs可视化
with tf.name_scope(‘inputs’):
xs=tf.placeholder(tf.float32,[None,1],name=’x_input’)#None是无论给多少sample都OK
ys=tf.placeholder(tf.float32,[None,1],name=’y_input’)

hidden layer可视化
def add_layer(inputs,in_size,out_size,activation_function=None):
with tf.name_scope(‘layer’):
with tf.name_scope(‘weight’):
Weights=tf.Variable(tf.random_normal([in_size,out_size]),name=’W’)#用random比用0好
with tf.name_scope(‘biases’):
biases=tf.Variable(tf.zeros([1,out_size])+0.1,name=’b’) #biases推荐的值不为0
with tf.name_scope(‘Wx_plus_b’):
Wx_plus_b=tf.matmul(inputs,Weights)+biases
if activation_function is None:
outputs=Wx_plus_b
else:
outputs=activation_function(Wx_plus_b)
return outputs

loss&train可视化
with tf.name_scope(‘loss’):
loss=tf.reduce_mean(tf.reduce_sum(tf.square(ys-prediction),reduction_indices=[1]),name=’loss’)
#平方和相加再平均,reduction_indices=[1]时,*维对应位置相加

with tf.name_scope(‘train’):
train_step=tf.train.GradientDescentOptimizer(0.1).minimize(loss)#通常learning rate 小于1

文件储存
init=tf.initialize_all_variables()#初始所有变量
sess=tf.Session()
writer= tf.summary.FileWriter(‘/tensorboard/logs/’,sess.graph)#放到浏览器之后才能观看
sess.run(init)#上面所有步骤都没有激活直到这里

tensorboard打开
进入cmd :cd/d logs文件的上一级
如:cd/d D:\tensorboard
then tensorboard –logdir=logs
进入网址打开graphs

%title插图%num
tensorboard打开注意事项:
①目录中不要出现中文!!!!
②在cmd中cd/d 时后面加的是logs文件的上一级目录!!!
③*好用goggle浏览器打开
④*好在打开前在anaconda激活tensorflow
⑤在进入网页前不要按ctrl+c,按完就进不去了