Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong normalization? #86

Closed
lars76 opened this issue Oct 25, 2021 · 6 comments
Closed

Wrong normalization? #86

lars76 opened this issue Oct 25, 2021 · 6 comments

Comments

@lars76
Copy link

lars76 commented Oct 25, 2021

Where does the mean/std come from in ScalingLayer? The VGG16 mean/std is mean = [0.485, 0.456, 0.406] and std = [0.229, 0.224, 0.225].

@richzhang
Copy link
Owner

Thanks for the question. This has caused some confusion. The mean/std is recomputed to expect images from [-1, +1] instead of [0, +1] (which is what the values are for above). After the scaling layer, the results are the same.

@lars76
Copy link
Author

lars76 commented Oct 25, 2021

Thank you for the quick response. I should have read more carefully the other issues :)

Here the computation in detail if somebody comes across this issue. Let us say we have a pixel in the R-channel with a pixel value of 240. I rescale it to [-1, 1] with 2 * 240/255 - 1 = 15/17. Then I normalize it with ScalingLayer and get (15/17 - -0.030)/0.458 = 1.99203. Regular VGG would do (240/255 - 0.485)/0.229 = 1.99203. So the normalization is indeed correct.

@lars76 lars76 closed this as completed Oct 25, 2021
@98mxr
Copy link

98mxr commented Dec 1, 2022

I have a small problem. Since it is to be compatible with imagenet's mean/std, it is not good to input the img of [0, 1] from the beginning.

@Zyriix
Copy link

Zyriix commented Jun 6, 2023

Still confused about this.
If my inputs is already normalized by imagenet mean std.
Eg: x (0-1)
x = (x - imgnet_mean)/imgnet_val

if i do this before i put it into lpips , does it means that i can just delete the scaling layers?

@richzhang
Copy link
Owner

Yes, that's right

@Zyriix
Copy link

Zyriix commented Jun 7, 2023

Yes, that's right

ok, thank you : )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants