Skip to content

Instantly share code, notes, and snippets.

View developer-mayuan's full-sized avatar

Mabuchi Akira developer-mayuan

View GitHub Profile
@developer-mayuan
developer-mayuan / conv2d_fixed_paddingpy
Created December 21, 2017 00:07
padding for convolution layer.
def fixed_padding(inputs, kernel_size, data_format):
"""
Pads the input along the spatial dimensions independently of input size.
:param inputs: A tensor of size [batch, channels, height_in, width_in] or [batch, height_in, width_in]
:param kernel_size: The kernel to be used in the conv2d or max_pool2d operation. Should be a positive integer.
:param data_format: The input format ('channels_last' or 'channels_first').
:return A tensor with the same format as the input with the data either intact (if kernel_size == 1) or padded (if kernel_size > 1).
"""
pad_total = kernel_size - 1
pad_beg = pad_total // 2