How to make multiple crops for images

Is there any implementation of multiple crops in pytorch? I’ve look up in pytorch document, but there are only

class torchvision.transforms.CenterCrop(size)

class torchvision.transforms.RandomCrop(size, padding=0)

class torchvision.transforms.RandomSizedCrop(size, interpolation=2)

I think all these transforms will return one crop of an image. So how to get multiple sub-crops such as 10 sub-crops(4 coners + 1 center with(out) flips).

Thanks!

you need to write your own transform.

OK, thanks for your reply

Has anyone implemented multi-crop testing transforms efficiently?

I have coded a custom transform class to generate N random crops with padding size and number of random crops:


and here’s a test script:

1 Like

You can place the data loading step inside a loop with number of loops equal number of crops required per image/

data_transforms = transforms.Compose([
        transforms.RandomCrop(200),
        transforms.RandomHorizontalFlip(),
        transforms.ToTensor()
    ])
image_dataset_hazy = torchvision.datasets.ImageFolder('/home/Desktop/Data3',transform= data_transforms)   

Place the above code (and after it) inside loop.