Questions Regarding the Direction of Half Padding for Odd-Sized Inputs in PyTorch Conv2D and ConvTransposed2D

Hello, I have a question regarding the behavior of padding in convolution layers in PyTorch’s CNN implementation. According to the official PyTorch documentation, for details on how convolutions operate, it refers us to the following paper: ([1603.07285] A guide to convolution arithmetic for deep learning). While reading that paper, I noticed something about the way padding is handled in ConvTransposed2D compared to the regular Conv2d function.

In general, consider a scenario where stride = 2 and the kernel size is an odd number (let’s say 3), and you have an odd-by-odd 2D tensor as input. According to the paper, half padding is applied toward the bottom-right direction. I believe the code also implements this in the same way. If that’s the case, then for the Conv2D function as well, when stride = 2, the kernel size is odd, and the input is an odd-by-odd 2D tensor, you would need to apply half padding in a similar manner as with ConvTransposed2D. In that situation, in which direction would the half padding be applied for the Conv2D function?

I’ve tried looking into the relevant parts of the code, but PyTorch is so well-encapsulated that I can’t seem to find the portion that handles this exact behavior🤣.


I think the figure above clearly illustrates the problematic situation.

The question I created seems completely incorrect. I don’t know how to delete it…
I’ll revise it and ask again.