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

Comment inconsistent with the code related to Normalize transformation #1818

Closed
dsimonovic opened this issue Feb 4, 2022 · 3 comments · Fixed by #2405
Closed

Comment inconsistent with the code related to Normalize transformation #1818

dsimonovic opened this issue Feb 4, 2022 · 3 comments · Fixed by #2405
Assignees
Labels
docathon-h1-2023 A label for the docathon in H1 2023 intro medium

Comments

@dsimonovic
Copy link

dsimonovic commented Feb 4, 2022

Normalize transform does not normalize tensor per se. Only if the correct mean and standard deviation are passed as arguments will the output be "normalized" as in zero mean and standard deviation of 1.0.
On its own, all the transform does is shift and scale an image using the arguments passed.

Line 289 of code,
Normalize(mean=(0.5,0.5,0.5) and std=(0.5,0.5,0.5))
Which shifts values by 0.5 and scale by 1/0.5
Comment bellow states that above Normalize transformation would make mean zero and standard deviation 0.5, which is not quite (on CIFAR10 final mean = -0.053, and std is 0.503).

As initial colors have values between 0.0 and 1.0, after Normalized transform, they would be shifted by 0.5 and scaled by 1/0.5 making the final values fall in the range -1.0 and 1.0.

transform = transforms.Compose(
    [transforms.ToTensor(),
     transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])


##########################################################################
# Here, we specify two transformations for our input:
#
# -  ``transforms.ToTensor()`` converts images loaded by Pillow into 
#    PyTorch tensors.
# -  ``transforms.Normalize()`` adjusts the values of the tensor so
#    that their average is zero and their standard deviation is 0.5. Most

cc @suraj813

@svekars svekars added the intro label Oct 19, 2022
@svekars
Copy link
Contributor

svekars commented Mar 6, 2023

@svekars svekars added medium docathon-h1-2023 A label for the docathon in H1 2023 labels May 31, 2023
@HemanthSai7
Copy link
Contributor

/assigntome

@HemanthSai7 HemanthSai7 removed their assignment Jun 1, 2023
@zabboud
Copy link
Contributor

zabboud commented Jun 1, 2023

/assigntome

zabboud added a commit to zabboud/tutorials that referenced this issue Jun 2, 2023
svekars pushed a commit that referenced this issue Jun 2, 2023
…ansforms.Normalize (#2405)

* Fixes #2083 - explain model.eval, torch.no_grad
* set norm to mean & std of CIFAR10(#1818)
---------

Co-authored-by: Svetlana Karslioglu <svekars@fb.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docathon-h1-2023 A label for the docathon in H1 2023 intro medium
Projects
None yet
4 participants