Functioning of Torch transform on a batch

Hello, I have a very simple doubt that’s bothering me.
I want to know, when I create a transform for a dataloader which takes a batch_size=32, do all the transforms happen exactly same to all the 32 samples in the batch?
For eg.

transforms = compose([RandomAffine(10), toTensor()])
# random affine transformation within (-10,10) degrees
ds = utils.DataLoader(some_custom_data_loader, transforms, batch_size = 32)

Now if I take any one batch generated from it, will all the samples in it have exactly same affine transformation(in degrees), say 5 deg to all of them?
Or will each sample(out of 32) have a different transformation (like [5, -1, 0, 9, -2,…(32 samples)] degrees)?

Excuse me if this is too simple doubt!
Thank you in advance!

Hey @Ajinkya_Ambatwar

I have made a GIST that takes an image and transforms is with RandomAffine(10). This indeed randomly transforms each image in the batch with a random degree.

I would also like to add that, in the code snippet you have provided, I guess you have mistyped utils.DataLoader, it should have been utils.data.DataLoader. Another little thing to add here is that a DataSet has a transform parameter. The GIST provided has all that you would need for an ablation study.

Hope this might help you :grinning_face_with_smiling_eyes:

Screen-Shot

1 Like

Hey @ariG23498 , thank you for a very clear explanation. I had one more doubt related to compose transforms. If I compose few transformations say RandomAffine, RandomCrop etc. are all the transformations applied on to the image in a single iteration? Or say few of the transforms are selected and applied in a single iteration?

A compose is a composition of many transforms all together. You can think of a compose as just another complex transform. To answer your question, yes, a compose should apply all the transforms it is made up of, to the image in a single operation.

1 Like

Thank you! That’s helpful!!