AILearn AI
LearnGlossarySources
ID/EN
Learn AI — open material for learning AIEvery lesson cites its original sources.
▦Deep Learning Architectures
  1. Convolutional Neural Networks (CNNs)
  2. CNN Architectures and Transfer Learning
  3. Recurrent Networks: RNN, LSTM and GRU
  4. Embeddings: Meaning as Vectors
  5. Attention and Transformers
Modules
  1. ◎ AI Foundations
  2. ∿ Classical Machine Learning
  3. ⌬ Neural Networks
  4. ↘ Training Results & Evaluation
  5. ▦ Deep Learning Architectures
  6. ✎ Large Language Models
  7. ◐ Image Generation
  8. ♪ Audio & Speech AI
  9. ◈ Multimodal, Video & 3D
  10. ↻ Reinforcement Learning
  11. ⚙ ML Development & MLOps
  12. ★ Advanced & Frontier Topics
Learn/Deep Learning Architectures

CNN Architectures and Transfer Learning

LeNet, AlexNet, VGG, GoogLeNet and ResNet: the ideas each one added, why residual connections made 100+ layer networks trainable, and how to reuse a pretrained network for your own task.

Intermediate~25 min·6 references
Key terms
CNN (Convolutional Neural Network)ResNet (Residual Network)Transfer learningPoolingBatch normalizationDropoutData augmentation

Between 2012 and 2015, the ImageNet Large Scale Visual Recognition Challenge (ILSVRC: 1.2 million training images, 1,000 classes) turned into a race of CNN architectures. Top-5 error fell from about 26% (non-deep methods) to under 4% in four years. Each winning design introduced an idea that is still in use today. Knowing them helps you read modern architectures — and, more practically, choose a pretrained backbone for transfer learning.

Model (year)Depth / paramsKey ideaResult
LeNet-5 (1998)~7 layers / ~60kConv → subsample → conv → subsample → dense, trained end-to-endRead handwritten digits on bank cheques
AlexNet (2012)8 layers / ~60MReLU, dropout, heavy data augmentation, trained on 2 GPUsILSVRC-2012 top-5 error 15.3% vs 26.2% for the runner-up
VGG-16/19 (2014)16–19 layers / ~138M (VGG-16)Only 3×3 convs, stacked deep; very uniform design2nd in ILSVRC-2014 classification; hugely popular backbone
GoogLeNet / Inception (2014)22 layers / ~12× fewer than AlexNetInception modules: parallel 1×1, 3×3, 5×5 branches with 1×1 bottlenecksWon ILSVRC-2014 classification (6.7% top-5)
ResNet (2015)18–152 layers / 25.6M (ResNet-50)Residual (skip) connections + BatchNormWon ILSVRC-2015 (3.57% top-5, ensemble)
Numbers from the original papers[1][2][3][4].

LeNet-5: the template

LeCun et al. established the pattern almost every CNN still follows: alternate convolutions (to detect features) with downsampling (to grow the receptive field and reduce size), then finish with fully connected layers for classification — and train the whole thing with backpropagation[1]. It used tanh-like activations and average-pooling-style subsampling on 32×32 grayscale digits.

AlexNet: deep learning goes mainstream

Krizhevsky, Sutskever & Hinton scaled the template up and made it trainable on 1.2M images: ReLU activations (training several times faster than tanh in their experiments), dropout (p = 0.5) in the large dense layers, data augmentation (random crops, flips, colour shifts) and a two-GPU implementation[2]. The large margin of victory in 2012 is widely seen as the start of the deep learning era in computer vision.

VGG: small kernels, deep stacks

Simonyan & Zisserman showed depth itself matters, using only 3×3 convolutions[3]. Two stacked 3×3 layers have the same 5×5 receptive field as one 5×5 layer but use 2·9 = 18 instead of 25 weights per channel pair, and add an extra non-linearity; three 3×3 layers replace a 7×7 (27 vs 49). The downside: ~138M parameters, most of them in the final dense layers, and heavy compute.

Loading interactive…
VGG-16 in 3D. Rotate it and tap the layers: the 224×224 image shrinks by half after every pooling stage while channels double from 64 to 512. Tap the first dense layer to see where most of the ~138M parameters live, then switch to AlexNet and LeNet-5 to compare the three designs.

