how to increase number of images with data augmentation

I’m trying to apply data augmentation with pytorch. In particular, I have a dataset of 150 images and I want to apply 5 transformations (horizontal flip, 3 random rotation ad vertical flip) to every single image to have 750 images, but with my code I always have 150 images.

‘train’: transforms.Compose([
transforms.Resize(224),
transforms.RandomHorizontalFlip(),
transforms.RandomRotation(degrees = (90,90)),
transforms.RandomRotation(degrees = (180,180)),
transforms.RandomRotation(degrees = (270,270)),
transforms.RandomVerticalFlip(p=1),
transforms.ToTensor(),
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
])

It performs the transformations on fly in each iteration. So it will not increase the actual scale of your data on your disk

1 Like

If you want more images you need to generate them ahead of time. There are a number of libraries that can help you do this. Albumentations and Imgaug come to mind.

But the greater question is what are you trying to accomplish with transformations? If you just want more random samples then train your networks for a longer number of epochs. Every epoch your dataset will be transformed differently (since you have random transformations there) so you’ll get a fresh set of 150 images for your network to chew on.

Lastly, you don’t want to be chaining your transforms as you’ve done above since you are doing the rotations one after another and thus potentially undoing your intended result.

5 Likes

is there any package for 3d image?

I also want to know how to do that. Did you find the solution?