@@ -288,7 +288,7 @@ def num_flat_features(self, x):
288
288
289
289
transform = transforms .Compose (
290
290
[transforms .ToTensor (),
291
- transforms .Normalize ((0.5 , 0.5 , 0.5 ), (0.5 , 0.5 , 0.5 ))])
291
+ transforms .Normalize ((0.4914 , 0.4822 , 0.4465 ), (0.2470 , 0.2435 , 0.2616 ))])
292
292
293
293
294
294
##########################################################################
@@ -297,9 +297,28 @@ def num_flat_features(self, x):
297
297
# - ``transforms.ToTensor()`` converts images loaded by Pillow into
298
298
# PyTorch tensors.
299
299
# - ``transforms.Normalize()`` adjusts the values of the tensor so
300
- # that their average is zero and their standard deviation is 0.5 . Most
300
+ # that their average is zero and their standard deviation is 1.0 . Most
301
301
# activation functions have their strongest gradients around x = 0, so
302
302
# centering our data there can speed learning.
303
+ # The values passed to the transform are the means (first tuple) and the
304
+ # standard deviations (second tuple) of the rgb values of the images in
305
+ # the dataset. You can calculate these values yourself by running these
306
+ # few lines of code:
307
+ # ```
308
+ # from torch.utils.data import ConcatDataset
309
+ # transform = transforms.Compose([transforms.ToTensor()])
310
+ # trainset = torchvision.datasets.CIFAR10(root='./data', train=True,
311
+ # download=True, transform=transform)
312
+ #
313
+ # #stack all train images together into a tensor of shape
314
+ # #(50000, 3, 32, 32)
315
+ # x = torch.stack([sample[0] for sample in ConcatDataset([trainset])])
316
+ #
317
+ # #get the mean of each channel
318
+ # mean = torch.mean(x, dim=(0,2,3)) #tensor([0.4914, 0.4822, 0.4465])
319
+ # std = torch.std(x, dim=(0,2,3)) #tensor([0.2470, 0.2435, 0.2616])
320
+ #
321
+ # ```
303
322
#
304
323
# There are many more transforms available, including cropping, centering,
305
324
# rotation, and reflection.
0 commit comments