Solved by ptrblck in post #2 
              
              
                Instead of using random_split you could create two CustomDataset instances each one with the different transformation: 
train_dataset = CustomDataset(filenames, train_transform)
val_dataset = CustomDataset(filenames, train_transform)

and then use Subset on both with their corresponding indices: 
tr…