It depends on your workflow.
The manipulation itself would work and valset
would use the new_transform
when self.transform
is called. However, if you are wrapping valset
into a DataLoader
using multiple workers, you have to be careful when (and if) this change will be visible.
When you start iterating the DataLoader
, each worker will create a copy of the Dataset
until the loop finishes. Changing the valset
via loader.dataset.transform = new_transform
would then be visible in the next epoch (or when you restart the DataLoader
loop). Also, if you are using persistent_workers=True
, the workers would never restart (and thus also never create a new copy of the dataset) and thus the change won’t be used.
1 Like