I using the same code but its not working for me…
I have initially created a dataset from ImageFolder and than used random_split to get the train and val sets and than I am trying to apply transformations with the method above but its not working
As previously described: if you want to add the transformation to the internal .transform attribute late (I would not recommend to use this approach) you would have to index the internal dataset via dataset.dataset.transform.
Manipulating the internal .transform attribute assumes that self.transform is indeed used to apply the transformations.
While this might be the case for e.g. MNIST other datasets could use other attributes (e.g. self.image_fransform) and you would need to add this manipulation according to the real implementation (which could of course also change between releases).
The right approach is thus to set the transformations once during the initialization of the Dataset and allow the Dataset to handle the transformations internally without depending on its actual implementation.