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之一(显示网络结构)

相关文章:

  • 2021-12-29
  • 2022-12-23
  • 2021-09-21
  • 2021-09-24
  • 2021-08-31
  • 2021-11-10
  • 2021-11-06
  • 2021-09-16
猜你喜欢
  • 2022-12-23
  • 2021-06-28
  • 2021-07-21
  • 2022-12-23
  • 2021-06-06
  • 2021-10-27
  • 2021-10-28
相关资源
相似解决方案