-
Notifications
You must be signed in to change notification settings - Fork 7k
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
[Feature Request] Un-Normalize Image Tensor #528
Comments
I agree with @karandwivedi42 and the comment that he linked to. If you want to reverse the normalization, all you need to do is to use a new normalization, with slight modifications: mean = torch.tensor([1, 2, 3], dtype=torch.float32)
std = torch.tensor([2, 2, 2], dtype=torch.float32)
normalize = T.Normalize(mean.tolist(), std.tolist())
unnormalize = T.Normalize((-mean / std).tolist(), (1.0 / std).tolist()) EDIT: fixed thanks to @karandwivedi42 comment |
Thanks @karandwivedi42 , my bad! |
Hey, This does not seem to work for me at all. I am using the following code:
Could you please tell me what am I doing wrong :( |
For future reference this is the correct answer:
|
Your solution is pretty much what @fmassa laid out. If you look at his unnormalize method, he is computing the negative mean divided by the standard deviation. |
I also had issues with the solution above. Seems like Compose(
[
Normalize(
mean=tuple(-m / s for m, s in zip(mean, std)),
std=tuple(1.0 / s for s in std),
max_pixel_value=1.0,
),
FromFloat(max_value=255, dtype="uint8"),
]
) |
Basically the inverse of
transforms.Normalize
as this will allow us to visualize tensors during training more easily.The text was updated successfully, but these errors were encountered: