Skip to content

Commit

Permalink
denormalization example
Browse files Browse the repository at this point in the history
For transforms.Normalize, added an explanation in the docblock on how to revert the performed normalization.
  • Loading branch information
hijarian authored Jan 2, 2025
1 parent d3beb52 commit 682a10d
Showing 1 changed file with 8 additions and 0 deletions.
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

0 comments on commit 682a10d

Please sign in to comment.