def Affine(name_scope,input_tensor,out_channels, relu=True, init_sess=None):
input_shape = input_tensor.get_shape().as_list()
input_channels = input_shape[-1]
with tf.name_scope(name_scope):
weights = tf.Variable(
tf.truncated_normal([input_channels, out_channels],
stddev=1.0 / math.sqrt(float(input_channels))),name='weights')
biases = tf.Variable(tf.zeros([out_channels]),name='biases')
if init_sess is not None: init_sess.run(tf.initialize_variables([weights,biases]))
if relu: return tf.nn.relu(tf.matmul(input_tensor, weights) + biases)
else: return tf.matmul(input_tensor, weights) + biases
评论列表
文章目录