ResNet: learning the residual

Simply stacking more layers eventually made things worse: on CIFAR-10, a plain 56-layer network had higher training error than a 20-layer one. That's not overfitting — it's an optimization failure (the “degradation problem”). He et al.'s fix was the residual block: let each block learn a correction F(x) that is added to its input[4].

y = F(x, {Wᵢ}) + x ⇒ ∂y/∂x = ∂F/∂x + I
If the best thing a block can do is nothing, it only has to push F toward 0 — easy. The “+ I” gives gradients a direct highway back to early layers.
In words: The block's output is its input plus a learned correction. Differentiating gives the learned part's slope plus the identity, so even if ∂F/∂x is tiny, the gradient still passes through with a factor of about 1.
Symbols(hover a symbol in the formula)
x
block input (e.g. a 56×56×64 feature map)
y
block output, same shape as x
F(x, {Wᵢ})
the residual function: the block's conv–BN–ReLU layers with weights Wᵢ
⇒
“implies”: what follows when you differentiate the left side
∂y/∂x
how the output changes with the input — the factor the gradient is multiplied by when flowing backwards
∂F/∂x
the slope of the learned part alone
I
identity (1 for scalars): the contribution of the shortcut
▸Worked example
Toy scalar block F(x) = 0.1·x, input x = 2 Residual: y = 0.2 + 2 = 2.2, ∂y/∂x = 0.1 + 1 = 1.1 Plain: y = 0.2, ∂y/∂x = 0.1 Through 10 stacked blocks the gradient is multiplied by plain: 0.1¹⁰ = 0.0000000001 (vanished) residual: 1.1¹⁰ ≈ 2.59 (still alive; BatchNorm and small initial weights keep F small).

ResNets train reliably at 50, 101 or 152 layers (and over 1,000 on CIFAR). Deeper variants use a bottleneck block: 1×1 conv (reduce channels) → 3×3 conv → 1×1 conv (expand), keeping compute manageable. Every conv is followed by Batch normalization. Skip connections are now everywhere: in U-Nets, in every Transformer block, in diffusion models. Later CNNs refined the recipe — DenseNet, EfficientNet's compound scaling, and ConvNeXt (Liu et al., 2022) which modernised ResNet to compete with Vision Transformers (Vision Transformer (ViT)).

Loading interactive…
The three kinds of residual block. Press Walk through to follow x through the basic block, then the projection shortcut used when a stage halves the resolution, then the bottleneck. Notice that the ReLU comes after the addition, and that the identity shortcut has no parameters at all.
Loading interactive…
ResNet-18 in 3D: a 7×7 stem, then four stages of two basic blocks each. Rotate and tap the layers to follow the shapes 112 → 56 → 28 → 14 → 7 while channels go 64 → 512, and notice how few parameters the global-average-pool classifier needs compared with VGG's dense layers.

Transfer learning

≈
An experienced photographer learns a new subject
A photographer who has shot thousands of street scenes already understands light, edges, textures and composition. Asked to photograph birds, they don't relearn how a camera works — they only learn what makes a good bird photo. Transfer learning does the same: keep the general visual knowledge of a network pretrained on ImageNet, and learn only the task-specific part.

Yosinski et al. measured how transferable each layer is: early layers learn general features (edges, colour blobs, Gabor-like filters) that transfer almost perfectly between tasks; later layers become increasingly specific to the original classes[5]. So the standard approach is to take a pretrained backbone, replace its final classification layer with a new “head” for your classes, and decide how much of the backbone to retrain[6].

