espnet2.gan_codec.shared.encoder.seanet.get_extra_padding_for_conv1d
Less than 1 minute
espnet2.gan_codec.shared.encoder.seanet.get_extra_padding_for_conv1d
espnet2.gan_codec.shared.encoder.seanet.get_extra_padding_for_conv1d(x: Tensor, kernel_size: int, stride: int, padding_total: int = 0) → int
Pad for a convolution to make sure that the last window is full. Extra padding is added at the end. This is required to ensure that we can rebuild an output of the same length, as otherwise, even with padding, some time steps might get removed. For instance, with total padding = 4, kernel size = 4, stride = 2:
0 0 1 2 3 4 5 0 0 # (0s are padding) 1 2 3 # (out-frames of a convolution, last 0 is never used) 0 0 1 2 3 4 5 0 # (out-tr.conv., but pos.5 will get removed as padding)
1 2 3 4 # once you removed padding, we are missing one time step !