How do I feed higher res images to model zoo models?

The size mismatch is coming from the output of the last avgpool layer feeding into the input of the resnet.fc module. To feed it larger images you will need to strip the existing fully connected layer and replace it with one with a larger input dimension.

something like:

your_net = models.resnet18(pretrained=True)`

new_num_features = *something bigger than 512*

your_net.fc = nn.Linear(new_num_features, 1000)

This will create untrained parameters, though. To use the pretrained models, I think you are restricted to image sizes below what you are using.

the easiest way that I’ve found to deal with this is to temporarily modify the resnet.py file to print x.size() right before the x = self.fc(x)

this will show you the dimensions of the tensor that is created by whatever images you are using

1 Like