-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Description
In one of my project, I run into an issue, which can be simplied as the following code.
import torch
import torch.nn as nn
torch.version.version
input = torch.randn(1, 1, 16, 1)
m = nn.MaxPool2d(2, stride=2)
output = m(input)
output.shape
On pytorch 1.0.1, this will give an output as
[1,1,8,1]
On pytorch 0.4.1, this will throw an error saying:
RuntimeError: Given input size: (1x16x1). Calculated output size: (1x8x0). Output size is too small at /pytorch/aten/src/THNN/generic/SpatialDilatedMaxPooling.c:67
According to the equation in master doc (https://pytorch.org/docs/stable/nn.html#torch.nn.MaxPool2d), the output size should be 0, which agrees with 0.4.1, but not 1.1.0:
Hout = (Hin + 2*padding - dilation * (kernel_size - 1) - 1)/stride + 1
Which in this case should be:
(1 + 2 * 0 - 1 * (2 - 1) - 1)/1 + 1 = 0
I took a quick look into the source code of pytorch 1.1, and found the equation is implemented as in the doc in pooling_shape.h, so I'm confused why it returns an output of (1, 1, 8, 1), as opposed to (1, 1, 8, 0).