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.

Key takeaways
  • Image classification maps a whole image to one label from a fixed set of KK 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.
The core insight

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 xx to exactly one label y∈{1,…,K}y \in \{1, \dots, K\} 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 KK classes. The classification head is almost always a single linear (fully connected) layer producing KK real-valued logits z1,…,zKz_1, \dots, z_K, followed by the softmax function:

pk=ezk∑j=1Kezj,k=1,…,K.p_k = \frac{e^{z_k}}{\sum_{j=1}^{K} e^{z_j}}, \qquad k = 1, \dots, K.

Softmax converts arbitrary real-valued scores into a valid probability distribution: every pk∈(0,1)p_k \in (0,1) and ∑kpk=1\sum_k p_k = 1. 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 pp and the one-hot true label yy:

L(x,y)=−log⁡py=−zy+log⁡∑j=1Kezj.\mathcal{L}(x, y) = -\log p_y = -z_y + \log \sum_{j=1}^{K} e^{z_j}.

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 KK-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 3×33\times3 convolutions with stride 1 and padding 1 (which preserve spatial size), only 2×22\times2 max-pooling with stride 2 (which halves spatial size), and double the channel count after every pooling stage. Two stacked 3×33\times3 convolutions have the same receptive field as one 5×55\times5 convolution but with fewer parameters and an extra nonlinearity, and three stacked 3×33\times3 convolutions match a 7×77\times7 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 H(x)H(x), it asks them to learn a residual F(x)=H(x)−xF(x) = H(x) - x, and adds the input back via a shortcut connection:

y=F(x,{Wi})+x.y = F(x, \{W_i\}) + x.

If the optimal mapping for a block is close to the identity, it is trivial to drive F(x)→0F(x) \to 0 (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.

Figure
Three backbone philosophies feeding the same softmax head
AlexNet Conv 11×11 /4 Pool Conv 5×5 Pool 3×Conv 3×3 Pool FC 4096 ×2 Drop VGG-16 2×Conv 3×3 Pool 2×Conv 3×3 Pool 3×Conv 3×3 Pool 3×Conv 3×3 Pool 3×Conv 3×3 FC 4096 ×2 ResNet-34 Conv 7×7 /2 Res ×3 Res ×4 Res ×6 Res ×3 GlobalAvgPool Linear + Softmax p₁ … p_K all three backbones feed the same classifier head

Complexity & correctness

Forward-pass time complexity. For a convolutional layer with input size H×W×CinH \times W \times C_{in}, kernel size k×kk \times k, and CoutC_{out} output channels applied with stride 1, the cost is

O(H⋅W⋅Cin⋅Cout⋅k2)O(H \cdot W \cdot C_{in} \cdot C_{out} \cdot k^2)

multiply-accumulate operations, because each of the H⋅WH \cdot W output positions per output channel requires a k×k×Cink \times k \times C_{in} dot product, repeated for CoutC_{out} channels. A full backbone's cost is the sum of this quantity over all layers. VGG's design choice of two stacked 3×33\times3 convolutions in place of one 5×55\times5 is not just about receptive field: parameter count drops from 25C225 C^2 to 2⋅9C2=18C22 \cdot 9 C^2 = 18 C^2 for equal channel width CC, and three 3×33\times3 layers replacing one 7×77\times7 drop parameters from 49C249C^2 to 27C227C^2 — 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 KK logits z(x;θ)z(x;\theta) as a function of image xx and parameters θ\theta. Define the likelihood of the training set under the categorical model P(y∣x;θ)=softmax(z(x;θ))yP(y \mid x;\theta) = \text{softmax}(z(x;\theta))_y. The log-likelihood of the whole training set, assuming i.i.d. samples, is

ℓ(θ)=∑i=1Nlog⁡P(yi∣xi;θ)=−∑i=1NL(xi,yi).\ell(\theta) = \sum_{i=1}^{N} \log P(y_i \mid x_i; \theta) = -\sum_{i=1}^N \mathcal{L}(x_i, y_i).

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 zkz_k gives the clean expression

∂L∂zk=pk−1[k=y],\frac{\partial \mathcal{L}}{\partial z_k} = p_k - \mathbb{1}[k = y],

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 H(x)H(x) via stacked nonlinear layers versus a residual block computing F(x)+xF(x) + x where FF 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 FF 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 y=F(x)+xy = F(x) + x contributes a +1+1 term to ∂y/∂x\partial y/\partial x, 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 ϕ\phi, and the final linear layer produces logits for classes {cat, dog, bird}: z=[2.0, 1.0, 0.1]z = [2.0,\ 1.0,\ 0.1]. The true label is "dog" (index 2).

Step 1 — softmax. Subtract the max for stability (m=2.0m = 2.0):

classzkz_kzk−mz_k - mezk−me^{z_k - m}
cat2.00.01.0000
dog1.0-1.00.3679
bird0.1-1.90.1496

Sum =1.0000+0.3679+0.1496=1.5175= 1.0000 + 0.3679 + 0.1496 = 1.5175.

pcat=1.0000/1.5175=0.659,pdog=0.3679/1.5175=0.242,pbird=0.1496/1.5175=0.099.p_{\text{cat}} = 1.0000/1.5175 = 0.659,\quad p_{\text{dog}} = 0.3679/1.5175 = 0.242,\quad p_{\text{bird}} = 0.1496/1.5175 = 0.099.

Check: 0.659+0.242+0.099=1.0000.659 + 0.242 + 0.099 = 1.000 ✓.

Step 2 — cross-entropy loss. True label is "dog", so

L=−log⁡(0.242)=1.418.\mathcal{L} = -\log(0.242) = 1.418.

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., −log⁡(0.95)=0.051-\log(0.95) = 0.051).

