def Affine(name_scope,input_tensor,out_channels, relu=True):
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')
# initializer = tf.initialize_variables([weights,biases])
if relu: return tf.nn.relu(tf.matmul(input_tensor, weights) + biases)#,initializer
else: return tf.matmul(input_tensor, weights) + biases#,initializer
评论列表
文章目录