randomized data trasnformation in pytorch
I want to rotate all the images in my Dataset with a random degree between [0,180]. If I compose a transformation function and pass my images to this function in the __getitem__ function of my Dataset class. Does this mean:

every single image is randomly rotated?
images in each batch get rotated with an identical degree but this degree randomly changes across batches (calls)?

I would appreciate it if you could clarify this for me.

In mapped datasets, __getitem__ is used to select a single element from the dataset.
The way random transformations work in PyTorch/Torchvision is they apply a unique random transformation each time the transform is called. This means:

Every single image in your dataset is indeed randomly rotated but not by the same amount.

Additionally images in a batch get different transformations. In other words, elements in the batch won't share the same transformation parameters.



Here is a minimal example with a dummy dataset:
class D(Dataset):
    def __init__(self, n):
        super().__init__()
        self.n = n
        self.transforms = T.Lambda(lambda x: x*randint(0,10))
    
    def __len__(self):
        return self.n

    def __getitem__(self, index):
        x = self.transforms(index)
        return x

Here you can see the random transformer inter and intra batches:
&gt;&gt;&gt; dl = DataLoader(D(10), batch_size=2)

&gt;&gt;&gt; for i, x  in enumerate(dl):
...     print(f'batch {i}: elements {2*i} and {2*i+1} = {x.tolist()}')
batch 0: elements 0 and 1 = [0, 2]
batch 1: elements 2 and 3 = [14, 27]
batch 2: elements 4 and 5 = [32, 40]
batch 3: elements 6 and 7 = [60, 0]
batch 4: elements 8 and 9 = [80, 27]

