def conv2d(input, num_filters, filter_size, stride, reuse=False,
pad='SAME', dtype=tf.float32, bias=False):
stride_shape = [1, stride, stride, 1]
filter_shape = [filter_size, filter_size, input.get_shape()[3], num_filters]
w = tf.get_variable('w', filter_shape, dtype, tf.random_normal_initializer(0.0, 0.02))
if pad == 'REFLECT':
p = (filter_size - 1) // 2
x = tf.pad(input, [[0,0],[p,p],[p,p],[0,0]], 'REFLECT')
conv = tf.nn.conv2d(x, w, stride_shape, padding='VALID')
else:
assert pad in ['SAME', 'VALID']
conv = tf.nn.conv2d(input, w, stride_shape, padding=pad)
if bias:
b = tf.get_variable('b', [1,1,1,num_filters], initializer=tf.constant_initializer(0.0))
conv = conv + b
return conv
评论列表
文章目录