1

I am trying to understand this particular set of compose transforms:

transform= transforms.Compose([transforms.Resize((224,224) interpolation=torchvision.transforms.InterpolationMode.BICUBIC),\
transforms.CenterCrop(224),transforms.ToTensor(),\
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])])

Does it make sense (and is it legit) to do centercrop after transforms - with the same size parameter? I would have thought resize itself is giving the centercrop but I see in the repos that centercrop is composed after resize - both with exactly the same sizes. I wonder what is the use of doing such a thing. For the sake of completeness, I would like to add that my input image sizes vary (ie they are all not of the same dims).

thanks!

AJW
  • 5,569
  • 10
  • 44
  • 57

1 Answers1

1

I would have thought resize itself is giving the center crop.

Function T.Resize won't center crop your image, the center will stay the same since you are only resizing the original image, i.e. proportions are kept and the original center remains at the center. Applying a crop of the same shape as the image - since it's just after the resize - with T.CenterCrop doesn't make any difference since you are cropping nothing out of the image.

If you change the sizes of your T.CenterCrop, then this and the order you apply both transforms will matter greatly.

Ivan
  • 34,531
  • 8
  • 55
  • 100
  • thank you for this awesome explanation. So, as things stand, in the transform I have shown, `CenterCrop` will have no effect since it is of the same size as resize and is applied directly after resize. Is my understanding correct? Thank you for your help. – AJW Sep 26 '21 at 11:22
  • Have you tried looking w/ and w/o it? – Ivan Sep 26 '21 at 11:31
  • I did and I did not see a difference - but, since I was looking at an image, I was unsure if it did something or not (as you can imagine). Hence my question (more of a paranoid clarification) – AJW Sep 26 '21 at 11:34