AI Logic

Datasets and Benchmarks

ImageNet-C

Updated:

How ImageNet-C is built and evaluated. The left side shows the flow: ImageNet validation images are resized to a common size, 15 kinds of corruption are applied at 5 severity levels and saved as JPEG, divided into 4 categories (noise, blur, weather, digital), plus the 4 extra validation corruptions. The right side shows the flow from error rates per corruption and severity to the per-corruption error normalized by AlexNet (CE), averaged over the 15 kinds to give mCE.

Overview

ImageNet-C is an evaluation-only dataset made by mechanically applying common corruptions, such as noise, blur, fog, and JPEG compression, to the validation images of ImageNet. It was created by Hendrycks of the University of California, Berkeley and Dietterich of Oregon State University and presented in an ICLR 2019 paper. The C in the name stands for "corruption".

It was created because image classification models reach near-human accuracy on clean photos yet make large mistakes under slight noise or blur. Unlike adversarial examples, which are crafted deliberately to cause errors, there was no yardstick for measuring, under uniform conditions, how well models withstand corruptions that occur in everyday use, such as camera shake, snow and fog, or compression during transmission. ImageNet-C distributes 15 kinds of corruption × 5 severity levels as fixed images, so every model can be compared on the same images.

ImageNet-C is like an "eye test" for models. Even with the same accuracy on clean images, how much a model's vision degrades under poor conditions such as fog or camera shake differs greatly between models.

Contents: Construction, Corruption Types, and Format

Construction proceeds as follows.

  1. Prepare the original images. The 50,000 validation images (1,000 classes) of ImageNet (ILSVRC 2012) are used.
  2. Normalize the size. The shorter side is resized to 256 pixels, and the central 224×224 is cropped.
  3. Apply corruptions. 15 kinds of corruption are applied at 5 severity levels, 1–5. Where possible, corruptions vary even at the same severity; for example, the fog pattern differs from image to image.
  4. Save as JPEG. Images are saved as lightly compressed JPEGs (quality 85 in the official generation code). As a result, even Gaussian noise images, for example, carry a slight JPEG compression artifact on top.

The result is 75 combinations, 15 kinds × 5 levels, each with 50,000 images.

Corruption types fall into 4 categories.

CategoryCorruptions (the 15 used for evaluation)Extra for validation
NoiseGaussian noise, shot noise, impulse noiseSpeckle noise
BlurDefocus blur, glass blur, motion blur, zoom blurGaussian blur
WeatherSnow, frost, fog, brightnessSpatter (rain or mud on the lens)
DigitalContrast, elastic transform, pixelate, JPEG compressionSaturate

The 4 extra validation corruptions are for tuning methods without overfitting to the 15 evaluation corruptions. Choosing hyperparameters on the evaluation corruptions would overestimate robustness.

Format: a folder for each corruption name and severity, containing class folders identical to ImageNet's (e.g., JPEGs of a class's images under gaussian_noise/3/n01440764/). It can be read directly with PyTorch's ImageFolder. It is distributed on Zenodo as 5 tar files: noise (about 21 GB), blur (about 7 GB), weather (about 12 GB), digital (about 7 GB), and the extra validation corruptions (about 15 GB).

Other versions include CIFAR-10-C, CIFAR-100-C, Tiny ImageNet-C (200 classes, 64×64), and ImageNet 64×64-C, which apply the same corruptions to small images, as well as a version matched to the input size of Inception models. The same paper also introduced ImageNet-P, which measures prediction stability on video-like sequences in which corruption gradually intensifies.

Evaluation Protocol

The procedure is as follows.

  1. Prepare a model ff that has not been trained on ImageNet-C corruptions, and measure its top-1 error rate on clean validation images, EcleanfE^f_{\mathrm{clean}}.
  2. For each corruption cc and severity ss (1≤s≤51 \le s \le 5), measure the top-1 error rate Es,cfE^f_{s,c}.
  3. For each corruption, sum the error rates over the 5 levels and divide by the same quantity for AlexNet to obtain the Corruption Error (CE).
  4. Average the 15 CEs to obtain the mCE (mean Corruption Error).
CEcf=∑s=15Es,cf∑s=15Es,cAlexNet,mCEf=115∑cCEcf\mathrm{CE}^f_c = \frac{\sum_{s=1}^{5} E^f_{s,c}}{\sum_{s=1}^{5} E^{\mathrm{AlexNet}}_{s,c}}, \qquad \mathrm{mCE}^f = \frac{1}{15} \sum_{c} \mathrm{CE}^f_c

The division by AlexNet is because corruptions differ in difficulty. For example, fog hides objects more easily than a brightness change, and averaging without normalization would let the hardest corruptions dominate. AlexNet's mCE is 100% by definition, so below 100% means more robust to corruptions than AlexNet.

mCE also includes how accurate the model is on clean images. To look only at the degradation caused by corruptions, use the relative mCE, which subtracts the clean-image error rate.

