How to keep output size identic with input size?

Hi experts,

I have a tensor with shape (2, 64, **7**, 28, 28) and pass it to Conv3d() with stride = 1, padding = 1 and kernel_size = (1,3,3). Why my the output has (2, 64, **9**, 28, 28)? Notice that the temporal size incresed to 9. I want to keep the size same.

How to keep the size same using kernel_size = (1,3,3)? Tensor format is (bs, ch, t, h, w)
Thanks.

Hi,

You can compute output size using this formula: out = floor((in - kernel + 2*padding) / stride) + 1
So, in your case, floor((7 - 1 + 2*1) / 1) +1 = 9. There is two ways to have the identical output size, first of is to use proper kernel size which in your case it is 3 instead of 1. Second approach is to change the padding only for that particular channel which in your case, you need to use zero padding.

For the second approach this post may help you:

Bests

1 Like

Thank you. I need my kernel to convolve only on single timestep at a time so that’s why I set 1 for the kernel size. I will try you 2nd suggestion.