Image transforms

Is there a need to resize images using (transforms.RandomResizedCrop(224)) in validation and testing datasets when using transfer learning with VGG16? or only using normalization and nothing else?


If your input images are bigger than [224, 224] just normalization would be enough, otherwise you need to resize all image to the aforementioned size.

Here is the official source code of evaluation step:

normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406],
                                     std=[0.229, 0.224, 0.225])

            transforms.Scale(256),  # optional
            transforms.CenterCrop(224),  # optional

Source code of training using ImageNet dataset


1 Like

Many thanks!
Could you tell me how can I check the images sizes in a certain dataset?

If I understand correctly, you can find info about image sizes in the webpage of each dataset. If you are using your own custom dataset, you can check it in __getitem__ method by using CustomDataset. Here is post for such a situation: Custom Dataset with some preprocessing

Also, dataloading tutorial may help.

But a simple solution would be adding transforms.Resize(224) in the previous post right before ToTensor().

1 Like

Thank you, that’s what I’m looking for :smiley: