Skip to main content
LearnMLAcademy
Advanced10 min read

CNN Architectures: AlexNet to ResNet

Understand deep residual connections and skip connections in ResNet networks, with feature-map visuals, architecture comparisons, and image exercises.

What you will master in this lesson
Intuitive core mechanisms & practical real-world intuition
Step-by-step mathematical breakdown & visual diagrams
Runnable Python implementation & practical trade-offs

Deep Learning · Architecture Design

From LeNet to ResNet: Why CNN Architectures Changed

CNN architecture names are useful only when you understand the problem each design tried to solve. This lesson follows the move from small digit recognizers to GPU-scale networks, repeated small filters, multi-scale branches and residual shortcuts. You will calculate why stacked 3 × 3 filters work, trace a residual block with numbers, and learn when a pretrained architecture is a sensible starting point.

An Architecture Is a Plan for Moving and Combining Features

The previous lesson explained convolution, feature maps and pooling. An architecture specifies how many of those operations are used, how they connect, when spatial size shrinks, how channel count grows and how the final prediction is produced. Changing the plan changes accuracy, memory, speed and how easily gradients reach early layers.

The classic architectures below are milestones because each demonstrated a reusable idea. Later models did not simply “add more layers”; they found better ways to use depth, computation and information flow.

CNN progress was a sequence of solved bottlenecks

Read this as a map of design ideas, not a leaderboard for today.

Timeline from LeNet-5 to ResNetFive architecture milestones and the main problem-solving idea associated with each.1998 · LeNet-5
Conv + pooling for digits
2012 · AlexNet
Scale, GPUs, ReLU, dropout
2014 · VGG
Repeat small 3×3 filters
2014 · GoogLeNet
Parallel multi-scale branches
2015 · ResNet
Identity shortcuts
Each model inherited ordinary convolutional building blocks. Its historical importance comes from a design or training choice that made a new scale of visual learning practical.

LeNet-5 Established the Basic CNN Pattern

LeNet-5 was designed for small grayscale character images. Its recognizable flow—convolution, subsampling, another convolution, then fully connected classification—showed that a network could learn local stroke patterns and combine them into digit evidence. It is small enough to study, but its original activations and training context belong to an earlier era.

Read an architecture as a sequence of explained shape changes

The historical LeNet-5 flow is useful because every dimension can be followed. Shapes below use channels × height × width for one image.

1Input1 × 32 × 321 grayscale channel; 32×32 pixels are supplied by the data
2C1 convolution6 × 28 × 28six 5×5 filters are a designer choice; 28 = 32−5+1
3S2 subsample6 × 14 × 14each 2×2 region is reduced; the six channels remain
4C3 convolution16 × 10 × 10sixteen output maps are chosen; 10 = 14−5+1
5S4 subsample16 × 5 × 5spatial width and height are halved again
6Classifier120 → 84 → 10120 and 84 are architecture choices; 10 matches the digit classes
Channel counts such as 6 and 16 were selected by the model designers. Spatial sizes such as 28 and 10 are consequences of the filter and padding choices. The final 10 is dictated by the task because the possible labels are digits 0–9.

AlexNet Showed What Scale, ReLU and GPUs Could Do

AlexNet tackled ImageNet: roughly 1.2 million training images across 1,000 classes in the original competition setup. Its five convolutional and three fully connected learned layers were far larger than LeNet. GPU training made the computation feasible; ReLU activations trained faster than saturating tanh units in that setting; overlapping max pooling, data augmentation and dropout were important parts of the system.

Compute

The original network split work across two GPUs because the model did not fit conveniently on one GPU of that era.

Optimization

ReLU produced positive linear responses instead of saturating both sides like sigmoid/tanh.

Generalization

Random crops/reflections and dropout reduced overfitting in a high-capacity model.

VGG Made Depth Easy to Read

VGG replaced a mixture of large filter sizes with a regular pattern: repeat 3 × 3 convolutions, then downsample. Stacking small filters gradually grows the receptive field while placing nonlinear activations between calculations. VGG-16 is conceptually clean and remains useful for education and feature-based perceptual losses, but its dense classifier makes the standard model very large.

Why VGG repeated 3 × 3 convolutions

Two stride-1, unpadded 3 × 3 layers give the second layer a 5 × 5 receptive field, with a nonlinearity between them.

3 × 3

first local view

→ ReLU →

3 × 3

second local view

=

5 × 5

effective receptive field

One 5×5 filter: 25 spatial weights per input-output channel pair.

Two 3×3 filters: 18 spatial weights in this simplified single-channel comparison, plus an extra learned nonlinearity.

Real multi-channel parameter counts also depend on the number of input and output channels, so the simplified 25-versus-18 comparison is not a complete layer count.

GoogLeNet Looked at Multiple Scales Without Paying the Full Cost

A small filter is good for fine detail; a larger filter sees a wider region. An Inception module sends the same input through several branches and concatenates their output channels. A 1 × 1 convolution is more than a spatial filter: at each position it learns a weighted combination across input channels and can reduce the number of channels before a costly 3 × 3 or 5 × 5 operation.

An Inception module asks several size questions in parallel

input maps
→
1×1 conv
1×1 → 3×3
1×1 → 5×5
pool → 1×1
→
concatenate channels
Small and larger filters capture different spatial scales. The 1 × 1 convolutions before expensive branches reduce channel count, so multi-scale processing costs less than applying every large filter to every input channel.

Why place a 1 × 1 convolution before an expensive 5 × 5 branch?

Suppose one location has 192 incoming channels and the branch should produce 32 output channels. These channel counts are architecture choices. Ignore biases so the comparison stays focused.

Direct 5 × 5 convolution

5 × 5 spatial weights
× 192 input channels
× 32 output filters
= 153,600 weights

Reduce to 16 channels, then use 5 × 5

1×1 reduction: 1×1×192×16 = 3,072
5×5 branch: 5×5×16×32 = 12,800
total = 15,872 weights

The 1 × 1 layer multiplies and adds across all 192 channels at each position, learning 16 useful mixtures. The following 5 × 5 filters process those 16 mixtures instead of all 192 maps, reducing this simplified branch count by almost ten times.

GoogLeNet also used global average pooling near the end, avoiding the enormous dense head seen in VGG. The trade-off is a more complicated branching design. Modern descendants changed the exact factorization and normalization choices, but the multi-scale and bottleneck ideas remained influential.

Why Simply Making a Plain Network Deeper Can Fail

Depth lets a network compose more stages of representation, but a deeper plain network can be harder to optimize. The ResNet authors highlighted a degradation problem: adding layers could produce higher training error, even when overfitting was not the explanation. In principle, extra layers could copy their input and do no harm; in practice, learning that identity through many nonlinear layers was difficult.

A residual block makes the easy path explicit. The main branch learns F(x), a change to the input, while the shortcut carries x directly. Their sum lets a block preserve information when a large change is unnecessary and gives gradient information a direct route backward.

A residual block learns a useful change while preserving a direct route

Residual block with main and identity pathsInput x flows through two convolutional layers to create F of x and also follows an identity shortcut. The two paths are added and passed through ReLU.xconv → ReLU→ convF(x)identity shortcut carries x+ReLUoutput yy = ReLU(F(x) + x)
The shortcut is usually an identity map when shapes match. If width, height or channel count changes, a learned projection such as a 1 × 1 convolution can align the shapes before addition.

One residual addition with numbers

For a transparent teaching example, we manually choose the incoming feature vector x = [2, −1] and suppose the convolutional branch has calculated F(x) = [0.5, 0.8]. In a trained network, x comes from the previous layer and F(x) is produced by learned convolution and normalization parameters.

1. Main branch result
F(x) = [0.5, 0.8]

