From 682a10d4f6081dc27be2b834f3a60189c214800a Mon Sep 17 00:00:00 2001 From: Mark Safronov Date: Thu, 2 Jan 2025 14:33:57 +0100 Subject: [PATCH] denormalization example For transforms.Normalize, added an explanation in the docblock on how to revert the performed normalization. --- torchvision/transforms/transforms.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/torchvision/transforms/transforms.py b/torchvision/transforms/transforms.py index 07932390efe..3de87b0b1c3 100644 --- a/torchvision/transforms/transforms.py +++ b/torchvision/transforms/transforms.py @@ -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.