Vision: [Feature Request] Un-Normalize Image Tensor

Created on 5 Jun 2018  路  3Comments  路  Source: pytorch/vision

Basically the inverse of transforms.Normalize as this will allow us to visualize tensors during training more easily.

Most helpful comment

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

All 3 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!
I'll fix my comment!

Was this page helpful?
0 / 5 - 0 ratings