Clarification: random resize / crop / resized_crop

Hello. I was reading the doc of the following three transformations.

Is the operation of RandomCrop + Resize EQUIVALENT EXACTLY to RandomResizedCrop?

Are there any differences? Is there any reason other than conveniences to have RandomResizedCrop than the combination of RandomCrop + Resize operations?

They operate exactly the same.
However, RandomResizedCrop runs faster than Crop + Resize

import torch
import torchvision.transforms as transforms
from PIL import Image
import glob
import time

image_path = glob.glob('*.png')
image = Image.open(image_path[0])

c_r = transforms.Compose([
    transforms.RandomCrop(size=(100, 100)),
    transforms.Resize(size=(100, 100))
    ])

r_c = transforms.Compose([
    transforms.RandomResizedCrop(size=(100, 100))
    ])

start = time.time()
out = c_r(image)
print(f'{time.time() - start}') # 0.012

start = time.time()
out = r_c(image)
print(f'{time.time() - start}') # 0.003
1 Like

Thanks for the information. What could be the cause of the execution gap? The implementation details should be very similar! :thinking: