How the means and stds get calculated in the Transfer Learning tutorial

I’m going through the Pytorch Transfer Learning tutorial at: http://pytorch.org/tutorials/beginner/transfer_learning_tutorial.html#visualize-a-few-images

In the data augmentation stage, there is the following step to normalize images:

transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])

I can understand why it’s doing this but I can’t find how the mean and std values get calculated? I tried to calculate the mean on the train data set and the mean values are:

array([ 0.11727478,  0.04542569, -0.28624609], dtype=float32)
1 Like

All pre-trained models should be preprocessed in that same way.
Those values are mean, stddev for ImageNet, not for your specific dataset. You can also check the discussion here.

1 Like

This makes sense now. It’ll be much clearer if the author can add a line of comment in the tutorial to say why it’s using those values.