Skip to content

Inconsistent MaxPool2d Output size between 0.4.1 and 1.0.1 #22337

@JasonVann

Description

@JasonVann

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).

Metadata

Metadata

Assignees

Labels

high prioritymodule: cpuCPU specific problem (e.g., perf, algorithm)module: error checkingBugs related to incorrect/lacking error checkingsmallWe think this is a small issue to fix. Consider knocking off high priority small issuestriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions