RuntimeError: Calculated padded input size per channel: (2 x 18). Kernel size: (3 x 3). Kernel size can't be greater than actual input size

I was trying to implement the NVDIA’s paper on self-driving cars and had the following error
RuntimeError: Calculated padded input size per channel: (2 x 18). Kernel size: (3 x 3). Kernel size can’t be greater than actual input size

My conv_layer is as follows:
self.conv_layers = nn.Sequential(
nn.Conv2d(3, 24, 5, stride=2),
nn.ELU(),
nn.Conv2d(24, 36, 5, stride=2),
nn.ELU(),
nn.Conv2d(36, 48, 5, stride=2),
nn.ELU(),
nn.Conv2d(48, 64, 3, stride=2),
nn.ELU(),
nn.Conv2d(64, 64, 3, stride=2),
nn.MaxPool2d((1,3)),
nn.Dropout(0.5)
)

and the input.size() to this layer is torch.Size([32, 3, 70, 320]).
I am trying to understand how the the the size of ([32,3,70,320]) gets converted to a 3@66*220 input layer to it
Help me out

Your input size is just too small for this model.
I’ve added the output shapes of the conv layers as comments:

conv_layers = nn.Sequential(
nn.Conv2d(3, 24, 5, stride=2), # [N, 24, 33, 158]
nn.ELU(),
nn.Conv2d(24, 36, 5, stride=2), # [N, 36, 15, 77]
nn.ELU(),
nn.Conv2d(36, 48, 5, stride=2), # [N, 48, 6, 37]
nn.ELU(),
nn.Conv2d(48, 64, 3, stride=2), # [N, 64, 2, 18]
...

As you can see, the spatial size if the last mentioned layer is 2x18, which is too small for a kernel size of 3 with stride=2.

2 Likes

This was happening to me in pretrained model, As above I had used small input size for inception_v3,
After i resize image to (229, 229) as mention on docs . oh It didn’t worked. Help!!
Throwing same error
RuntimeError: Calculated padded input size per channel: (3 x 3). Kernel size: (5 x 5). Kernel size can't be greater than actual input size

problem was solved inception v3 calculated padded input…