Skip to content

nn.Conv* incostintent error depending on stride #9592

@maxme1

Description

@maxme1

Issue description

Convolutions do not raise an exception for too small input shape if stride > 1.

Code example

Suppose we have a following convolution:

conv = torch.nn.Conv2d(1, 1, kernel_size=3, dilation=2, stride=1)
tensor = torch.empty(1, 1, 4, 4)
conv(tensor).shape

This code raises a RuntimeError: Given input size per channel: (4 x 4). Calculated output size per channel: (0 x 0). Which is quite expected.

Now change the stride to 2:

conv = torch.nn.Conv2d(1, 1, kernel_size=3, dilation=2, stride=2)
tensor = torch.empty(1, 1, 4, 4)
conv(tensor).shape

Which gives torch.Size([1, 1, 1, 1]). Is this expected behavior?

I guess this is because in the formula for the output shape there is a division by the stride and the check is performed before taking the floor operation.

System Info

  • How you installed PyTorch: conda
  • OS: Linux
  • PyTorch version: 0.4
  • Python version: 3.6

The code was run on CPU.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions