Image Classification with Deep Networks
Imagine handing a computer ten million unlabeled photographs. Ask it to sort them into a thousand bins. These include cat, tabby cat, sports car, coral reef, espresso machine. A human can do this instantly. This draws on decades of visual experience. A machine has to learn everything from pixels alone. Image classification maps a whole image to a single label. That label comes from a fixed vocabulary of categories. It has served for over a decade as the flagship benchmark for progress in computer vision. The task looks deceptively simple — one image in, one label out. But it forces a system to solve nearly every hard problem in vision at once. This includes invariance to lighting, pose, scale, and clutter. It also requires tolerance for intra-class variation, and robustness to occlusion. A classifier must generalize from a few thousand training examples per class. It must handle millions of unseen photographs, taken by different cameras in different countries. This is a genuinely hard statistical and representational problem. Getting it right unlocked practical systems. These include photo search, content moderation, medical image triage, and retail visual search. It also produced the backbone features that power object detection and segmentation. This article traces the architectural lineage that made deep classifiers work. AlexNet made a breakthrough use of deep convolutional stacks trained on GPUs. VGG demonstrated that depth and uniform 3×3 convolutions are enough. ResNet introduced residual connections. These let networks reach hundreds of layers without degrading. Along the way we fix the mathematical scaffolding. This includes the softmax output layer, the cross-entropy loss, and the training loop. Every modern classifier still uses these, whether it is a small CNN or a vision transformer. By the end you should be able to explain this precisely. You should know why a convolutional network trained with softmax and cross-entropy performs maximum-likelihood estimation of class probabilities. You should know why deeper networks eventually fail to train without shortcuts. You should also know why residual connections fix that failure. You should also be able to reproduce the essential architecture diagrams and pseudocode. This applies to AlexNet, VGG, and ResNet. You should do this from memory of their design principles, rather than rote recall.
- Image classification maps a whole image to one label from a fixed set of classes using a learned scoring function.
- A CNN backbone extracts features; a final linear layer plus softmax converts scores ("logits") into a probability distribution over classes.
- Training minimizes cross-entropy loss via stochastic gradient descent and backpropagation — this is maximum-likelihood estimation of the class-conditional distribution.
- AlexNet (2012) proved deep CNNs trained on GPUs beat hand-engineered features by a large margin on ImageNet.
- VGG (2014) showed that stacking small 3×3 convolutions and going deeper, with a simple uniform design, improves accuracy predictably.
- ResNet (2015) introduced residual (skip) connections, solving the degradation problem and enabling networks over 100 layers deep.
A deep image classifier is a differentiable pipeline — convolutional feature extractor plus softmax classifier — trained end-to-end by gradient descent to maximize the likelihood of the correct label.
The idea
Whole-image classification is the supervised learning task of assigning an image to exactly one label from a predefined, mutually exclusive set of categories. This differs from object detection (which localizes multiple objects with bounding boxes) and from segmentation (which labels every pixel); classification produces a single global judgment about the entire image. The standard architecture has two conceptual parts. First, a convolutional backbone — built from the stacked convolution, nonlinearity, and pooling operations covered in CNNs for Images Revisited — transforms the raw pixel array into a compact feature vector, progressively trading spatial resolution for semantic abstraction. Second, a classification head takes that feature vector and produces a probability distribution over the classes. The classification head is almost always a single linear (fully connected) layer producing real-valued logits , followed by the softmax function:
Softmax converts arbitrary real-valued scores into a valid probability distribution: every and . It is the multi-class generalization of the logistic sigmoid, and it is not an arbitrary choice — it falls out of assuming the logits are proportional to log class-conditional likelihoods under an exponential-family model, making the softmax classifier the maximum-entropy distribution consistent with those scores. Training minimizes the cross-entropy loss between the predicted distribution and the one-hot true label :
Minimizing cross-entropy over the training set is exactly maximum-likelihood estimation of the network's parameters under the assumption that labels are drawn from the softmax-induced categorical distribution — this is the statistical justification for why "train with cross-entropy" is the correct objective rather than a heuristic. The architectural history of the field — AlexNet, VGG, ResNet — is the story of how to build the backbone that feeds this head so that the resulting features are linearly separable by class.
How it works
The training pipeline has three moving parts: the forward pass through the backbone and head, the loss computation, and backpropagation through both to update every weight. Architecturally, the three canonical networks differ mainly in how the backbone is built, while the head and training loop stay essentially fixed.
AlexNet (8 weight layers: 5 convolutional, 3 fully connected) established the template: convolution → ReLU → (occasional) local response normalization → max-pooling, repeated with increasing channel depth and decreasing spatial resolution, followed by two large fully connected layers, dropout for regularization, and a final -way softmax. Its key engineering contributions were using ReLU instead of saturating sigmoids (faster convergence), training on two GPUs in parallel, using dropout to fight overfitting in the huge fully-connected layers, and using aggressive data augmentation (foreshadowed further in Data Augmentation for Vision).
VGG simplified the design space: use only convolutions with stride 1 and padding 1 (which preserve spatial size), only max-pooling with stride 2 (which halves spatial size), and double the channel count after every pooling stage. Two stacked convolutions have the same receptive field as one convolution but with fewer parameters and an extra nonlinearity, and three stacked convolutions match a receptive field while using roughly half the parameters and adding two extra ReLUs. VGG-16 and VGG-19 (16 and 19 weight layers) demonstrated that with this simple recipe, accuracy improves monotonically with depth, up to a point.
ResNet solved the point where it stops improving. Beyond roughly 20 layers, plain stacked networks suffer from the degradation problem: training accuracy — not just test accuracy — gets worse as depth increases, which rules out overfitting as the explanation and points instead to an optimization difficulty. ResNet's fix is the residual block: instead of asking a stack of layers to learn a full mapping , it asks them to learn a residual , and adds the input back via a shortcut connection:
If the optimal mapping for a block is close to the identity, it is trivial to drive (push weights toward zero), whereas forcing a plain stack of nonlinear layers to approximate the identity exactly is empirically hard. The shortcut also gives gradients a direct, unimpeded path back to earlier layers during backpropagation, mitigating vanishing gradients in very deep stacks. ```
# Generic image-classifier training loop (applies to AlexNet, VGG, ResNet) function TRAIN_CLASSIFIER(model, train_data, epochs, lr): initialize model.weights # e.g. He/Kaiming init for ReLU nets for epoch in 1..epochs: for (batch_images, batch_labels) in MINIBATCHES(train_data):
# ---- forward pass ---- features = model.backbone(batch_images) # conv stack -> feature map pooled = GLOBAL_OR_FLATTEN_POOL(features) # -> fixed-length vector logits = model.head(pooled) # linear layer -> K logits probs = SOFTMAX(logits) # per-example distribution loss = CROSS_ENTROPY(probs, batch_labels) loss += weight_decay * L2_NORM(model.weights) # regularization
# ---- backward pass ---- grads = BACKPROP(loss, model.weights) # chain rule through all layers model.weights = SGD_UPDATE(model.weights, grads, lr) # or Adam, momentum, etc. lr = DECAY_SCHEDULE(lr, epoch) # step / cosine decay return model function SOFTMAX(logits): # logits: length-K vector m = MAX(logits) # subtract max for numerical stability exps = [EXP(z - m) for z in logits] s = SUM(exps) return [e / s for e in exps] function CROSS_ENTROPY(probs, label_index): return -LOG(probs[label_index] + epsilon) # epsilon avoids log(0) function RESIDUAL_BLOCK(x, weights1, weights2): h = RELU(CONV(x, weights1)) h = CONV(h, weights2) if SHAPE(x) != SHAPE(h): x = CONV_1x1_PROJECTION(x) # match dims/stride when block downsamples return RELU(h + x) # the skip connection ``` The `RESIDUAL_BLOCK` function is the one structural addition ResNet makes to the plain VGG-style stack; everything else — convolution, ReLU, pooling, softmax head, cross-entropy training — is shared machinery.
Complexity & correctness
Forward-pass time complexity. For a convolutional layer with input size , kernel size , and output channels applied with stride 1, the cost is
multiply-accumulate operations, because each of the output positions per output channel requires a dot product, repeated for channels. A full backbone's cost is the sum of this quantity over all layers. VGG's design choice of two stacked convolutions in place of one is not just about receptive field: parameter count drops from to for equal channel width , and three layers replacing one drop parameters from to — roughly 45% fewer weights for the same receptive field, plus two additional ReLU nonlinearities that increase representational capacity.
Space complexity. Training must store activations from the forward pass for every layer to compute gradients during backpropagation (reverse-mode automatic differentiation), giving memory cost linear in the number of layers times the feature map size at each layer — this is why very deep networks are memory-hungry at training time even though inference-only memory is much smaller (activations can be discarded layer by layer). AlexNet's split across two GPUs in the original paper was driven precisely by this memory constraint on 2012-era hardware.
Why softmax + cross-entropy is the correct training objective. Treat the network as producing logits as a function of image and parameters . Define the likelihood of the training set under the categorical model . The log-likelihood of the whole training set, assuming i.i.d. samples, is
So minimizing the sum of per-example cross-entropy losses is exactly maximizing the likelihood of the observed labels under this model — cross-entropy is not a heuristic surrogate but the negative log-likelihood itself. A useful correctness check on the gradient: differentiating the loss with respect to logit gives the clean expression
meaning the backpropagated error signal at the output is simply "predicted probability minus 1 for the true class, minus 0 otherwise" — an intuitively correct and numerically well-behaved gradient with no vanishing or exploding terms at the classification head itself.
Why residual connections fix degradation. Consider a plain block computing via stacked nonlinear layers versus a residual block computing where is the same stack. If the identity mapping is (near-)optimal for a given block, the residual formulation only needs to drive the weights of toward zero — trivially achievable via gradient descent with small weight initialization — whereas the plain formulation must fit a stack of nonlinear (ReLU) layers to approximate identity exactly, which is a harder function-approximation target for generic nonlinear layers with random initialization. Empirically, this explains why plain networks past ~20 layers show rising training error (an optimization failure, not overfitting), while ResNets with skip connections train stably to 100+ and even 1000+ layers. During backpropagation, the identity shortcut in contributes a term to , guaranteeing that gradient magnitude does not shrink to zero purely due to depth, which mitigates (though does not entirely eliminate) vanishing gradients.
Tradeoffs to be honest about. Softmax cross-entropy assumes classes are mutually exclusive and exhaustive; it is the wrong loss for multi-label problems (an image containing both "dog" and "frisbee") where independent per-class sigmoids are correct instead. Deeper is not always better in practice — depth increases inference latency and memory, and beyond a point accuracy gains saturate while cost keeps rising, so real deployments trade off ResNet-50 against ResNet-152 based on latency budgets. VGG's huge fully connected layers (over 100 million parameters in the first FC layer alone) make it far more parameter-heavy and slower to train than ResNet-50 despite similar or worse accuracy, which is why ResNet variants dominate as backbones today.
Worked example
Trace a single training example through a small 3-class classifier to make the arithmetic concrete. Suppose after the backbone and pooling, the feature vector is , and the final linear layer produces logits for classes {cat, dog, bird}: . The true label is "dog" (index 2).
Step 1 — softmax. Subtract the max for stability ():
| class | |||
|---|---|---|---|
| cat | 2.0 | 0.0 | 1.0000 |
| dog | 1.0 | -1.0 | 0.3679 |
| bird | 0.1 | -1.9 | 0.1496 |
Sum .
Check: ✓.
Step 2 — cross-entropy loss. True label is "dog", so
Because the model's top prediction ("cat", 65.9%) is wrong, the loss is substantial — a correct, confident prediction would give a loss near zero (e.g., ).
Step 3 — gradient at the logits. Using :
| class | gradient | ||
|---|---|---|---|
| cat | 0.659 | 0 | +0.659 |
| dog | 0.242 | 1 | -0.758 |
| bird | 0.099 | 0 | +0.099 |
The gradient pushes the "cat" and "bird" logits down (positive gradient means increasing increases loss, so gradient descent decreases them) and pushes the "dog" logit up — exactly the correction the network needs, with magnitude proportional to how wrong the current probability is. This 3-vector then flows backward through the fully connected layer and the entire convolutional stack via the chain rule, updating every convolution filter by a tiny amount in the direction that would have made "dog" more likely for this particular image.
Step 4 — architecture comparison on the same input. If this feature vector came from three different backbones processing a cat photo, the backbones differ enormously upstream even though the head computation above is identical:
| Backbone | Depth (weight layers) | Approx. parameters | Top-5 ImageNet error (roughly, original papers) |
|---|---|---|---|
| AlexNet | 8 | ~60M | ~17% |
| VGG-16 | 16 | ~138M | ~7-8% |
| ResNet-152 | 152 | ~60M | ~4-5% |
Notice ResNet-152 has fewer parameters than AlexNet despite being nearly 20× deeper — depth from residual blocks with bottleneck 1×1 convolutions is far more parameter-efficient than width from giant fully connected layers, and it achieves substantially lower error.
Common pitfalls & traps
| Pitfall | Why it happens | Fix |
|---|---|---|
| Skipping the max-subtraction in softmax | overflows for large logits, producing `NaN` | Always compute before normalizing |
| Using softmax+cross-entropy for multi-label images | Softmax enforces mutual exclusivity; an image can have several correct labels | Use independent sigmoid outputs with binary cross-entropy per class |
| Training a 50-layer plain (non-residual) CNN and blaming overfitting | Rising training error with depth is a degradation/optimization problem, not overfitting | Add residual (skip) connections, or use careful initialization/normalization |
| Forgetting weight decay / dropout in huge FC layers (VGG/AlexNet style) | Millions of FC parameters overfit small or noisy training sets | Add dropout on FC layers and L2 weight decay on all layers |
| Testing accuracy computed with train-time batch norm statistics | Batch statistics differ between a single test image and training minibatches | Switch to running (population) statistics at evaluation/inference time |
| Comparing architectures without controlling for training recipe | Learning rate schedule, augmentation, and epochs affect accuracy as much as architecture | Hold training procedure fixed when isolating architectural effects |
Pioneers & history
Origins · 1 minGeoffrey Hinton and how this was discovered
Hinton's group demonstrated in 2012 that a deep convolutional network, trained end-to-end with backpropagation on GPUs, could beat decades of hand-engineered computer-vision features on ImageNet by a wide margin — a result that reoriented the entire field toward learned representations.
He identified and diagnosed the degradation problem in very deep plain networks and proposed the residual-learning reformulation, enabling networks with over one hundred layers to train reliably and win the 2015 ImageNet competition.
Where this matters
Convolutional classifiers descended from this lineage are the backbone of nearly every modern vision system. Object detectors (Faster R-CNN, YOLO, SSD) and segmentation networks reuse a pretrained classification backbone — typically a ResNet variant — as a feature extractor, a strategy formalized in Transfer Learning for Vision. Photo organization apps use classification-style features for search and duplicate detection. Medical imaging pipelines use fine-tuned classifiers to flag likely-malignant regions for radiologist review. Content moderation systems at social platforms run classification models continuously on uploaded images and video frames. Retail and e-commerce visual-search products embed images using classifier-derived features to find visually similar products. The benchmark that drove this progress, and the datasets and evaluation protocols that made comparison possible across labs, are covered in ImageNet and Benchmark Datasets; the training tricks (random crops, flips, color jitter) that let these networks generalize from finite training sets are covered in Data Augmentation for Vision.
Ask the tutor: Can you show why the residual formulation's gradient never fully vanishes, using the explicit chain rule across several stacked residual blocks?
Why subtract the maximum logit before exponentiating in softmax?
Floating-point numbers have limited range, and grows extremely fast — a logit of 100 already overflows standard 32-bit floats. Since softmax is invariant to adding a constant to every logit (the constant cancels in the ratio ), subtracting before exponentiating keeps every exponent at most zero, so every , avoiding overflow while producing mathematically identical probabilities. This is a numerically necessary but mathematically inert transformation, and virtually every deep learning framework implements softmax this way internally.
Is a deeper network always more accurate than a shallower one?
No. Very deep plain (non-residual) networks suffer from the degradation problem, where both training and test error rise past a certain depth because the optimizer cannot find a good solution in the larger space — this is not overfitting, since training error itself worsens. Residual connections mitigate this and let depth help up to a point, but returns diminish: ResNet-152 improves modestly over ResNet-50 at much higher compute cost, and beyond several hundred layers gains largely plateau for standard image classification without further architectural changes.
Why does AlexNet use dropout but ResNet architectures often rely more on batch normalization?
AlexNet's capacity is concentrated in two enormous fully connected layers with tens of millions of parameters each, which are highly prone to overfitting; dropout randomly zeroes activations during training to prevent co-adapted feature detectors, acting as an implicit ensemble regularizer. ResNet instead uses global average pooling before a small final linear layer, dramatically reducing the fully-connected parameter count, and relies on batch normalization after each convolution to stabilize and accelerate training of very deep stacks. The two techniques address different problems — overfitting versus training stability — and modern architectures often use both where each is needed.
What is the difference between logits, softmax probabilities, and the predicted class?
Logits are the raw, unbounded real-valued outputs of the final linear layer — they can be any real number and have no probabilistic interpretation on their own. Softmax probabilities are the normalized, non-negative values summing to one, obtained by exponentiating and rescaling the logits — these are interpretable as the model's estimated class probabilities. The predicted class is simply (equivalently , since softmax preserves ordering), the single label the model commits to as its best guess.
Why do ResNet bottleneck blocks use 1×1 convolutions around a 3×3 convolution?
A bottleneck block uses a 1×1 convolution to reduce channel depth, a 3×3 convolution to process the reduced representation, and another 1×1 convolution to restore the original channel depth. This sandwich drastically cuts the computational cost of the expensive 3×3 convolution — which scales with — while keeping the block's representational capacity, letting deep ResNets (50, 101, 152 layers) stay computationally comparable to much shallower plain networks. It is a direct application of the parameter-vs-receptive-field tradeoff also seen in VGG's small-kernel design.
Can a classifier trained with softmax handle images belonging to multiple valid classes at once?
Not correctly, because softmax's normalization forces the probabilities to sum to one, encoding an assumption that classes are mutually exclusive. An image that genuinely contains both a dog and a frisbee, labeled correctly with both tags, would force the model to arbitrarily split probability mass between them even when both are fully present. The standard fix for such multi-label settings is to replace the single softmax with independent sigmoid outputs, each trained with its own binary cross-entropy loss, so the presence of one class does not suppress the score of another.
How does this classification pipeline relate to the CNN operations covered elsewhere?
This article assumes the mechanics of convolution, pooling, and nonlinearities from CNNs for Images Revisited and focuses on how those pieces are assembled into full architectures and trained as classifiers. The backbone designs described here — AlexNet, VGG, ResNet — become the reusable feature extractors discussed in Transfer Learning for Vision, the benchmark and dataset context is developed in ImageNet and Benchmark Datasets, and the training tricks needed to make these networks generalize are the subject of Data Augmentation for Vision.