Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix error messages thrown when the padding size is not valid (#50135)
Summary: Hi, I changed error messages so that they correspond to the actual implementation. Acording to the implementation, half of kernel size is valid as padding size. This is minor but an example that the padding size is exactly equal to the half of kernel size, Input: 5 x 5 Kernel: 4 x 4 Stride: 4 Padding: 2 ==> Output: 2 x 2 You don't get the error in the above case, like following: ```python import torch import torch.nn as nn # no error input = torch.randn(1, 1, 5, 5) pool = nn.MaxPool2d(4, 4, padding=2) print(pool(input).shape) # >>> torch.Size([1, 1, 2, 2]) ``` You get the error when you set the padding size larger then half of kernel size like: ```python # it raises error input = torch.randn(1, 1, 5, 5) pool = nn.MaxPool2d(4, 4, padding=3) print(pool(input).shape) ``` The error message is: ``` --------------------------------------------------------------------------- RuntimeError Traceback (most recent call last) <ipython-input-43-2b09d1c5d79a> in <module>() 1 input = torch.randn(1, 1, 5, 5) 2 pool = nn.MaxPool2d(4, 4, padding=3) ----> 3 print(pool(input).shape) 3 frames /usr/local/lib/python3.6/dist-packages/torch/nn/functional.py in _max_pool2d(input, kernel_size, stride, padding, dilation, ceil_mode, return_indices) 584 stride = torch.jit.annotate(List[int], []) 585 return torch.max_pool2d( --> 586 input, kernel_size, stride, padding, dilation, ceil_mode) 587 588 max_pool2d = boolean_dispatch( RuntimeError: pad should be smaller than half of kernel size, but got padW = 3, padH = 3, kW = 4, kH = 4 ``` Thanks in advance. Pull Request resolved: #50135 Reviewed By: hl475 Differential Revision: D25815337 Pulled By: H-Huang fbshipit-source-id: 98142296fa6e6849d2e1407d2c1d4e3c2f83076d
- Loading branch information