Your dataSimilar to ImageNet (photos of objects)Very different (X-rays, satellite, spectrograms)
Small (hundreds–few thousand images)Feature extraction: freeze the backbone, train only the new headFreeze early layers, fine-tune later blocks carefully with strong augmentation
Large (tens of thousands+)Fine-tune the whole network with a small learning rateFine-tune everything (pretrained init still usually beats random)
A rule-of-thumb grid adapted from the CS231n notes on transfer learning.
knobNumber of frozen layers
What it is
How much of the pretrained backbone is kept fixed (requires_grad = False) while training on your data.
↑ If you increase it
Fewer trainable parameters: faster, less memory, less overfitting on small datasets — but less adaptation; if your images are very different from ImageNet, accuracy plateaus lower.
↓ If you decrease it
More adaptation and usually higher accuracy with enough data; with little data, risk of overfitting and of destroying useful pretrained features.
Typical values
Start with everything frozen except the head; then unfreeze the last stage or two.
knobFine-tuning learning rate
What it is
The learning rate for pretrained layers — usually much smaller than for the freshly initialized head (discriminative learning rates).
↑ If you increase it
Faster adaptation, but too high wipes out pretrained features (“catastrophic forgetting”) and validation accuracy can drop below the frozen baseline.
↓ If you decrease it
Preserves pretrained knowledge, but adapts slowly; at 0 it equals freezing.
Typical values
Backbone: ~10× smaller than the head, e.g. 1e-4 (backbone) vs 1e-3 (head) with AdamW.
python
import torch
import torch.nn as nn
from torchvision.models import resnet50, ResNet50_Weights

weights = ResNet50_Weights.DEFAULT
model = resnet50(weights=weights)
preprocess = weights.transforms()          # the exact resize/crop/normalize used in pretraining

# Stage 1: feature extraction — freeze the backbone, train a new head
for p in model.parameters():
    p.requires_grad = False
model.fc = nn.Linear(model.fc.in_features, 5)     # new head for 5 classes (trainable)
opt = torch.optim.AdamW(model.fc.parameters(), lr=1e-3)
# ... train a few epochs ...

# Stage 2: fine-tune the last stage with a smaller learning rate
for p in model.layer4.parameters():
    p.requires_grad = True
opt = torch.optim.AdamW([
    {"params": model.layer4.parameters(), "lr": 1e-4},
    {"params": model.fc.parameters(), "lr": 1e-3},
], weight_decay=0.01)
Two-stage transfer learning with a torchvision ResNet-50. weights.transforms() gives the matching preprocessing.
!
Common pitfalls
Watch out for these:
  • Wrong preprocessing: a pretrained model expects the same resize and mean/std normalization it was trained with. Different normalization quietly costs accuracy.
  • BatchNorm while fine-tuning with tiny batches: requires_grad = False does not stop BN running statistics from updating in train mode. Put frozen BN layers in eval mode if batches are small.
  • One learning rate for everything: the random new head needs a much larger LR than the pretrained layers.
  • Licences: check the licence of pretrained weights and their training data before commercial use.
▸Go deeper: why do residual connections work so well?

In a follow-up paper, He et al. (Identity Mappings in Deep Residual Networks, 2016) showed that keeping the skip path a pure identity (moving BN and ReLU inside the residual branch, “pre-activation”) lets signals propagate directly between any two blocks in both the forward and backward pass, enabling 1,001-layer networks. Unrolled, a ResNet is a sum over many paths of different lengths — gradients always have a short path back, which counters vanishing gradients the same way the LSTM's additive cell state does for sequences.

Quiz

1.
A plain 56-layer CNN has higher TRAINING error than a 20-layer one. What does this indicate?
2.
Why did VGG use stacks of 3×3 convolutions instead of larger kernels?
3.
You have 800 labelled photos of 4 kinds of flowers. What's the best starting strategy?
4.
Which ingredients did AlexNet popularize?
5.
When fine-tuning, you set requires_grad = False on all BatchNorm layers but train with batch size 2. Validation accuracy collapses. Why?
Score: 0/5

References

  1. [1]
    Gradient-based learning applied to document recognition
    PaperLeCun, Bottou, Bengio & Haffner1998doi.org
  2. [2]
    ImageNet Classification with Deep Convolutional Neural Networks
    PaperKrizhevsky, Sutskever & Hinton2012papers.nips.cc
  3. [3]
    Very Deep Convolutional Networks for Large-Scale Image Recognition
    PaperSimonyan & Zisserman2014arxiv.org
  4. [4]
    Deep Residual Learning for Image Recognition
    PaperHe, Zhang, Ren & Sun2015arxiv.org
  5. [5]
    How transferable are features in deep neural networks?
    PaperYosinski, Clune, Bengio & Lipson2014arxiv.org
  6. [6]
    CS231n: Transfer Learning
    CourseStanford CS231ncs231n.github.io
← Previous
Convolutional Neural Networks (CNNs)
Next →
Recurrent Networks: RNN, LSTM and GRU