How to use the pre-train model multiple time in pytorch with different size images as done with Kaggle Planet Competition

Hi,

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:

input1 = torch.rand(1,3,10,10)
input2 = torch.rand(1,3,2,2)
conv1 = nn.Conv2d(3,3,kernel_size=5, stride=2)
print('Original Input1 Shape: ', input1.shape)
print('After Convolution: ‘, conv1(input1).shape)
print(’\nOriginal Input2 Shape: ', input2.shape)
print('After Convolution: ', conv1(input2).shape) #Error

So,if the images are of adequate size, I believe it should work…