Image classification is the most fundamental computer vision task: assign a single label to an entire image, from a fixed set of possible categories. Every CNN and CNN architecture covered so far in this hub was built and evaluated primarily around this task.
The Task, Precisely
Given an image \(\mathbf{x}\), predict \(P(y=c\mid\mathbf{x})\) for each class \(c\) in a fixed set โ exactly the categorical cross-entropy setup from Categorical Cross-Entropy, with a softmax output layer. The predicted class is simply the one with the highest probability.
The Standard Pipeline
A CNN backbone (any architecture from the CNN Architectures category โ ResNet, EfficientNet, etc.) extracts increasingly abstract spatial features, Global Average Pooling or flattening condenses them to a vector, and a final fully-connected layer plus softmax produces class probabilities โ exactly the architecture pattern established throughout What Is CNN? and the CNN Fundamentals category.
Benchmark Datasets
| Dataset | Scale | Historical Role |
|---|---|---|
| MNIST | 70,000 grayscale digit images, 10 classes | The classic beginner benchmark, originally targeted by LeNet |
| CIFAR-10/100 | 60,000 small color images, 10 or 100 classes | A common testbed for new architectures at smaller scale |
| ImageNet | Over a million images, 1,000 classes | The large-scale benchmark that drove the AlexNet-onward CNN architecture race |
Code
import torchvision.models as models
import torch.nn as nn
model = models.resnet18(weights='IMAGENET1K_V1')
model.fc = nn.Linear(model.fc.in_features, 10) # adapt the final layer to a new 10-class task
x = torch.randn(1, 3, 224, 224)
logits = model(x)
predicted_class = logits.argmax(dim=1)
print(predicted_class)
Common Mistakes
- Evaluating a classifier using accuracy alone on an imbalanced dataset โ as covered in Accuracy, this can badly mislead; precision/recall/F1 per class are usually more informative.
- Forgetting to normalize input images to match whatever statistics a pretrained backbone expects (see Image Representation) โ mismatched normalization silently degrades pretrained model performance.
Interview Relevance
Q: "What's the standard architecture pattern for an image classification CNN?" A convolutional backbone extracts spatial features at increasing levels of abstraction, pooling (often Global Average Pooling in modern architectures) condenses these into a fixed-length vector, and a final fully-connected layer with softmax produces class probabilities โ trained end-to-end with categorical cross-entropy loss.
Practice Question
Why is a fixed set of possible classes a defining, necessary characteristic of the standard image classification task?