4.1 Tensorboard 可视化好帮手 1
Event / Scalar: 展示训练过程中的统计数据(最值,均值等)变化情况
Image: 展示训练过程中记录的图像
Audio: 展示训练过程中记录的音频
Histogram: 展示训练过程中记录的数据的分布图
Graphs: 展示神经网络结构图
可视化整个神经网络的结构
代码是前几节的截取
from __future__ import print_function
import tensorflow as tf
def add_layer(inputs, in_size, out_size, activation_function=None):
# add one more layer and return the output of this layer
with tf.name_scope('layer888'): #为隐藏层添加名字layer888(大框架)
with tf.name_scope('WWWWWWWWW'): #为weights层添加名字WWWWWWWW(小部件)
Weights = tf.Variable(tf.random_normal([in_size, out_size]), name='W') #为weights取名为W
with tf.name_scope('biasesss'):
biases = tf.Variable(tf.zeros([1, out_size]) + 0.1, name='b')
with tf.name_scope('Wx_plus_bbbb'):
Wx_plus_b = tf.add(tf.matmul(inputs, Weights), biases)
if activation_function is None:
outputs = Wx_plus_b
else:
outputs = activation_function(Wx_plus_b, )
return outputs
# define placeholder for inputs to network
with tf.name_scope('inputsss'):
xs = tf.placeholder(tf.float32, [None, 1], name='x_input')
ys = tf.placeholder(tf.float32, [None, 1], name='y_input')
# add hidden layer
l1 = add_layer(xs, 1, 10, activation_function=tf.nn.relu)
# add output layer
prediction = add_layer(l1, 10, 1, activation_function=None)
# the error between prediciton and real data
with tf.name_scope('losssss'):
loss = tf.reduce_mean(tf.reduce_sum(tf.square(ys - prediction),
reduction_indices&