简体   繁体   中英

What does Pytorch's default padding in Conv2D signify?

In the Pytorch documentation for the MaxPool2D states:

padding (int or tuple, optional) – Zero-padding added to both sides of the input. Default: 0

Does it mean that the default values for padding would be 0 or that there will be no padding?

In my code: nn.Conv2d(input_channels, output_channels, kernel_size, stride) , I didn't pass any padding parameter and when I printed it, it shows the following

(0): Conv2d(4, 8, kernel_size=(3, 3), stride=(1, 1), padding=(2, 2))

So, I'm assuming it by default adds padding to match the input size with values 0.

Now, if that's the case, then how can I turn it off and/or add a different padding value?

Does it mean that the default values for padding would be 0 or that there will be no padding?

It means that there will be no padding at all (because the parameter padding specifies the size of the padding for each dimension and by default it is padding=0 , ie (0, 0) ).

>>> conv = torch.nn.Conv2d(4, 8, kernel_size=(3, 3), stride=(1, 1))
>>> conv.padding
(0, 0)

The convolution layer is agnostic of the input height and width, it only expects the input to have 4 channels (in this particular example). The input height and weight are computed after you pass the input to it, and if the image size is smaller than the kernel size, then it will throw an error -- it will not pad the input automatically to match the size. It would help if you posted full code to see where the padding comes from.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM