def asymmetric_spatial_2d_padding(x, top_pad=1, bottom_pad=1,
left_pad=1, right_pad=1,
dim_ordering='default'):
'''Pad the rows and columns of a 4D tensor
with "top_pad", "bottom_pad", "left_pad", "right_pad" (resp.) zeros
rows on top, bottom; cols on left, right.
'''
if dim_ordering == 'default':
dim_ordering = image_dim_ordering()
if dim_ordering not in {'th', 'tf'}:
raise ValueError('Unknown dim_ordering ' + str(dim_ordering))
if dim_ordering == 'th':
pattern = [[0, 0],
[0, 0],
[top_pad, bottom_pad],
[left_pad, right_pad]]
else:
pattern = [[0, 0],
[top_pad, bottom_pad],
[left_pad, right_pad],
[0, 0]]
return tf.pad(x, pattern)
评论列表
文章目录