Step 3 — gradient at the logits. Using ∂L/∂zk=pk−1[k=y]\partial \mathcal{L}/\partial z_k = p_k - \mathbb{1}[k=y]:

classpkp_k1[k=y]\mathbb{1}[k=y]gradient
cat0.6590+0.659
dog0.2421-0.758
bird0.0990+0.099

The gradient pushes the "cat" and "bird" logits down (positive gradient means increasing zz 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 ϕ\phi came from three different backbones processing a 224×224×3224\times224\times3 cat photo, the backbones differ enormously upstream even though the head computation above is identical:

BackboneDepth (weight layers)Approx. parametersTop-5 ImageNet error (roughly, original papers)
AlexNet8~60M~17%
VGG-1616~138M~7-8%
ResNet-152152~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

PitfallWhy it happensFix
Skipping the max-subtraction in softmaxezke^{z_k} overflows for large logits, producing `NaN`Always compute ezk−max⁡jzje^{z_k - \max_j z_j} before normalizing
Using softmax+cross-entropy for multi-label imagesSoftmax enforces mutual exclusivity; an image can have several correct labelsUse independent sigmoid outputs with binary cross-entropy per class
Training a 50-layer plain (non-residual) CNN and blaming overfittingRising training error with depth is a degradation/optimization problem, not overfittingAdd 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 setsAdd dropout on FC layers and L2 weight decay on all layers
Testing accuracy computed with train-time batch norm statisticsBatch statistics differ between a single test image and training minibatchesSwitch to running (population) statistics at evaluation/inference time
Comparing architectures without controlling for training recipeLearning rate schedule, augmentation, and epochs affect accuracy as much as architectureHold training procedure fixed when isolating architectural effects

Pioneers & history

Origins · 1 minGeoffrey Hinton and how this was discovered
GH
Geoffrey Hinton
born 1947 · University of Toronto and Google; co-author of the AlexNet paper and pioneer of backpropagation for deep networks

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.

KH
Kaiming He
active researcher, Microsoft Research Asia then Facebook AI Research · lead author of the ResNet paper and of the Kaiming/He weight-initialization scheme

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.

History
1989
— Yann LeCun demonstrates convolutional networks (LeNet) for handwritten digit recognition, establishing the conv/pool/nonlinearity template.
2012
— Krizhevsky, Sutskever, and Hinton's AlexNet wins the ImageNet Large Scale Visual Recognition Challenge, halving the prior best error rate.
2014
— Simonyan and Zisserman introduce VGGNet, showing uniform small-kernel stacking scales accuracy with depth.
2014
— Szegedy et al. introduce GoogLeNet/Inception, using multi-branch modules for efficiency at similar depth.
2015
— He, Zhang, Ren, and Sun introduce ResNet with residual connections, winning ImageNet with a 152-layer network.

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 eze^{z} 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 ezk−c/∑jezj−ce^{z_k-c}/\sum_j e^{z_j-c}), subtracting max⁡jzj\max_j z_j before exponentiating keeps every exponent at most zero, so every ezk−c∈(0,1]e^{z_k-c} \in (0,1], 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 arg⁡max⁡kpk\arg\max_k p_k (equivalently arg⁡max⁡kzk\arg\max_k z_k, 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 Cin⋅CoutC_{in} \cdot C_{out} — 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 KK 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.

Before this

Where this leads