I remember in part 1 of the course, pretrained CNN were used with different input sizes of images. The example of Kaggle Planet Competition was provided and how different sizes of images were used in the same model. But I cannot figure out how to do the same in pytorch.
I have seen in pytorch the pre-train Resnet takes the input of 224X224 image, and gives an error otherwise, so how is possible to train a 64X64 image on it and then re-train the same network with 224X224 images.
In Pytorch and FastAi, we have AdaptiveAvgPool2d before the final layer (‘fc’ layer), which reshapes the input to a size suitable for the ‘fc’ layer. So, the models are flexible in terms of image sizes…
import torch.nn as nn
input1 = torch.rand(1,1,10,10)
input2 = torch.rand(1,1,15,15)
AAP = nn.AdaptiveAvgPool2d(1)
print(AAP(input1))
print(AAP(input2))
In the earlier layers, we have convolution operations that reduce the image size and one of these can fail if image sizes are too small. Example: