AI Logic

Datasets and Benchmarks

ImageNet

Updated:

How ImageNet was built and split. Left: the flow from WordNet synsets, through collecting candidates by image search and human verification, to ImageNet, then selecting 1,000 classes and splitting ILSVRC 2012 into training, validation, and test sets. Right: five predictions for one photo and the rules for top-5 and top-1 judgments

Overview

ImageNet is a dataset that collects photos for each concept, following the English lexical hierarchy called WordNet. Deng et al. presented it at CVPR in 2009. In deep learning, "ImageNet" usually refers to a subset of it: the ILSVRC 2012 classification data (1,000 classes, about 1.28 million images; also called ImageNet-1k).

The goal was to provide object recognition research with images that are "large-scale, cleanly labeled, and organized in a concept hierarchy". WordNet has about 80,000 noun concepts (sets of synonyms called synsets), and ImageNet aimed to provide an average of 500–1,000 images for many of them. At publication, it covered 12 subtrees such as mammals, birds, and vehicles, with 5,247 synsets and 3.2 million images.

From 2010, an image recognition competition using part of ImageNet, ILSVRC (ImageNet Large Scale Visual Recognition Challenge), was held every year. In 2012, a team using a CNN (AlexNet) won by a wide margin, which became one of the triggers for the spread of deep learning.

The full ImageNet (all synsets in the hierarchy) and the 1,000-class subset chosen for ILSVRC are treated as different things. "Accuracy on ImageNet" in papers is almost always measured on the ILSVRC 2012 validation set.

Contents: construction, classes, and splits

ImageNet was built in the following steps.

  1. Collect candidates. For each synset, images are gathered from several image search engines using the WordNet synonyms as queries. Because the number of images a search returns is limited, queries are expanded with words from parent concepts (e.g., "whippet dog") and with translations into Chinese, Spanish, Dutch, Italian, and other languages.
  2. Have humans verify. On Amazon Mechanical Turk (a service for outsourcing tasks online), workers are shown the synset's definition and candidate images and asked whether the object appears.
  3. Select by votes. Several people judge the same image independently, and only images that enough people say contain the object are kept. Harder-to-distinguish concepts, such as "Burmese (a cat breed)" rather than "cat", need more votes, so the required number of votes is set per synset.

The paper examined randomly chosen synsets and reports that about 99.7% of the kept images correctly depicted the concept.

The ILSVRC classification data is built by choosing 1,000 synsets with no parent-child relations among them. For example, "dog" and "Siberian husky" are never both classes. In 2012, 90 classes were replaced with dog breeds, so fine-grained discrimination between similar objects is also tested. The 2012–2014 competitions used the same 1,000 classes and the same data.

SplitImagesPer classLabels
Training1,281,167732–1,300Public
Validation50,00050Public
Test100,000100Hidden (scored by an evaluation server)

Each example is a pair of an RGB photo whose size varies by image and a single class label. Labels are synset IDs (e.g., n02110185), and libraries map them to integers 0–999 in sorted ID order. Even if a photo contains several objects, it has only one label.

Evaluation rules

For ILSVRC classification, the top-5 error rate is the standard metric. The model may give five classes per image, and the answer counts as correct if any of them matches the ground-truth label. With ground-truth label CiC_i for image ii and the model's five classes ci1,…,ci5c_{i1}, \dots, c_{i5},

