Convolutional Neural Networks
Source: CS1674 Ch.14 (Part A). CNNs replace fully-connected layers for images with local receptive fields + weight sharing (convolution), add pooling, and stack into deep architectures (AlexNet, VGG, GoogLeNet/Inception, ResNet).
1. Backstory & Motivation
- Biological inspiration: Hubel & Wiesel (Nobel 1981) — visual cortex has a hierarchy of simple → complex → hyper-complex cells with local receptive fields.
- Neocognitron (Fukushima 1980): self-organizing model invariant to shift.
- LeNet-5 (LeCun et al. 1998): gradient-based document recognition.
Why not an MLP for images?
A multi-layer perceptron takes the whole image as a flat vector → fully connected to the next layer. Problems:
- Too many parameters (e.g., 224×224×3 → millions of weights for one FC layer).
- No spatial prior; treats pixels as independent; not translation-equivariant.
Convolutional architecture
Limit each unit's receptive field, slide it across the input, and use shared weights (the same filter everywhere). This is equivalent to sliding a learned filter and computing dot products at every location → a feature map.
2. The Convolution (Cross-Correlation) Layer
For an input patch and a
For an
Examples (input
- No padding, stride 1 →
- With padding 1, stride 1 → 7
- With padding, stride 2 →
(In DL practice this is cross-correlation, not true convolution — the filter is not flipped; consistent with Ch.2 convention.)
Channels / feature maps
- One input image has
input feature maps (e.g., RGB → ); produce output feature maps. - Each output map uses an
filter (3D filter). - Computational cost (MAC units) to compute the full output volume:
Receptive field growth
Stacking conv layers grows the receptive field: three
3. Why 1×1 Convolutions?
With
Example (256-channel I/O):
- Structure A: one
conv, 256→256 → weights/MAC. - Structure B (bottleneck):
(256→64) + (64→64) + (64→256) → .
⇒ 1×1 convs reduce parameters and compute while preserving representational power (the Inception trick).
4. Depthwise Separable & Groupwise Convolutions
Depthwise + 1×1 (MobileNet, Howard et al. 2017)
- Depthwise: apply a
filter per input channel separately ( per position). - 1×1 (pointwise): mix across channels.
- Example: regular
, 256→256 ≈ 590,000 MAC; depthwise+1×1 ≈ 7,800 MAC → ~8.7× speedup.
Groupwise
Split the
5. Pooling
- Max pooling: take the max in each window (most common; preserves strong activations).
- Average pooling: take the mean.
Example:
6. Backpropagation Through a Conv Layer
Forward (1D for clarity):
The gradients distribute back through the same shared weights
7. Landmark Architectures (ImageNet ILSVRC)
| Year | Model | Key idea | Top-5 err. |
|---|---|---|---|
| 2012 | AlexNet (SuperVision, 7 layers) | First deep CNN winner; ReLU, dropout, GPU | 15.3% |
| 2014 | VGG-16 (Oxford) | Stack of | 7.32% |
| 2014 | GoogLeNet (Inception) | Inception modules, global avg pool | winner |
| 2015 | ResNet (152 layers) | Residual blocks; won localization/detection | best |
AlexNet vs. VGG-16
- AlexNet: ~61M params, 0.7 GFLOP, 1.9 MB.
- VGG-16: ~138M params (2.3×), 13.6 GFLOP (19.4×), 48.6 MB (25×). VGG shows depth helps, but cost grows.
GoogLeNet (Inception)
- Aggressive stem: rapidly downsamples at the start (cheap memory: 7.5 MB vs VGG-16's 42.9 MB).
- Inception module: parallel paths with different receptive-field sizes/operations capture sparse correlation patterns; uses 1×1 convs for dimensionality reduction before expensive convs.
- Global average pooling instead of huge FC layers (most VGG params were in FC) → far fewer parameters.
- Auxiliary classifiers help train very deep nets.
ResNet — why residuals?
A series of products in backprop causes vanishing gradients (extremely slow/no learning). The residual block adds a skip connection:
So the gradient includes:
Even if
Beyond ResNet
- Wide ResNet (WRN): fewer, wider blocks; a 16-layer WRN beats 1000-layer ResNets.
- ResNeXt: groupwise convolutions (cardinality).
- DenseNet: each layer connects to all subsequent layers (dense shortcuts).
8. Summary
- CNNs use local receptive fields + weight sharing + pooling → few params, translation equivariance/invariance.
- Output size:
; cost . - 1×1 convs mix channels cheaply; depthwise/separable convs (MobileNet) give huge speedups; groupwise (ResNeXt) for efficiency.
- Backprop through conv reuses shared weights.
- Architectures evolved: AlexNet → VGG (depth) → GoogLeNet (Inception, global pool) → ResNet (residuals fix vanishing gradients).
9. Receptive Field & Modern Training Tricks
Receptive field growth
The receptive field of a unit in layer
So strides compound multiplicatively; stacking
Batch Normalization (Batchnorm)
Normalize each feature across the mini-batch:
Dropout
Randomly zero a fraction of activations during training → prevents co-adaptation, improves generalization (common in FC parts; less used inside conv stacks).
Weight initialization
With ReLU, use He/Kaiming init:
Data augmentation
Flips, crops, color jitter, mixup/cutmix — cheap regularization that matters a lot for CNN generalization.
10. ResNet Bottleneck Block
A deeper residual building block uses the
The
11. The Modern CNN Recipe
- Stack
convs (sometimes depthwise-separable) with BN + ReLU. - Downsample via stride-2 convs (or pooling) to build a pyramid.
- Use shortcuts (ResNet) for deep training.
- End with global average pooling + a linear classifier (GoogLeNet style) instead of huge FCs.
- Regularize with augmentation + dropout; optimize with SGD/Adam.
CNNs remain the efficient, inductive-bias-rich backbone; even ViTs often use a light CNN stem.