espnet2.gan_codec.shared.discriminator.msstft_discriminator.get_2d_padding
Less than 1 minute
espnet2.gan_codec.shared.discriminator.msstft_discriminator.get_2d_padding
espnet2.gan_codec.shared.discriminator.msstft_discriminator.get_2d_padding(kernel_size: Tuple[int, int], dilation: Tuple[int, int] = (1, 1))
Calculate the 2D padding required for a convolutional layer given the kernel
size and dilation.
The padding is computed to ensure that the output dimensions remain the same as the input dimensions when using the specified kernel size and dilation in a convolution operation.
- Parameters:
- kernel_size (tuple of int) – The size of the convolution kernel in the format (height, width).
- dilation (tuple of int , optional) – The dilation rate for the kernel in the format (dilation_height, dilation_width). Defaults to (1, 1).
- Returns: A tuple containing the calculated padding values in the format : (padding_height, padding_width).
- Return type: tuple
Examples
>>> get_2d_padding((3, 3))
(1, 1)
>>> get_2d_padding((5, 5), dilation=(2, 2))
(4, 4)
NOTE
The padding values are computed using the formula: padding = ((kernel_size - 1) * dilation) // 2