Foundations to Frontier
Tests
G. Computer Vision and Remote Sensing › G2 Core Vision Tasks

Image classification

Image classification assigns one label (or a set of labels) to a whole image. It is the oldest deep-learning vision task and still the base of most others: detectors and segmenters reuse classification backbones. This page treats the task rather than the architectures: problem setups (single-label, multi-label, fine-grained, long-tailed), the datasets that shaped the field (ImageNet, CIFAR, EuroSAT, BigEarthNet), the metrics (top-k accuracy, balanced accuracy, macro-F1, calibration), a modern training and fine-tuning pipeline, and the failure modes that survive high test accuracy: shortcuts, distribution shift and label noise. In the exercises you implement top-k accuracy, balanced accuracy and expected calibration error. You then train a classifier on aircraft and ship chips in which the background (tarmac or water) agrees with the class 95% of the time. Plain training scored 0.947 in distribution but 0.506 once the background stopped predicting the class, with worst-group accuracy 0.000. Reweighting the groups raised the worst group to 0.649 and randomising backgrounds to 0.786, matching shortcut-free training data, at a cost of 13 points in distribution.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

One label for a whole picture

An image classifier looks at a picture and answers one question: which of a fixed list of categories is this? A ship or an aircraft, a cloudy or a clear satellite scene, a healthy or a cracked turbine blade. It learns from many labelled examples. The hard part is not getting a high score on a test set; it is making sure the model looks at the right thing. A classifier that recognises ships by the water around them will fail on a ship in dry dock. The demo shows a second trap: with a rare class, accuracy can look excellent while the rare class is mostly missed.

Vision task lab
accuracy0.95balanced acc.0.69rare precision0.51rare F10.45
Accuracy 0.951 against 0.950 for always predicting the common class; balanced accuracy 0.690; rare-class F1 0.449. With a rare class, accuracy mostly measures the common one.
Why engineers care

Earth-observation teams classify image chips for land cover, cloud cover and ship or aircraft presence; inspection teams classify defects in turbine blades and composite panels. A model that is right for the wrong reason fails exactly when conditions change.

📝 Quick check (Level 0)
0/3 answered
  1. 1. Image classification outputs…
  2. 2. With a 1% rare class, always predicting the common class gives accuracy…
  3. 3. A model that recognises ships by the surrounding water has learned…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

By hand

  • Setups. Single-label (softmax over K classes, cross-entropy); multi-label (K independent sigmoids, binary cross-entropy; BigEarthNet has 19 land-cover labels per Sentinel-2 patch); fine-grained (aircraft variants, bird species: small differences between classes); long-tailed (a few frequent classes, many rare ones).
  • Datasets. ImageNet-1k (Deng et al. 2009; 1.28 million training images, 1000 classes, 50000 validation images) drove the field from AlexNet (2012) through ResNet (2016) to ViT (2021) and ConvNeXt (2022). CIFAR-10/100 (2009) for quick studies. EuroSAT (Helber et al. 2019; 27000 Sentinel-2 patches, 10 classes) and BigEarthNet (Sumbul et al. 2019) for Earth observation.
  • Metrics. Top-1 and top-5 accuracy; balanced accuracy (mean per-class recall) and macro-F1 when classes are imbalanced; mAP for multi-label; expected calibration error (ECE) when the probabilities drive decisions.
  • Evaluation protocol. ImageNet-style: resize the short side to 256, centre-crop 224, normalise with the training mean and standard deviation. Keep a validation set for choices and touch the test set once.
  • Failure modes. Shortcut learning (Geirhos et al. 2020): background, watermark or sensor artefacts that predict the label in the data but not in the world. Distribution shift: ImageNet-V2 (Recht et al. 2019) cost models 11 to 14 points of top-1 with a near-identical collection process. Label noise: about 6% of ImageNet validation labels are wrong (Northcutt et al. 2021). Overconfidence (Guo et al. 2017).
