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

A denormalization example in the dockblock for transforms.Normalize #8835

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions torchvision/transforms/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,14 @@ class Normalize(torch.nn.Module):
.. note::
This transform acts out of place, i.e., it does not mutate the input tensor.

Passing 0 as mean and 1 as std for a channel keeps the values in this channel unchanged.

As follows from the output formula above, to denormalize the tensor you can apply Normalize again with the following changes
in the mean and std:

* ``mean=[-m / s for m, s in zip(mean, std)]``
* ``std=[1.0 / s for s in std]``

Args:
mean (sequence): Sequence of means for each channel.
std (sequence): Sequence of standard deviations for each channel.
Expand Down