Solved by vfdev-5 in post #4 
              
              
                OK, I see. 
Personally, I’d perform the mapping inside Dataset before the training/validation code: 
train_dataset = ...  # your training dataset
val_dataset = ...  # your validation dataset etc

class TransformedDataset(torch.utils.data.Dataset):
    def __init__(self, dataset, transform_fn):
     …