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.
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 / params | Key idea | Result |
|---|---|---|---|
| LeNet-5 (1998) | ~7 layers / ~60k | Conv → subsample → conv → subsample → dense, trained end-to-end | Read handwritten digits on bank cheques |
| AlexNet (2012) | 8 layers / ~60M | ReLU, dropout, heavy data augmentation, trained on 2 GPUs | ILSVRC-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 design | 2nd in ILSVRC-2014 classification; hugely popular backbone |
| GoogLeNet / Inception (2014) | 22 layers / ~12× fewer than AlexNet | Inception modules: parallel 1×1, 3×3, 5×5 branches with 1×1 bottlenecks | Won ILSVRC-2014 classification (6.7% top-5) |
| ResNet (2015) | 18–152 layers / 25.6M (ResNet-50) | Residual (skip) connections + BatchNorm | Won ILSVRC-2015 (3.57% top-5, ensemble) |
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.
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].
- 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
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)).
Transfer learning
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 data | Similar 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 head | Freeze early layers, fine-tune later blocks carefully with strong augmentation |
| Large (tens of thousands+) | Fine-tune the whole network with a small learning rate | Fine-tune everything (pretrained init still usually beats random) |
- 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.
- 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.
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)weights.transforms() gives the matching preprocessing.- 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 = Falsedoes 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
References
- [1]Gradient-based learning applied to document recognitionPaperLeCun, Bottou, Bengio & Haffner1998doi.org
- [2]ImageNet Classification with Deep Convolutional Neural NetworksPaperKrizhevsky, Sutskever & Hinton2012papers.nips.cc
- [3]Very Deep Convolutional Networks for Large-Scale Image RecognitionPaperSimonyan & Zisserman2014arxiv.org
- [4]Deep Residual Learning for Image RecognitionPaperHe, Zhang, Ren & Sun2015arxiv.org
- [5]How transferable are features in deep neural networks?PaperYosinski, Clune, Bengio & Lipson2014arxiv.org
- [6]CS231n: Transfer LearningCourseStanford CS231ncs231n.github.io