MCPcopy Create free account
hub / github.com/MorvanZhou/tutorials / add_layer

Function add_layer

tensorflowTUT/tf15_tensorboard/full_code.py:14–31  ·  view source on GitHub ↗
(inputs, in_size, out_size, n_layer, activation_function=None)

Source from the content-addressed store, hash-verified

12
13
14def 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

Callers 1

full_code.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected