Lecture 4: Convolutional Neural Networks
Why Not Just an MLP?
To feed an image into an MLP you flatten it into one long vector. A
- Too many parameters: a single fully connected layer can already need millions of weights.
- Loses spatial structure: after flattening, the MLP no longer knows which pixels are neighbors.
CNN idea: use small filters to extract image features first, then a small MLP to classify.
Image → [Conv + Pool] × k → Flatten → Fully connected → Class
feature extraction classifierConvolution
Slide a small filter (kernel) over the image. At each position, multiply element-wise and sum. The result is a feature map.
Classical vision used hand-designed filters (edge detectors, blur). A CNN learns the filter values by back-prop.
Few parameters
1000 filters of size
Stride and Padding
- Stride
: how far the filter moves each step. Larger stride → smaller output. - Padding
: add rings of zeros around the image so the border pixels are used too and the output does not shrink.
| Valid | Same | |
|---|---|---|
| Padding | none | |
| Output size | smaller than input | same as input |
Output size (input
Example:
Volume Convolution (Color / Multi-channel)
- The filter always has the same depth as the input. A
RGB input uses a filter, and one filter produces one channel. - Use
filters to get output channels.
Input
Example network
| Layer | filters | Output | |||
|---|---|---|---|---|---|
| input | |||||
| conv 1 | 3 | 1 | 0 | 10 | |
| conv 2 | 5 | 2 | 0 | 20 | |
| conv 3 | 5 | 2 | 0 | 40 | |
| flatten | 1960 |
Height and width shrink, channels grow.
Pooling
Shrink the feature map by summarizing each small window. No learnable parameters.
- Max pooling: keep the largest value (most common).
- Average pooling: keep the mean.
Typical CNN Layers
| Layer | Role |
|---|---|
| CONV | extract features with learned filters |
| POOL | shrink size, keep the strongest response |
| FC | final classifier |
Benefits and Challenges
Benefits
- Parameter sharing: the same filter (e.g. an edge detector) is useful everywhere in the image.
- Sparse connections: each output pixel depends only on a small patch of the previous layer.
- Translation invariance: a cat is recognized wherever it is in the image.
Challenges
- Convolutions are computationally expensive.
- Each layer only sees a local patch, so you need deep networks to understand the whole image.
Classic Architectures
| Network | Year | Key points |
|---|---|---|
| LeNet-5 | 1998 | first famous CNN, digit recognition. conv(6, 5×5) → avg pool → conv(16, 5×5) → avg pool → conv(120, 5×5) → FC 84 → FC 10 |
| AlexNet | 2012 | won ImageNet. ~60M parameters, ReLU, trained on multiple GPUs |
| VGG-16 | 2014 | only |
Trend: deeper networks built from smaller, simpler, repeated blocks.