def pad_to_size(bottom, output_size):
'''
A layer used to pad the tensor bottom to output_size by padding zeros around it
TODO: implement for 3D data
'''
input_size = bottom.get_shape().as_list()
size_diff = np.subtract(output_size, input_size)
pad_size = size_diff // 2
odd_bit = np.mod(size_diff, 2)
if len(input_size) == 4:
padded = tf.pad(bottom, paddings=[[0,0],
[pad_size[1], pad_size[1] + odd_bit[1]],
[pad_size[2], pad_size[2] + odd_bit[2]],
[0,0]])
return padded
elif len(input_size) == 5:
raise NotImplementedError('This layer has not yet been extended to 3D')
else:
raise ValueError('Unexpected input size: %d' % input_size)
评论列表
文章目录