| 21 | |
| 22 | |
| 23 | def add_layer(inputs, in_size, out_size, layer_name, activation_function=None, ): |
| 24 | # add one more layer and return the output of this layer |
| 25 | Weights = tf.Variable(tf.random_normal([in_size, out_size])) |
| 26 | biases = tf.Variable(tf.zeros([1, out_size]) + 0.1, ) |
| 27 | Wx_plus_b = tf.matmul(inputs, Weights) + biases |
| 28 | # here to dropout |
| 29 | Wx_plus_b = tf.nn.dropout(Wx_plus_b, keep_prob) |
| 30 | if activation_function is None: |
| 31 | outputs = Wx_plus_b |
| 32 | else: |
| 33 | outputs = activation_function(Wx_plus_b, ) |
| 34 | tf.summary.histogram(layer_name + '/outputs', outputs) |
| 35 | return outputs |
| 36 | |
| 37 | |
| 38 | # define placeholder for inputs to network |