error rate=1N∑i=1Nmin⁡jd(cij,Ci),d(c,C)={0(c=C)1(c≠C)\text{error rate} = \frac{1}{N}\sum_{i=1}^{N} \min_{j} d(c_{ij}, C_i), \qquad d(c, C) = \begin{cases} 0 & (c = C) \\ 1 & (c \neq C) \end{cases}

where NN is the number of images. Five guesses are allowed because a photo may contain several objects yet has only one label. For example, if a photo labeled "strawberry" also shows an apple, the model cannot know which one it should answer.

The top-1 error rate (or top-1 accuracy), which judges only the first prediction, is also used. The organizers also tried top-1 and an error rate that considers closeness in the hierarchy, but every variant gave the same team ranking, so from 2012 rankings were based on top-5 alone. Recent papers mostly report top-1 accuracy.

Test labels are not released, to prevent fitting to the test set (only the 2010 labels were released later). Scoring on the evaluation server remains available after the competition, but each team may submit only twice a week. Research therefore commonly reports results on the 50,000 validation images in place of the test set.

Since the validation set serves as the final evaluation, it cannot be used for hyperparameter tuning. Hold out part of the training set for tuning and use the validation set only for the final evaluation. Reporting values tuned on the validation set overestimates performance by the amount of overfitting.

Usage and historical significance

ImageNet has served two roles.

  • Comparing image classification performance: new architectures (VGG, GoogLeNet, ResNet, ViT, and others) are almost always compared by ImageNet top-1 accuracy.
  • Pretraining: the weights of a model trained on ImageNet serve as the starting point for other tasks such as object detection and segmentation (fine-tuning). In self-supervised learning such as SimCLR, it is also standard to evaluate representations learned without labels by ImageNet classification.

The top-5 error rate of the winning team in ILSVRC classification dropped sharply over five years.

YearWinning teamTop-5 error
2010NEC28.2%
2012SuperVision (AlexNet)16.4%
2013Clarifai11.7%
2014GoogLeNet6.7%

In 2012, when most methods used hand-crafted features, SuperVision used a CNN and finished far ahead of second place. The organizers' paper estimates the top-5 error of a trained human annotator at about 5.1% on 1,500 test images. However, this is from a single annotator; another annotator with less training scored about 12.0%. A lower error rate than humans does not mean a model recognizes objects the way humans do.

Caveats

License: the copyright of ImageNet images belongs to their photographers. The terms of use of Princeton University and Stanford University, which distribute ImageNet, restrict use to non-commercial research and education. Downloading requires agreeing to the terms on the official site or on Hugging Face.

Whether a model trained on ImageNet may be used in a commercial product depends on the terms of use and on the conditions of the model's distributor. The images themselves may not be redistributed or used as product data. Check the terms before commercial use.

Label errors: Northcutt et al. (2021) report that at least 2,916 (about 6%) of the 50,000 validation labels are wrong. Based on additional expert review, they also estimate that the actual error rate may approach 20%. They also point out pairs of classes with the same name ("maillot" at 638 and 639, "crane" at 134 and 517).

One label per image: even images with multiple objects have a single label. Beyer et al. (2020) relabeled the validation set with multiple labels (ReaL labels) and showed that accuracy gains on ReaL labels are much smaller than gains on the original labels. Part of the accuracy differences between recent models may come from memorizing quirks of the labeling.

Suspected overfitting to the test set: Recht et al. (2019) rebuilt a new test set (ImageNetV2) following the original procedure and showed that the accuracy of many models drops by 11–14%. However, model rankings were largely preserved, and the authors conclude that the drop is caused less by fitting to the validation set than by the new images being slightly harder.

Images of people: among the 1,000 classes, only three are about people themselves ("scuba diver", "groom", and "ballplayer"), but images in other classes also show people photographed without consent. Training on a version with blurred faces has been reported to reduce accuracy by only about 0.6%.

Comparison with similar datasets

Datasets commonly used for image classification, compared along the same dimensions:

DatasetImagesClassesTrain / evalBest suited for
MNISTHandwritten digits, 28×28 grayscale1060,000 / 10,000Sanity checks, getting started
CIFAR-10/100Photos of objects, 32×32 color10 or 10050,000 / 10,000Quick comparisons of methods on small images
ImageNet (ILSVRC 2012)Photos of objects, color, various sizes1,0001,281,167 / 50,000 (validation)Serious performance comparison, pretraining
ImageNetV2Photos recollected with the same procedure as ImageNet1,000Eval only, 10,000Checking for fitting to the validation set
ImageNet-CImageNet images with corruptions applied1,000Eval onlyChecking robustness to image corruptions

Rough guidelines for choosing:

  • To check that a method works, try MNIST or CIFAR-10 in minutes to hours.
  • To demonstrate the performance of an architecture or training method, report ImageNet top-1 accuracy. Training takes a long time on GPUs, so plan according to your compute budget.
  • To check whether results reflect real generalization, also evaluate on ImageNetV2 or ReaL labels and look at the gap from the original validation set.

PyTorch example

Show code
python
import torch
from torch.utils.data import DataLoader
from torchvision import datasets, transforms

'''
Load ImageNet (ILSVRC 2012) with torchvision
'''

# ImageNet requires agreeing to its terms of use, so there is no download argument.
# Download the following three files manually from the official site and place them in root:
#   ILSVRC2012_devkit_t12.tar.gz (class mapping, etc.)
#   ILSVRC2012_img_train.tar (for split='train')
#   ILSVRC2012_img_val.tar (for split='val')
root = './data/imagenet'

# Image sizes vary, so resize them before converting to tensors
# The mean and std are the values used by torchvision's pretrained models
normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])

