Transform not getting applied on CustomDataset Pytorch
I images with folder structure as following :
root_dir
│
└───folder1
│   │   file011.png
│   │   file012.png
│   
└───folder2
|   │   file021.png
|   │   file022.png
|
└───folder2
    │   file031.png
    │   file032.png
...

Now I wanted to create a CustomeDataset without labels in PyTorch (since I am using it for GANs)
So I did the following :
class CurrencyDataset(Dataset):
    '''
    Currency Dataset with no labels
    '''
    def __init__(self, type, transform):
        '''
        Parameters
            type : &quot;Train&quot; or &quot;Test&quot;
            transform : Transformations to be applied 
        '''
        root_dir = &quot;indian-currency-notes-classifier/&quot; 
        # Storing images in a list
        self.data = []
        self.transform = transform
        dir = os.path.join(root_dir, type)
        for note in os.listdir(dir) :
            note_dir = os.path.join(dir, note)
            for img_name in os.listdir(note_dir):
                img = io.imread(os.path.join(note_dir, img_name))
                self.data.append(img)

    def __len__(self):
        return len(self.data)
        
    def __getitem__(self, idx):
        if torch.is_tensor(idx):
            idx = idx.tolist()
        x = self.data[idx]
        if self.transform :
            x = self.transform(x)
        return x

and used the following transformations :
transform = transforms.Compose([
    transforms.Normalize([0.5, 0.5, 0.5], [0.5, 0.5, 0.5]),
    transforms.RandomRotation(15),
    transforms.Resize((224, 224)),
    transforms.ToTensor(),
])

train_ds = CurrencyDataset(&quot;Train&quot;, transform)

but on checking the shape and values of the Tensors, I found out that transformations were not getting applied
train_ds.data[0].shape
&gt;&gt; (1072, 1154, 3)

I am a bit new to PyTorch so please let me know If I am doing something wrong here or What needs to be done to make it correct ?

You forgot to assign the transform object as an attribute of the instance. This, in turn, means self.transform evaluates to None in the __getitem__ function. Simply add the following in the __init__:
self.transform = transform


Additonally, you are not calling the proper function (__getitem__) with train_ds.data[0].shape, instead it should be train_ds[0] (in other words: train_ds.__getitem__(0)).

Finally, your pipeline doesn't have the correct order of transforms as T.Resize expects a torch.Tensor, not a PIL image:
transform = T.Compose([
    T.RandomRotation(15),
    T.Resize((224, 224)),
    T.ToTensor(),
    T.Normalize([0.5, 0.5, 0.5], [0.5, 0.5, 0.5])])

