Does transforms.Compose applied to all Images?

I have Image data and I have custom augmentation classes for transforms.

transform_custom = [Rescale(256), RandomCrop(224), Resize(224)]

These classes are passed to transform and its output to DataLoader

transformed_dataset = Classification(df, transform=transforms.Compose(transform_custom))
dataloader = DataLoader(transformed_dataset, shuffle=True, num_workers=0, batch_size=4).


Does all Images undergo .all mentioned rescale, random_crop and resize transformations or Images and transformations are randomly selected to undergo transformations?

If all the Images undergo all transformations, How can I make selection of Images and selection of transformation random?

As per my observation, all images undergo all transformations from left to right! but the pytorch library undergoes transformation randomly. how can i implement this feature in my script

Yes the transformations you applied to the images are applied to all of them. If you want to have it applied randomly you could use different transformations like randomresizedcrop or something else. Just go into the docs and look for transforms with a probability argument those will apply to random images. You can also try to use the

torchvision.transforms.RandomApply(transforms, p=0.5)

transform also found in the docs to apply transformations randomly.

1 Like