I've started to work with a leaf classification dataset on Kaggle. All input images have different rectangular shapes. I want to transform the input into squares of a fixed size (say, 224x224) with a symmetric zero-padding either on top and bottom or on the left and right sides of the rectangle. Prior to that, I think that I need to rescale the image (some images in the dataset have shapes
>1000). I've encountered the next two problems:
torchvision.transforms.Resize(size)rescales the image so that its smaller side is matched to
sizeis a scalar). I want the opposite, the bigger side to be matched to
torchvision.transforms.Pad(padding)seemingly works only with some fixed
padding, but this transform will not always output a square.
How would you resolve this problem? I'm aware of
RandomSizedCrop, but I feel like some datasets (like this one) aren't good for this method (some of the input images are too oblong). Also, I heard that
RandomSizedCrop shouldn't be
used for the test data loaders.
More generally, how do you deal with input images of different rectangular shapes in PyTorch? Any help is appreciated.