Skip to content

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 32×32×3 image becomes 3072 inputs, and every neuron in the next layer connects to all of them.

  • 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            classifier

Convolution ​

Slide a small filter (kernel) over the image. At each position, multiply element-wise and sum. The result is a feature map.

[111011001]∗[101010101]=1+1+1+1=4

Classical vision used hand-designed filters (edge detectors, blur). A CNN learns the filter values by back-prop.

Few parameters

1000 filters of size 3×3 = 9K parameters, compared with millions for a fully connected layer.

Stride and Padding ​

  • Stride s: how far the filter moves each step. Larger stride → smaller output.
  • Padding p: add p rings of zeros around the image so the border pixels are used too and the output does not shrink.
ValidSame
Paddingnonep=(f−1)/2
Output sizesmaller than inputsame as input

Output size (input n×n, filter f×f):

out=⌊n+2p−fs⌋+1

Example: n=5,f=3,p=0: stride 1 → 3×3; stride 2 → 2×2.

Volume Convolution (Color / Multi-channel) ​

  • The filter always has the same depth as the input. A 5×5×3 RGB input uses a f×f×3 filter, and one filter produces one channel.
  • Use nf filters to get nf output channels.

Input 5×5×3, 5 filters of 2×2×3 → output 4×4×5.

Example network

LayerfspfiltersOutput
input39×39×3
conv 13101037×37×10
conv 25202017×17×20
conv 3520407×7×40
flatten1960

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.
[4925562424545684]→max, 2×2, s=2[9568]

Typical CNN Layers ​

LayerRole
CONVextract features with learned filters
POOLshrink size, keep the strongest response
FCfinal 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 ​

NetworkYearKey points
LeNet-51998first famous CNN, digit recognition. conv(6, 5×5) → avg pool → conv(16, 5×5) → avg pool → conv(120, 5×5) → FC 84 → FC 10
AlexNet2012won ImageNet. ~60M parameters, ReLU, trained on multiple GPUs
VGG-162014only 3×3 conv (same) and 2×2 max pool, stacked deep and regular. 64 → 128 → 256 → 512 → 512 filters, ~138M parameters

Trend: deeper networks built from smaller, simpler, repeated blocks.