| 12 | |
| 13 | |
| 14 | def add_layer(inputs, in_size, out_size, n_layer, activation_function=None): |
| 15 | # add one more layer and return the output of this layer |
| 16 | layer_name = 'layer%s' % n_layer |
| 17 | with tf.name_scope(layer_name): |
| 18 | with tf.name_scope('weights'): |
| 19 | Weights = tf.Variable(tf.random_normal([in_size, out_size]), name='W') |
| 20 | tf.summary.histogram(layer_name + '/weights', Weights) |
| 21 | with tf.name_scope('biases'): |
| 22 | biases = tf.Variable(tf.zeros([1, out_size]) + 0.1, name='b') |
| 23 | tf.summary.histogram(layer_name + '/biases', biases) |
| 24 | with tf.name_scope('Wx_plus_b'): |
| 25 | Wx_plus_b = tf.add(tf.matmul(inputs, Weights), biases) |
| 26 | if activation_function is None: |
| 27 | outputs = Wx_plus_b |
| 28 | else: |
| 29 | outputs = activation_function(Wx_plus_b, ) |
| 30 | tf.summary.histogram(layer_name + '/outputs', outputs) |
| 31 | return outputs |
| 32 | |
| 33 | |
| 34 | # Make up some real data |