Could you try to pass just the classes without calling them, e.g. normalize instead of normalize(img).
Also, normalization should come after the ToTensor transformation.
Usually you would apply the transformations on each sample in the __getitem__ method of your Dataset. Have a look at the data loading tutorial for an example.
If you wrap your Dataset in a DataLoader with multiple workers, the loading and processing will be applied using multiprocessing in the background while your GPU is busy with the training.
While a lot of torchvision.transforms are applied on PIL.Images, Normalize is applied on a tensor which is why I suggested to call it after ToTensor.
Note that ToTensor will return a tensor image with values in the range [0, 1]. Your mean and std in Normalize should therefore also be relative to this range.
Is it possible to insert a new transform to an already composed transform.
For example: if I have train_transform = transforms.Compose( [transforms.ToTensor(), transforms.Normalize(mean=mean, std=std)])
And later I want to add RandomFlip to this train_transform.
transforms.Compose holds an internal list, which is passed as the initial argument to it and iterates all transformations in this list.
You could thus manipulate this list object directly via e.g. insert: