If you build your network as a pure CNN
, namely FCNN
, then the network itself can support any input size.
Usually the issue is the data type of the batch.
For performance the container of a batch is a contiguous array, for example in PyTorch it is called a tensor. This tensor requires that all samples along any dimensions will have the same dimensions.
There are few ways around it:
Set the batch size to 1
This will hurt performance but is probably the easiest solution.
Create a dedicated loader
This loader will select from a pre defined list of samples with the same dimensions. It will ruin the randomness of the batches but will benefit run time performance.
Pad / Sample all elements to the same size
One may pad all samples to have the same size (Of the max size per dimension in the batch). In cases it makes sense you may use resampling / interpolation.
In case you have a Fully Connected / Dense layer somewhere you may do something to stabilize the number of inputs to that layer regardless of the input size. A simple trick is using a global maximum per channel. This means the output depends only on the number of channels.
A generalization is max pooling over a relative size of the image. Namely split it into quarters and have a global operator over it.
This is basically the idea in Spatial Pyramid Pooling in Deep Convolutional Networks for Visual Recognition.