Normalization by imagenet statistics strange behavior

pytorchnewbie: <p>So I was trying to normalize my cat image by the imagenet statistics when I ended up with values between -1 and &gt; 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 &gt; 1. I expected it to remain between 0 and 1…</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/a/8/a8f4f0c3f443e00e7596719bcced1f5b3aee3cc5.png" data-download-href="https://discuss.pytorch.org/uploads/default/a8f4f0c3f443e00e7596719bcced1f5b3aee3cc5" title="Screen Shot 2020-02-24 at 11.03.34 AM"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/a/8/a8f4f0c3f443e00e7596719bcced1f5b3aee3cc5_2_562x500.png" alt="Screen Shot 2020-02-24 at 11.03.34 AM" data-base62-sha1="o6EZQPB5N2DdZgAPVGFHpcUqdzD" width="562" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/a/8/a8f4f0c3f443e00e7596719bcced1f5b3aee3cc5_2_562x500.png, https://discuss.pytorch.org/uploads/default/optimized/3X/a/8/a8f4f0c3f443e00e7596719bcced1f5b3aee3cc5_2_843x750.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/a/8/a8f4f0c3f443e00e7596719bcced1f5b3aee3cc5_2_1124x1000.png 2x" data-dominant-color="F2F2F2"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">Screen Shot 2020-02-24 at 11.03.34 AM</span><span class="informations">1158×1030 127 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>After;</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/f/9/f91018a2a940f2eb51c3933f2c59958d0d8bacb9.png" data-download-href="https://discuss.pytorch.org/uploads/default/f91018a2a940f2eb51c3933f2c59958d0d8bacb9" title="Screen Shot 2020-02-24 at 11.05.28 AM"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/f/9/f91018a2a940f2eb51c3933f2c59958d0d8bacb9_2_690x485.png" alt="Screen Shot 2020-02-24 at 11.05.28 AM" data-base62-sha1="zxjnjXqmOV1ik813S8mSrsGmGg1" width="690" height="485" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/f/9/f91018a2a940f2eb51c3933f2c59958d0d8bacb9_2_690x485.png, https://discuss.pytorch.org/uploads/default/optimized/3X/f/9/f91018a2a940f2eb51c3933f2c59958d0d8bacb9_2_1035x727.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/f/9/f91018a2a940f2eb51c3933f2c59958d0d8bacb9.png 2x" data-dominant-color="F2F2F2"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">Screen Shot 2020-02-24 at 11.05.28 AM</span><span class="informations">1080×760 102 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

albanD: <p>Hi,</p>
<p>The normalization won’t keep it between 0 and 1.<br>
It is only doing: <code>(inp - mean)/std</code>.</p>
<p>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.</p>

pytorchnewbie: <p>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…</p>

albanD: <p>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).</p>

pytorchnewbie: <p>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!</p>

albanD: <blockquote>
<p>its fine to pass it into the model because the image itself is an outlier w respect to the imagenet database?</p>
</blockquote>
<p>Exactly that !</p>
<p>You did not “normalize one image” you “normalize wrt to the image full dataset”.</p>

pytorchnewbie: <p>That makes sense. Thanks so much !!</p>