How to preprocess input for pre trained networks?

Is this applicable to all imagenet models that come with Pytorch?
I remember in keras each model had it’s own specific preprocessing function,

Yes, this is the step has been used in all models of ImageNet.
Here is the link to ReadMe:

All of the mentioned models use this normalization.

@smth I have confusion regarding the use of same mean and std for all data. Why can’t we use per image in that way each image is independent for nomalization?

you can do that if you want, it depends on what one wants to do. I feel more comfortable with a single mean / std for the whole dataset – or else i think it amplifies artificacts in high-noise images

1 Like

What is best way to transform a tensor back to NumPy?
When it is scaled with 0.5,0.50.5 it is clear but how would you recommend it to do when scaling with:
normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406],std=[0.229, 0.224, 0.225])

What about grey scale images, what should the mean and SD be?

@qianguih / @mattmacy,

Do you mean we need to normalize to [0,1] set mean to 0 and std deviation 1 respectively before we AGAIN apply the following? Thanks

normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406],
                                     std=[0.229, 0.224, 0.225])

Yes, this transform has to be applied after the ToTensor() transform

How about mean/std value of RGBD input