def conv2d(self, x, w_shape, strides, padding, name, reuse=False,
initializer_w=tf.truncated_normal_initializer(mean=0.0, stddev=1e-2),
initializer_b=tf.truncated_normal_initializer(mean=0.0, stddev=1e-2)
):
'''
convolution layer:
Input
- x:input tensor
- w_shape:weight shape for convolution kernel
- strides
- padding:'SAME' or 'VALID'
- name:variable name scope
- initializer_w/b:initializer of weight and bias
'''
_, _, _, num_out = w_shape
with tf.variable_scope(name, reuse=reuse) as scope:
weights = tf.get_variable('weights', w_shape, initializer=initializer_w)
biases = tf.get_variable('biases', [num_out], initializer=initializer_b)
#conv
conv = tf.nn.conv2d(x, weights, strides, padding)
#relu
relu = tf.nn.relu(conv + biases, name=scope.name)
return relu
评论列表
文章目录