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

resolve issue 1818 by modifying mean and standard deviation in the transforms.Normalize #2405

Merged
merged 5 commits into from
Jun 2, 2023

Conversation

zabboud
Copy link
Contributor

@zabboud zabboud commented Jun 2, 2023

Fixes #1818

Description

Modified transforms.Normalize mean and standard deviation values to reflect CIFAR10 train mean and standard deviations

from

transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])

to

transforms.Normalize((0.4914, 0.4822, 0.4465), (0.2470, 0.2435, 0.2616))])

Modified the docstring to reflect the change, that the new mean and standard deviation will be 0 and 1, respectively. Also, additional details were added to explain how those values were generated:

#   The values passed to the transform are the means (first tuple) and the
#    standard deviations (second tuple) of the rgb values of the images in
#    the dataset. You can calculate these values yourself by running these
#    few lines of code:
#          ```
#           from torch.utils.data import ConcatDataset
#           transform = transforms.Compose([transforms.ToTensor()])
#           trainset = torchvision.datasets.CIFAR10(root='./data', train=True,
#                                        download=True, transform=transform)
#
#           #stack all train images together into a tensor of shape 
#           #(50000, 3, 32, 32)
#           x = torch.stack([sample[0] for sample in ConcatDataset([trainset])])
#           
#           #get the mean of each channel            
#           mean = torch.mean(x, dim=(0,2,3)) #tensor([0.4914, 0.4822, 0.4465])
#           std = torch.std(x, dim=(0,2,3)) #tensor([0.2470, 0.2435, 0.2616])  
# 
#          ```   

Checklist

cc @suraj813

@github-actions github-actions bot added intro docathon-h1-2023 A label for the docathon in H1 2023 medium and removed cla signed labels Jun 2, 2023
@netlify
Copy link

netlify bot commented Jun 2, 2023

Deploy Preview for pytorch-tutorials-preview ready!

Name Link
🔨 Latest commit d1b9d71
🔍 Latest deploy log https://app.netlify.com/sites/pytorch-tutorials-preview/deploys/64793d5f8a198d000842fd02
😎 Deploy Preview https://deploy-preview-2405--pytorch-tutorials-preview.netlify.app/beginner/introyt/introyt1_tutorial
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla signed docathon-h1-2023 A label for the docathon in H1 2023 intro medium
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Comment inconsistent with the code related to Normalize transformation
4 participants