Normalization by imagenet statistics strange behavior

So I was trying to normalize my cat image by the imagenet statistics when I ended up with values between -1 and > 1 after the normalization, and am confused as to why. As you can see below, the initial image has values between 0 and 1. And as you see from the second image below, after the normalization its between -1 and > 1. I expected it to remain between 0 and 1…

After;

Hi,

The normalization won’t keep it between 0 and 1.
It is only doing: (inp - mean)/std.

It just uses the statistics from the imagenet dataset so that if you compute the mean and std of the images from imagenet with these transformation, you will get respectively 0 and 1.

Hi! Thank you! That makes sense to me, but isn’t it weird to pass in that range of values into a pretrained resnet? In the past I’ve always passed in 0…1 images or -1…1 images…

Well, you just correct the mean and std. So if you have outlier that have very very large value, they will still have very very larger values (and will skew the mean by a lot).

Im not sure I follow… so I just normalized my image, and now it has between -1 … 2.7. Are you saying I should do additional processing to this image now, or are you just saying that thats the way it is and its fine to pass it into the model because the image itself is an outlier w respect to the imagenet database? Thanks!

its fine to pass it into the model because the image itself is an outlier w respect to the imagenet database?

Exactly that !

You did not “normalize one image” you “normalize wrt to the image full dataset”.

1 Like

That makes sense. Thanks so much !!