def add_layer(inputs, in_size, out_size, n_layer, activation_function=None):
# add one more layer and return the output of this layer
layer_name = 'layer%s' % n_layer
with tf.variable_scope(layer_name):
with tf.variable_scope('weights'):
Weights = tf.get_variable(shape=[in_size, out_size], name='W', initializer=xavier_initializer())
tf.histogram_summary(layer_name + '/weights', Weights)
with tf.variable_scope('biases'):
biases = tf.get_variable(shape=[1, out_size], name='b', initializer=xavier_initializer())
tf.histogram_summary(layer_name + '/biases', biases)
with tf.variable_scope('Wx_plus_b'):
Wx_plus_b = tf.add(tf.matmul(inputs, Weights), biases)
if activation_function is None:
outputs = Wx_plus_b
else:
outputs = activation_function(Wx_plus_b, )
tf.histogram_summary(layer_name + '/outputs', outputs)
return outputs
# Make up some real data
tf_redshifts.py 文件源码
python
阅读 17
收藏 0
点赞 0
评论 0
评论列表
文章目录