2. Add matching positions
[0.5+2, 0.8+(−1)]
= [2.5, −0.2]

3. Apply ReLU
[max(0,2.5), max(0,−0.2)]
= [2.5, 0]

Why addition? It preserves the original signal while letting the branch propose a correction at each matching position. The gradient of the addition also contains a direct identity route back to x. Addition requires equal shapes; when shapes differ, the shortcut must first project x to the required size.

Compare the Design Idea, Not Just the Depth Number

ArchitecturePublishedRecognizable designProblem it helped solveImportant limitation
LeNet-51998Small conv/pool network for handwritten digitsShowed learned local features could replace much manual feature designHistorical teaching; input and activations differ from modern practice
AlexNet20125 convolutional + 3 dense trainable layers; ReLU, dropout, GPU trainingMade large-scale deep CNN image classification practicalLarge early filters and dense head are compute/parameter heavy
VGG-162014Uniform stacks of 3×3 convolutionsSimple repeated design increased depth and receptive fieldAbout 138M parameters in the standard ImageNet model
GoogLeNet / Inception v12014Parallel 1×1, 3×3, 5×5 and pooling branchesCaptured multiple scales while reducing expensive channel dimensionsBranch design is more complex than a plain sequential stack
ResNet2015Residual blocks with identity shortcutsMade substantially deeper networks easier to optimizeShortcuts help optimization but do not remove compute or guarantee better generalization

Parameter totals depend on the exact variant and classifier. For reference, Keras lists approximately 138.4M parameters for its standard VGG16 and 25.6M for ResNet50; depth and parameter count are not the same measurement.

Implement the Residual Idea Before Using a Full ResNet

This teaching block keeps the same number of channels and the same height and width, so the identity tensor can be added directly. Batch normalization and ReLU are shown in a common basic-block arrangement.

residual_block.py
import torch
from torch import nn

class BasicResidualBlock(nn.Module):
    def __init__(self, channels):
        super().__init__()
        self.main = nn.Sequential(
            nn.Conv2d(channels, channels, 3, padding=1, bias=False),
            nn.BatchNorm2d(channels),
            nn.ReLU(),
            nn.Conv2d(channels, channels, 3, padding=1, bias=False),
            nn.BatchNorm2d(channels),
        )
        self.relu = nn.ReLU()

    def forward(self, x):
        residual = self.main(x)   # learn F(x)
        return self.relu(residual + x)  # add identity path

block = BasicResidualBlock(channels=32)
x = torch.randn(8, 32, 28, 28)
y = block(x)
      print(y.shape)  # torch.Size([8, 32, 28, 28])

If a block changes shape—for example 32 to 64 channels with stride 2—the shortcut also needs a projection that produces the same shape. Tensor addition cannot combine mismatched dimensions.

Where the code dimensions come from: 8 is a chosen teaching batch size; 32 is the chosen channel count for the block; 28 × 28 is a sample spatial size. None of these values is learned.

What the layers do internally: each 3 × 3 convolution learns filters, padding 1 preserves 28 × 28, BatchNorm normalizes each channel and learns scale/shift parameters, and residual + x performs elementwise addition.

In Practice, Start From a Pretrained Model

For most applied image projects, recreating AlexNet or training ResNet from random weights is not the first choice. A model pretrained on a large image collection has already learned useful visual features. Replace its classifier for your classes, begin with conservative fine-tuning, and validate latency, memory and accuracy on your own data.

Project constraintReasonable starting directionWhy
Learning architecture mechanicsLeNet-like network or hand-built residual blockSmall enough to trace every shape
General image baselinePretrained ResNet-18/50Widely supported residual backbone
Very small device budgetMobileNet/EfficientNet-family lightweight variantDesigned for parameter/FLOP efficiency
Need simple feature extractor for legacy workflowPretrained VGG featuresEasy sequential blocks, but heavy model
Large modern vision pretrainingCompare modern CNN with Vision TransformerGlobal attention and convolutional bias trade off differently

