pytorch-cifar
pytorch-cifar copied to clipboard
Question regarding CIFAR10 standard deviation
I computed the mean and standard deviation of cifar dataset (train). While the means match, the standard deviations do not:
mean = [0.4913996458053589, 0.48215845227241516, 0.44653093814849854]
std = [0.2470322549343109, 0.24348513782024384, 0.26158788800239563]
Relevant line from main.py:
https://github.com/kuangliu/pytorch-cifar/blob/49b7aa97b0c12fe0d4054e670403a16b6b834ddd/main.py#L34
I am wondering what is the cause of this discrepancy. Relevant code that I used to compute these stats:
datasets = [ torchvision.datasets.CIFAR10('./data', download=True, train=True, transform=torchvision.transforms.ToTensor()) ]
channels = 3
total = torch.zeros(channels)
total_sq = torch.zeros(channels)
num = 0
for ds in datasets:
dl = DataLoader(ds, batch_size=1000)
for images, targets in dl:
total += torch.sum(images, (0, 2, 3))
total_sq += torch.sum(images * images, (0, 2, 3))
num += images.shape[0] * images.shape[2] * images.shape[3]
mean = total / num
mean_sq = total_sq / num
std = torch.sqrt(mean_sq - mean**2)
print(f'mean = {mean.tolist()}, std = {std.tolist()}')