Why PyTorch model takes multiple image size inside the model?
I am using a simple object detection model in PyTorch and using a Pytoch Model for Inferencing.
When I am using a simple iterator over the code
for k, image_path in enumerate(image_list):
    image = imgproc.loadImage(image_path)
    print(image.shape)
    with torch.no_grad():
        y, feature = net(x)        
    result = image.cuda()

It prints our variable sized images such as
torch.Size([1, 3, 384, 320])

torch.Size([1, 3, 704, 1024])

torch.Size([1, 3, 1280, 1280])

So When I am using Batch Inferencing using a DataLoader applying the same transformation the code is not running.
However, when I am resizing all the images as 600.600 the batch processing runs successfully.
I am having Two Doubts,
First why Pytorch is capable of inputting dynamically sized inputs in Deep Learning Model and Why dynamic sized input is failing in Batch Processing.

PyTorch has what is called a Dynamic Computational Graph (other explanation).
It allows the graph of the neural network to dynamically adapt to its input size, from one input to the next, during training or inference.
This is what you observe in your first example: providing an image as a Tensor of size [1, 3, 384, 320] to your model, then another one as a Tensor of size [1, 3, 384, 1024], and so forth, is completely fine, as, for each input, your model will dynamically adapt.
However, if your input is a actually a collection of inputs (a batch), it is another story. A batch, for PyTorch, will be transformed to a single Tensor input with one extra dimension. For example, if you provide a list of n images, each of the size [1, 3, 384, 320], PyTorch will stack them, so that your model has a single Tensor input, of the shape [n, 1, 3, 384, 320].
This &quot;stacking&quot; can only happen between images of the same shape. To provide a more &quot;intuitive&quot; explanation than previous answers, this stacking operation cannot be done between images of different shapes, because the network cannot &quot;guess&quot; how the different images should &quot;align&quot; with one another in a batch, if they are not all the same size.
No matter if it happens during training or testing, if you create a batch out of images of varying size, PyTorch will refuse your input.
Several solutions are usually in use: reshaping as you did, adding padding (often small or null values on the border of your images) to extend your smaller images to the size of the biggest one, and so forth.
