Skip to content

Instantly share code, notes, and snippets.

@weiaicunzai
Created June 22, 2018 13:48
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save weiaicunzai/e623931921efefd4c331622c344d8151 to your computer and use it in GitHub Desktop.
Save weiaicunzai/e623931921efefd4c331622c344d8151 to your computer and use it in GitHub Desktop.
compute cifar100 mean and std
def compute_mean_std(cifar100_dataset):
"""compute the mean and std of cifar100 dataset
Args:
cifar100_training_dataset or cifar100_test_dataset
witch derived from class torch.utils.data
Returns:
a tuple contains mean, std value of entire dataset
"""
data_r = numpy.dstack([cifar100_dataset[i][1][:, :, 0] for i in range(len(cifar100_dataset))])
data_g = numpy.dstack([cifar100_dataset[i][1][:, :, 1] for i in range(len(cifar100_dataset))])
data_b = numpy.dstack([cifar100_dataset[i][1][:, :, 2] for i in range(len(cifar100_dataset))])
mean = numpy.mean(data_r), numpy.mean(data_g), numpy.mean(data_b)
std = numpy.std(data_r), numpy.std(data_g), numpy.std(data_b)
return mean, std
@williamFalcon
Copy link

Do you have one for stl-10 and imagenet?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment