Inception : Calculated padded input size per channel: (4 x 4). Kernel size: (5 x 5)

Hello,
I am trying to add more layers to inception v3 to fit my dataset. Yet, I don’t figure out the Runtime Error. my input is (3* 256 * 256)

model =  models.inception_v3(init_weights=True, pretrained=False)

fc_feat = model.fc.in_features
model.fc = nn.Sequential(
    nn.Linear(fc_feat, 512),
    nn.ReLU(),
    nn.Linear(512,3),
)
train_model(model, optimizer, scheduler, 10)

Error:
RuntimeError                              Traceback (most recent call last)

<ipython-input-66-f4a3ac1ce1ac> in <module>()
----> 1 train_model(model, optimizer, scheduler, 10)

11 frames

/usr/local/lib/python3.6/dist-packages/torch/nn/modules/conv.py in _conv_forward(self, input, weight)
    418                             _pair(0), self.dilation, self.groups)
    419         return F.conv2d(input, weight, self.bias, self.stride,
--> 420                         self.padding, self.dilation, self.groups)
    421 
    422     def forward(self, input: Tensor) -> Tensor:

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

Thanks in advance!

The original Inception model expects an input in the shape [batch_size, 3, 299, 299], so a spatial size of 256x256 might be too small for the architecture and an empty activation would be created, which raises the issue.

1 Like