Mistakes That Architecture Diagrams Can Hide

Counting names instead of tensors

Trace N×C×H×W and the shortcut shape through every stage. A familiar block name does not prevent a dimension error.

Assuming deeper always means better

Optimization, data size, regularization, compute and task difficulty matter. Compare validated systems, not layer counts.

Using historical preprocessing blindly

Use the preprocessing specified for the exact pretrained weights. Input size and normalization differ across model families.

Comparing parameter count alone

Latency depends on operation type, resolution, hardware, memory movement and implementation—not just parameters.

Forgetting the classifier head

A 1,000-class ImageNet head does not match a four-class project. Replace and train the final layer deliberately.

Loading weights into the wrong variant

Match architecture, version and weight enum; strict loading errors often reveal a real mismatch rather than an inconvenience.

The Design Story to Remember

  • LeNet established the convolution–downsample–classify pattern.
  • AlexNet demonstrated deep CNNs at ImageNet scale with GPUs, ReLU and strong regularization.
  • VGG made depth systematic by stacking small 3 × 3 filters.
  • GoogLeNet processed several spatial scales in parallel and used 1 × 1 bottlenecks.
  • ResNet added identity shortcuts so blocks could learn changes instead of reconstructing everything.
  • A modern project should select and benchmark a pretrained architecture against its actual accuracy, latency, memory and data constraints.

Continue Learning

Apply this concept in a real hands-on project

You have studied the idea. Now use it in working Python code, see the calculation and output, and explain what changed. Each project includes step-by-step instructions, full source and tests.

Practice challenge: predict an outcome first, run the code, and explain the difference.

Track Your Progress0% curriculum done

Finished "CNN Architectures: AlexNet to ResNet"?

Mark this lesson as completed to update your progress bar and track your milestones across the full curriculum.

Overall Progress0 / 167 lessons

Was this tutorial helpful?

Your feedback helps us continuously refine and improve our open-access tutorials.

Knowledge Check

Progress: 0/5

Test your active recall. Choose one answer for each question, then check it to reveal the step-by-step reasoning.

Question 1 of 5conceptual
What design made VGG deeper while keeping filters simple?
Question 2 of 5conceptual
Why does GoogLeNet use parallel branches?
Question 3 of 5conceptual
What is the core ResNet block idea?
Question 4 of 5interpretation
Why must shortcut and residual shapes match before addition?
Question 5 of 5practical selection
How should a pretrained architecture be selected?

Knowledge Check Review & Explanations

Review the questions, verified correct answers, and conceptual explanations for this lesson.

1What design made VGG deeper while keeping filters simple?▼

Correct Answer: Stacks of 3×3 convolutions

Repeated small filters build larger receptive fields with a systematic architecture.

2Why does GoogLeNet use parallel branches?▼

Correct Answer: To process several spatial scales in one module

Its inception module combines multiple receptive-field sizes and pooling paths.

3What is the core ResNet block idea?▼

Correct Answer: Add an identity shortcut to a learned residual

The shortcut lets the block learn a change F(x) and output F(x)+x.

4Why must shortcut and residual shapes match before addition?▼

Correct Answer: Addition is element-wise

Corresponding batch, channel, height, and width entries must align; projections handle mismatches.

5How should a pretrained architecture be selected?▼

Correct Answer: Benchmark accuracy, latency, memory, and data fit

Architecture choice is an empirical system decision, not a depth contest.

Keep moving through the path

Continue Learning

Free Download: ML Interview Cheatsheet

100 essential Machine Learning interview questions and answers covering foundations, algorithms, evaluation, deep learning, Python, system design and interview strategy. Enter your email to download it instantly.

Optional Learning Resources

These resources may complement the lesson. They are optional and are not required to use ML Academy.

As an Amazon Associate I earn from qualifying purchases. Other links are identified separately when they are not affiliate links.

Next