train_transform = transforms.Compose([
  transforms.RandomResizedCrop(224),   # training: random crop resized to 224×224
  transforms.RandomHorizontalFlip(),
  transforms.ToTensor(),
  normalize,
])
val_transform = transforms.Compose([
  transforms.Resize(256),              # evaluation: resize the short side to 256 and center-crop (deterministic)
  transforms.CenterCrop(224),
  transforms.ToTensor(),
  normalize,
])

# split is 'train' or 'val'. Test labels are hidden, so use 'val' for evaluation
train_dataset = datasets.ImageNet(root, split='train', transform=train_transform)
val_dataset = datasets.ImageNet(root, split='val', transform=val_transform)
print(len(train_dataset), len(val_dataset))  # 1281167 50000
print(train_dataset.classes[0])              # name of class 0 (a tuple of synonyms)

train_loader = DataLoader(train_dataset, batch_size=256, shuffle=True, num_workers=8)
val_loader = DataLoader(val_dataset, batch_size=256, num_workers=8)


def topk_correct(logits, labels, k=5):
  '''Return how many samples have the label among the top-k predictions (top-1 is k=1)'''
  topk = logits.topk(k, dim=1).indices             # [B, k]
  return (topk == labels.unsqueeze(1)).any(dim=1).sum().item()


# Evaluation loop (model is a trained model)
# model.eval()
# correct1 = correct5 = 0
# with torch.no_grad():
#   for images, labels in val_loader:
#     logits = model(images)
#     correct1 += topk_correct(logits, labels, k=1)
#     correct5 += topk_correct(logits, labels, k=5)
# print('top-1 accuracy', correct1 / len(val_dataset), 'top-5 accuracy', correct5 / len(val_dataset))

# Loading with Hugging Face datasets (agree to the terms on Hugging Face and log in first)
# from datasets import load_dataset
# ds = load_dataset('ILSVRC/imagenet-1k')   # splits: 'train', 'validation', 'test'
# print(ds['validation'][0])                # {'image': PIL image, 'label': int}
# Every test label is -1 (because labels are hidden)

FAQ

Q. How many images does "trained on ImageNet" refer to?
A.

Usually the 1,281,167 training images of ILSVRC 2012 (1,000 classes). The full ImageNet has many more synsets and images, so check which one a paper used.

Q. Is the "ImageNet accuracy" in papers measured on the test set?
A.

Almost always it is measured on the 50,000 validation images. Test labels are hidden, and submissions to the evaluation server are limited to twice a week.

Q. Should I look at top-1 or top-5?
A.

Recent papers mainly use top-1 accuracy. Top-5 is the metric ILSVRC used to soften the problem that a photo can contain several objects but has only one label.

References

  1. Deng, J., Dong, W., Socher, R., Li, L.-J., Li, K., & Fei-Fei, L. (2009). ImageNet: A Large-Scale Hierarchical Image Database. CVPR 2009.
  2. Russakovsky, O., Deng, J., Su, H., et al. (2015). ImageNet Large Scale Visual Recognition Challenge. International Journal of Computer Vision, 115(3), 211–252.
  3. Recht, B., Roelofs, R., Schmidt, L., & Shankar, V. (2019). Do ImageNet Classifiers Generalize to ImageNet? ICML 2019.
  4. Beyer, L., Hénaff, O. J., Kolesnikov, A., Zhai, X., & van den Oord, A. (2020). Are we done with ImageNet?
  5. Northcutt, C. G., Athalye, A., & Mueller, J. (2021). Pervasive Label Errors in Test Sets Destabilize Machine Learning Benchmarks. NeurIPS 2021 Datasets and Benchmarks.
  6. ILSVRC/imagenet-1k (Hugging Face dataset card and terms of use).
  7. torchvision.datasets.ImageNet (PyTorch documentation).