📝 Quick check (Level 1)
0/3 answered
  1. 1. Multi-label classification uses…
  2. 2. For imbalanced classes prefer…
  3. 3. ImageNet-V2 showed that…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.

A modern classification pipeline

Exercise 1.

  • Top-k accuracy from a logit matrix.
  • A confusion matrix and balanced accuracy.
  • Expected calibration error with equal-width confidence bins.

Practice.

  • Start pretrained. Fine-tune a pretrained ConvNeXt, EfficientNetV2 or ViT from timm, or fit a linear probe on frozen DINOv2 or CLIP features; train from scratch only with ImageNet-scale data.
  • Augment. RandomResizedCrop and flips (not flips that change meaning, such as for text or chirality); RandAugment, Mixup and CutMix; for satellite chips also 90° rotations.
  • Regularise. Label smoothing 0.1, weight decay with AdamW, a cosine schedule with warm-up, EMA of the weights.
  • Evaluate per class and per group. Read the confusion matrix; slice by sensor, season, region and background; report the worst group, not only the mean.
  • Calibrate with temperature scaling on the validation set when probabilities feed a decision.
import timm, torch
model = timm.create_model("convnext_tiny.fb_in22k", pretrained=True, num_classes=10)  # new 10-class head
cfg = timm.data.resolve_data_config({}, model=model)            # the backbone's own resize, crop and normalisation
train_tf = timm.data.create_transform(**cfg, is_training=True, auto_augment="rand-m9-mstd0.5")
opt = torch.optim.AdamW(model.parameters(), lr=1e-4, weight_decay=0.05)
loss_fn = timm.loss.SoftTargetCrossEntropy()                     # with Mixup/CutMix soft labels
mixup = timm.data.Mixup(mixup_alpha=0.8, cutmix_alpha=1.0, label_smoothing=0.1, num_classes=10)
for x, y in loader:
    x, y = mixup(x, y); loss = loss_fn(model(x), y)
    opt.zero_grad(); loss.backward(); opt.step()
🐍 Exercise 1: classification metrics
Implement top-k accuracy, a confusion matrix, balanced accuracy and expected calibration error.
📝 Quick check (Level 2)
0/3 answered
  1. 1. A linear probe trains…
  2. 2. Report beside the mean accuracy…
  3. 3. Temperature scaling fixes…

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

Why shortcuts win. Empirical risk minimisation rewards any feature that lowers the training loss. If a feature such as background brightness agrees with the label in 95% of training images and is easier to pick up than shape, gradient descent learns it first and the remaining 5% of examples barely move the decision. Nothing in the average training or in-distribution test accuracy reveals this, because the shortcut is genuinely predictive there.

Groups and worst-group accuracy. Split data by (class, attribute), for example (aircraft, water). Worst-group accuracy is the minimum over groups. Group DRO (Sagawa et al. 2020) minimises the worst group’s loss; simpler fixes reweight groups to equal total weight or remove the shortcut by augmentation (randomise the background) or by collecting counter-examples.

Calibration. ECE = Σ_b (n_b/n)·|acc_b − conf_b| over confidence bins. Modern networks trained with cross-entropy tend to be overconfident; a single temperature fitted on validation data fixes most of it without changing the argmax.

Balanced metrics. Accuracy weights classes by frequency. Balanced accuracy averages per-class recall; macro-F1 averages per-class F1, so a rare class that is never predicted pulls both down.

📝 Quick check (Level 3)
0/3 answered
  1. 1. A shortcut feature is learned because it…
  2. 2. Worst-group accuracy is…
  3. 3. Temperature scaling changes the predicted class…

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

How badly does a background shortcut hurt a classifier, and which fixes recover the shape signal?

History.

  • R. Geirhos et al., “Shortcut learning in deep neural networks” (2020).
  • S. Sagawa et al., “Distributionally robust neural networks for group shifts” (2020): the Waterbirds benchmark (birds on land or water backgrounds).
  • B. Recht et al., “Do ImageNet classifiers generalize to ImageNet?” (2019).