Relative CEcf=∑s=15(Es,cf−Ecleanf)∑s=15(Es,cAlexNet−EcleanAlexNet)\mathrm{Relative\ CE}^f_c = \frac{\sum_{s=1}^{5} \left( E^f_{s,c} - E^f_{\mathrm{clean}} \right)}{\sum_{s=1}^{5} \left( E^{\mathrm{AlexNet}}_{s,c} - E^{\mathrm{AlexNet}}_{\mathrm{clean}} \right)}

As a training rule, the paper requires models to be trained on the ImageNet training data (plus any other data) and not on ImageNet-C corruptions. Ordinary data augmentation such as cropping and horizontal flipping, and other corruptions such as uniform noise, are allowed; if a model is trained on ImageNet-C corruptions, this must be stated explicitly.

Results from the paper are as follows (models trained only on ImageNet; Table 1 and the text of Section 5).

ModelClean error rate (%)mCE (%)Relative mCE (%)
AlexNet43.5100.0100.0
SqueezeNet41.8104.4―
VGG-19 + BN25.881.6―
ResNet-5023.976.7105.0
DenseNet-12125.673.492.8
DenseNet-16122.966.484.6
ResNeXt-5022.968.288.6
ResNeXt-10121.062.280.1

ResNet-50's mCE dropped to 69.3% when trained with Stylized ImageNet (images with altered artistic style) mixed in, and to 74.5% with CLAHE (contrast-limited adaptive histogram equalization) preprocessing. In the official repository's table, ResNet-50 reaches 65.3% with AugMix and 53.6% with DeepAugment combined with AugMix.

Training on ImageNet-C corruptions (or the same processing) lowers mCE greatly, but that only makes the model robust to "corruptions it has already seen". The paper does not recommend such training, and when comparing, always check that the data augmentation used in training does not overlap with the evaluation corruptions.

Usage and Historical Significance

ImageNet-C became the standard benchmark for numerically comparing classification models' "robustness to everyday corruptions".

  • It showed that clean-image accuracy alone does not reveal robustness. In the paper, progress from AlexNet to ResNet lowered mCE, but relative mCE barely improved (ResNet-50 at 105.0%). Much of the gain in accuracy was not robustness to corruptions itself.
  • It became a venue for comparing methods that improve robustness. Papers on data augmentation such as AugMix, training approaches such as supervised contrastive learning, and new architectures report ImageNet-C mCE alongside ImageNet accuracy.
  • It pioneered distribution shift benchmarks. The same authors also released ImageNet-A, natural photos that cause errors, and ImageNet-R (30,000 images), renditions such as paintings, cartoons, and sculptures. Whereas ImageNet-C measures "mechanical corruptions", these measure "different real-world appearances".

Caveats

License: ImageNet-C as distributed on Zenodo is CC BY 4.0, and the official repository of the corruption code is Apache License 2.0. However, the images themselves are processed versions of ImageNet validation images, and the copyright of the original photos belongs to their photographers.

It is safest to assume that ImageNet's terms of use (limited to non-commercial research and education) apply to the original images. Check ImageNet's terms before using it in commercial products or redistributing the images.

Do not stack preprocessing: the images are already cropped to 224×224. Applying "resize to 256 then crop 224" as in ordinary ImageNet evaluation resizes the corrupted images again, and the values will deviate from the official evaluation. The official evaluation code only does a central 224×224 crop and normalization.

Use the distributed JPEGs: the corruption functions are also distributed as a package (imagenet_c), but to keep evaluation consistent, the authors strongly recommend using the distributed JPEGs rather than generating corruptions in memory. The details of the corruptions change with the versions of random number generators and image processing libraries.

Use the published AlexNet values: the AlexNet error rates used to normalize CE are listed per corruption in Appendix D of the paper and on Zenodo (e.g., Gaussian noise 88.6%, brightness 56.5%). Re-measuring AlexNet yourself makes results incomparable with other papers.

Data size: the 5 tar files total about 66 GB. Trying the smaller CIFAR-10-C or Tiny ImageNet-C first allows faster iteration.

Limited to mechanical corruptions: the corruptions are generated by fixed formulas and are not the same as real camera or weather degradation. Robustness on ImageNet-C does not guarantee robustness to different real-world appearances (paintings or different photography), so examine it together with ImageNet-R and others.

Comparison with Similar Datasets

ImageNet and the evaluation datasets derived from it, compared from the same perspectives, are as follows.

DatasetImagesWhat it measuresImages (evaluation)Main metrics
ImageNet (ILSVRC 2012 validation)Original photosOrdinary accuracy50,000Top-1 and top-5 accuracy
ImageNetV2Photos re-collected with the same procedureOverfitting to the validation set10,000Top-1 accuracy
ImageNet-CValidation photos with 15 corruptions at 5 levelsRobustness to everyday corruptions75 combinations × 50,000mCE, relative mCE
ImageNet-PSequences of images with gradually intensifying corruptionPrediction stability―mFR, mT5D
ImageNet-RRenditions such as paintings, cartoons, and sculpturesRobustness to shifts in kinds of appearance30,000Top-1 accuracy

