MNIST mean and std

The values are the mean and standard deviation of the training split of MNIST.

import torch
from torchvision import datasets, transforms

transform = transforms.Compose([transforms.ToTensor()])
trainset = datasets.MNIST('mnist_train', train=True, download=True, transform=transform)
images = torch.stack(list(data[0] for data in trainset), dim=0)

print(images.shape) # torch.Size([60000, 1, 28, 28])
print(images.mean()) # tensor(0.1307)
print(images.std()) # tensor(0.3081)
3 Likes