tensorboard之一(显示网络结构)

with tf.name_scope('input'):
    xs = tf.placeholder(tf.float32, [None, 1], name = 'x_input')
    ys = tf.placeholder(tf.float32, [None, 1], name = 'y_input')

def add_layer(input, in_size, out_size, activation_function = None):
    with tf.name_scope('layer'):
        with tf.name_scope('weight'):
            W = tf.Variable(tf.random_normal([in_size, out_size]), name = 'W')
        with tf.name_scope('biases'):
            b = tf.Variable(tf.zeros([1, out_size]) + 0.1, name = 'b')
        with tf.name_scope('Wx_plus_b'):
            Wx_plus_b = tf.add(tf.matmul(input, W), b)
        if activation_function == None:
            out = Wx_plus_b
        else:
            out = activation_function(Wx_plus_b)
        return out

l1 = add_layer(xs, 1, 10, tf.nn.relu)
prediction = add_layer(l1, 10, 1)

with tf.name_scope('loss'):
    loss = tf.reduce_mean( tf.square(ys - prediction) )

optimize = tf.train.GradientDescentOptimizer(0.1)
with tf.name_scope('train'):
    train = optimize.minimize(loss)

sess = tf.Session()

writer = tf.summary.FileWriter('D:/log/', sess.graph)

 

tensorboard --logdir=./log --host=127.0.0.1

 

很棒的结果:

tensorboard之一(显示网络结构)_第1张图片

你可能感兴趣的:(神经网络实例)