Exercise 2. 8 × 8 chips of aircraft (a cross) or ships (a hull) at a jittered position, with Gaussian noise.

  • Shortcut: tarmac (bright) or water (dark) background; in training it matches the class (aircraft on tarmac, ships on water) for 95% of chips, so only 4.8% are counter-examples.
  • Model: logistic regression on the 64 pixels, 2000 training chips, 400 steps of gradient descent.
  • Variants: plain training (ERM); group reweighting (each of the four class × background groups gets equal total weight); background augmentation (background re-drawn at random); and, as a reference, training data with no shortcut.
  • Test: 4000 chips with the training correlation, and 4000 with background independent of class.
training in distribution background independent worst group
ERM 0.947 0.506 0.000
group reweighting 0.846 0.761 0.649
background augmentation 0.816 0.807 0.786
shortcut-free data 0.813 0.800 0.777
  • ERM learned the background, not the object: 0.947 where the shortcut holds, chance (0.506) where it does not, and aircraft on water were never recognised.
  • Training longer did not cure it: 8000 steps (20 times longer) raised ERM’s background-independent accuracy only to 0.591 and the worst group to 0.169.
  • Both fixes worked; augmentation, which removes the shortcut from the inputs, matched shortcut-free data. Reweighting helped less because only 95 minority chips carry the signal.
  • The cost is real: in-distribution accuracy fell from 0.947 to 0.816, because the shortcut is genuinely predictive in that distribution. A model selected by in-distribution validation accuracy would pick ERM.
  • Seeds 1 and 2: ERM worst group 0.001 and 0.000; reweighting 0.725 and 0.666; augmentation 0.769 and 0.779.
  • Caveat: a linear model on synthetic chips; deep networks can memorise the minority examples, which often makes reweighting weaker still (Sagawa et al. 2020 needed strong regularisation).
🐍 Exercise 2 (research): how badly does a background shortcut hurt a classifier, and which fixes recover the shape signal?
Train a classifier with a background shortcut and compare plain training, group reweighting and background augmentation on in-distribution, background-independent and worst-group accuracy.

Image classification in AI, robotics and aerospace

  • Earth observation: land-cover and cloud classification of Sentinel-2 and Landsat chips (EuroSAT, BigEarthNet); geographic and seasonal shift is the main failure mode, so evaluate on held-out regions.
  • Onboard satellites: ESA’s Φ-Sat-1 (2020) ran a CNN on board to discard cloudy images before downlink.
  • Inspection: defect classification on turbine blades, welds and composite panels, where defects are rare and balanced metrics matter.

References

  1. J. Deng et al. (2009). “ImageNet: a large-scale hierarchical image database.” CVPR.
  2. A. Krizhevsky, I. Sutskever and G. Hinton (2012). “ImageNet classification with deep convolutional neural networks.” NeurIPS.
  3. P. Helber et al. (2019). “EuroSAT: a novel dataset and deep learning benchmark for land use and land cover classification.” IEEE JSTARS.
  4. C. Guo, G. Pleiss, Y. Sun and K. Weinberger (2017). “On calibration of modern neural networks.” ICML.
  5. B. Recht, R. Roelofs, L. Schmidt and V. Shankar (2019). “Do ImageNet classifiers generalize to ImageNet?” ICML.
  6. R. Geirhos et al. (2020). “Shortcut learning in deep neural networks.” Nature Machine Intelligence.
  7. S. Sagawa, P. W. Koh, T. Hashimoto and P. Liang (2020). “Distributionally robust neural networks for group shifts.” ICLR.
  8. C. Northcutt, A. Athalye and J. Mueller (2021). “Pervasive label errors in test sets destabilize machine learning benchmarks.” NeurIPS Datasets and Benchmarks.