Rough guidelines for choosing are as follows.

  • To measure robustness to noise, blur, weather, and compression, use ImageNet-C. Looking at the CE for each corruption type shows which corruptions a model is weak to.
  • To see whether predictions fluctuate as corruption changes gradually, use ImageNet-P.
  • To assess robustness to different real-world appearances, use ImageNet-R and others together with ImageNet-C.
  • With limited computational resources, CIFAR-10-C, CIFAR-100-C, and Tiny ImageNet-C allow evaluation based on the same idea.

PyTorch example

Show code
python
import numpy as np
import torch
import torchvision.datasets as dset
import torchvision.transforms as T
from torch.utils.data import DataLoader
from torchvision.models import ResNet50_Weights, resnet50

"""
Compute mCE on ImageNet-C (ImageNet-C/<corruption>/<severity 1-5>/<class>/<image>.JPEG)
Images are already cropped to 224×224, so do not apply Resize(256)
"""

ROOT = 'ImageNet-C'

# the 15 evaluation corruptions and the AlexNet error rates used for normalization (mean over 5 levels; published values from Appendix D of the paper and Zenodo)
ALEXNET_ERR = {
  'gaussian_noise': 0.886, 'shot_noise': 0.894, 'impulse_noise': 0.923,
  'defocus_blur': 0.820, 'glass_blur': 0.826, 'motion_blur': 0.786, 'zoom_blur': 0.798,
  'snow': 0.867, 'frost': 0.827, 'fog': 0.819, 'brightness': 0.565,
  'contrast': 0.853, 'elastic_transform': 0.646, 'pixelate': 0.718, 'jpeg_compression': 0.607,
}

transform = T.Compose([T.CenterCrop(224), T.ToTensor(),
                       T.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])])

model = resnet50(weights=ResNet50_Weights.IMAGENET1K_V1)
model.eval()  # fix BN to the training statistics (always use eval mode for evaluation)


@torch.no_grad()
def top1_error(loader):
  wrong, total = 0, 0
  for x, y in loader:
    pred = model(x).argmax(dim=1)
    wrong += (pred != y).sum().item()
    total += y.numel()
  return wrong / total


ce = {}
for name, alex in ALEXNET_ERR.items():
  errs = []
  for severity in range(1, 6):
    # the sorted order of folder names (n01440764 etc.) matches the ImageNet class index order
    data = dset.ImageFolder(f'{ROOT}/{name}/{severity}', transform=transform)
    errs.append(top1_error(DataLoader(data, batch_size=256, num_workers=8)))
  # CE = sum of error rates over 5 levels / sum of AlexNet's error rates over 5 levels (published values are means, so multiply by 5)
  ce[name] = sum(errs) / (alex * 5)
  print(f'{name:18s} CE = {100 * ce[name]:.1f}%')

print(f'mCE = {100 * np.mean(list(ce.values())):.1f}%')  # ResNet-50 in the paper: 76.7%

FAQ

Q. Can models be trained on ImageNet-C?
A.

The paper does not recommend it. ImageNet-C is for measuring robustness to corruptions not seen in training. Training on ImageNet-C corruptions (or the same processing) lowers mCE, but robustness to other corruptions can no longer be measured. If it is used for training, state this explicitly. For hyperparameter tuning, use the 4 extra validation corruptions (speckle noise, Gaussian blur, spatter, saturate).

Q. What does an mCE below 100% mean?
A.

It means fewer errors under corruption than AlexNet. mCE divides each corruption's error rate by AlexNet's error rate before averaging, so AlexNet is exactly 100%. For example, ResNet-50's 76.7% corresponds to about 77% of AlexNet's errors.

Q. When should mCE and relative mCE each be used?
A.

mCE expresses "how often the model is right on corrupted images", while relative mCE expresses "how much performance drops from clean to corrupted images". To compare performance in actual use, look at mCE; to compare tolerance to corruption itself, look at relative mCE. In the paper, ResNet-50 had an mCE of 76.7%, better than AlexNet, while its relative mCE of 105.0% showed a larger drop than AlexNet.

References

  1. Hendrycks, D., & Dietterich, T. (2019). Benchmarking Neural Network Robustness to Common Corruptions and Perturbations. ICLR 2019. arXiv:1903.12261.
  2. hendrycks/robustness (official repository; corruption code, evaluation code, and benchmark tables).
  3. ImageNet-C (Zenodo; data distribution, CC BY 4.0, AlexNet error rates).
  4. Hendrycks, D., Mu, N., Cubuk, E. D., Zoph, B., Gilmer, J., & Lakshminarayanan, B. (2020). AugMix: A Simple Data Processing Method to Improve Robustness and Uncertainty. ICLR 2020. arXiv:1912.02781.