question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature Request] Un-Normalize Image Tensor

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

24reactions
fmassacommented, Jun 7, 2018

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

0reactions
varunagrawalcommented, Feb 13, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to normalize images in PyTorch ? - GeeksforGeeks
Normalization in PyTorch is done using torchvision.transforms.Normalize(). This normalizes the tensor image with mean and standard deviation ...
Read more >
Simple way to inverse transform ? Normalization - vision
I'm using torchvision.transforms to normalize my images before sending them to a pre trained ... [Feature Request] Un-Normalize Image Tensor.
Read more >
How to normalize an image using pytorch - ProjectPro
Step 1 - Import library · Step 2 - Load the Image · Step 3 - Convert to tensor · Step 4 -...
Read more >
Feature Extractor — transformers 4.7.0 documentation
A feature extractor is in charge of preparing input features for a multi-modal ... normalization, and conversion to Numpy, PyTorch, and TensorFlow tensors....
Read more >
Complete Guide to PyTorch Normalize - eduCBA
In the first step, we need to load and visualize the images and plot the graph as per requirement. · In the second...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found