Your DataLoader might return a list, not a tensor, so you would have to index data before calling size(0) on it.
Also, as mentioned in the thread, the var calculation should yield a better result that the std, since you would now be calculating the average of the stddevs.



 the_coder:

Now where should i run the loop ? In Dataloader object or in the image itself?


You should run this calculation once before your setup of the training procedure.



 the_coder:

My second question is after i find the mean and std dev what is the code to apply the transorms operation


Since your images are grayscale and will thus have a single channel by default, you should use the second approach.



 the_coder:

And my third question is how can i apply this mean and std() to my dataset , since it is a custom dataset i will not be able to follow instruction where the datasets are imported from torchvision.


I don’t understand this question completely.
If you are using a custom Dataset (or e.g. ImageFolder), you would only have to apply the Normalize transformation using your calculated stats.
Could you explain a bit, which instructions you won’t be able to follow?