3

According to the documentation on pre-trained computer vision models for transfer learning (e.g., here), input images should come in "mini-batches of 3-channel RGB images of shape (3 x H x W), where H and W are expected to be at least 224".

However, when running transfer learning experiments on 3-channel images with height and width smaller than expected (e.g., smaller than 224), the networks generally run smoothly and often get decent performances.

Hence, it seems to me that the "minimum height and width" is somehow a convention and not a critical parameter. Am I missing something here?

Elabore
  • 151
  • 6

2 Answers2

3

There is a limitation on your input size which corresponds to the receptive field of the last convolution layer of your network. Intuitively, you can observe the spatial dimensionality decreasing as you progress through the network. At least this is the case for feature extractor CNNs which aim at extracting feature embeddings from the input image. That is most pre-trained models such as vanilla VGG, and ResNets networks do not retain spatial dimensionality. If the input of a convolutional layer is smaller than the kernel size (even if/when padded), then you simply won't be able to perform the operation.

Ivan
  • 34,531
  • 8
  • 55
  • 100
1

TLDR: adaptive pooling layer

For example, the standard resnet50 model accepts input only in ranges 193-225, and this is due to the architecture and downscaling layers (see below). The only reason why the default pytorch model works is that it is using adaptive pooling layer which allows to not restrict input size. So it's gonna work but you should be ready for performance decay and other fun things :)

intermediate shapes of tensor during forward run

Hope you will find it useful:

  1. https://discuss.pytorch.org/t/how-can-torchvison-models-deal-with-image-whose-size-is-not-224-224/51077/3
  2. What is Adaptive average pooling and How does it work?
  3. https://pytorch.org/docs/stable/generated/torch.nn.AdaptiveAvgPool2d.html
  4. https://github.com/pytorch/vision/blob/c187c2b12d86c3909e59a40dbe49555d85b98703/torchvision/models/resnet.py#L118
  5. https://github.com/pytorch/vision/blob/c187c2b12d86c3909e59a40dbe49555d85b98703/torchvision/models/resnet.py#L151
  6. https://developpaper.com/pytorch-implementation-examples-of-resnet50-resnet101-and-resnet152/