Image data augmentation in pytorch

The DataLoader doesn’t have access to the transformation in the standard use case as the samples are loaded and transformed in the Dataset separately.
Here is a small example:

transform = transforms.Compose([
    transforms.ToPILImage(),
    transforms.Resize((128,128)),
    transforms.RandomVerticalFlip(1),
    transforms.RandomHorizontalFlip(1),
    transforms.ColorJitter(brightness=(0.5,1.5),contrast=(1),saturation=(0.5,1.5),hue=(-0.1,0.1)),
    transforms.ToTensor(),
])

x = torch.randn(3, 224, 224)
out = transform(x)

You can either use the functional API as described here, torchvision.transforms.v2 which allows to pass multiple objects as described here, or any other library mentioned in the first link.