1 Why FC layers fail on images
- A 224ร224ร3 image = 150,528 inputs. One FC layer to 1000 neurons = ~150.5M weights โ and that's ONE layer.
- Wasteful, overfits instantly, slow, memory-hungry.
- Core issue: FC treats every pixel as equally related to every neuron โ it ignores spatial structure.
- Key fact: nearby pixels are correlated (sky is blue in patches); distant pixels are usually unrelated.
2 Local connectivity
- Solution: connect each neuron to only a small local patch of the input, not the whole image.
- Same job, drastically fewer parameters โ each neuron sees only a small region.
- Intuition (Where's Waldo): your eye scans local patches for a pattern, then recognises it anywhere in the image.
3 Filters / kernels
- A filter (kernel) is a small grid of learnable weights (e.g. 3ร3).
- Operation = slide, multiply, sum, repeat: at each position, element-wise multiply with the patch then sum โ one output value.
- A filter responds (large output) where it finds its pattern; uniform regions โ output โ 0; matching edges โ large output.
- Examples: vertical-edge filter
[1 0 -1; 1 0 -1; 1 0 -1]; horizontal-edge filter[1 1 1; 0 0 0; -1 -1 -1].
4 Feature maps & dimensions
- 1 filter โ 1 feature map (detects one pattern). N filters โ N feature maps. Typical: 32, 64, 128, 256 per layer.
- Filter depth always equals the number of input channels.
| Component | Dimensions |
|---|---|
| Input | H ร W ร C |
| One filter | F ร F ร C (spans all input channels) |
| N filters โ output | Hโฒ ร Wโฒ ร N |
e.g. 224ร224ร3 with 64 filters โ 224ร224ร64.
5 Padding & stride
- Shrinking problem: each conv layer shrinks spatial dims (5ร5 โ 3ร3 โ 1ร1 โ gone). Fix = padding.
- Valid padding (no pad): output shrinks, e.g. 5ร5 with 3ร3 โ 3ร3.
- Same padding (pad=1 for 3ร3): ring of zeros around the border โ output = input size (5ร5 โ 5ร5). Most common.
- Stride = how far the filter jumps. Stride 1 = every position (default); stride 2 = skip every other โ output roughly halves.
- Stride > 1 is used for downsampling โ a modern alternative to pooling.
6 Output-size formula
Output = (W - F + 2P) / S + 1W = input size, F = filter size, P = padding, S = stride. Apply per spatial dimension; floor the result.
| W | F | P | S | Output |
|---|---|---|---|---|
| 7 | 3 | 0 | 1 | (7-3+0)/1+1 = 5 |
| 7 | 3 | 1 | 1 | (7-3+2)/1+1 = 7 (same!) |
| 7 | 3 | 1 | 2 | (7-3+2)/2+1 = 4 |
| 32 | 5 | 2 | 1 | (32-5+4)/1+1 = 32 (same!) |
Rule of thumb: for "same" padding with stride 1, set P = โF/2โ.
8 Receptive field
- Receptive field (RF): the region of the original input that one neuron "sees".
- Stacking 3ร3 convs (stride 1): 1 layer โ 3ร3, 2 layers โ 5ร5, 3 layers โ 7ร7. Each layer adds context.
- Formula:
RF = 1 + Lยท(F - 1)(L = layers, F = filter size). - Hierarchy of features: early layers โ edges/colors (small RF); middle โ textures/parts; deep โ objects/scenes (large RF). This is why we stack conv layers.
9 Pooling
- Pooling downsamples and summarizes. Max pooling (2ร2, stride 2): take the max in each window โ 4ร4 becomes 2ร2.
- Idea: "is there a strong feature somewhere in this region? I don't care exactly where."
- Three wins: (1) reduces spatial size / compute, (2) translation invariance (small shifts โ same output), (3) increases receptive field.
- Types: max pooling (classic), average pooling, global average pool (end of network).
โ Likely exam questions
Q1. A 128ร128ร3 image into an FC layer with 256 neurons โ how many weights? Why a problem?
128ยท128ยท3ยท256 = 12,582,912 weights. Overfits on small data, computationally expensive, and ignores spatial structure.
Q2. Input 13ร13, filter 5ร5, padding 2, stride 2 โ output size?
(13 - 5 + 2ยท2)/2 + 1 = 12/2 + 1 = 7 โ 7ร7.
Q3. Why does parameter sharing make sense for images but not for tabular features?
A pattern (e.g. a vertical edge) can appear anywhere in an image, so one shared filter works everywhere. In tabular data each feature (age, income) means something different โ sharing weights across them is nonsensical.
Q4. Receptive field of two stacked 3ร3 convs (stride 1)? Three layers?
Two layers โ 5ร5, three layers โ 7ร7. Each 3ร3 layer adds 2 pixels of context. Formula: RF = 1 + Lยท(F โ 1).
Q5. Main tradeoff of max pooling, and when does it hurt?
It discards exact spatial location โ you know a feature exists in a region but not precisely where. Hurts pixel-level tasks like segmentation or super-resolution.
Q6. State the output-size formula and give "same" padding for a 3ร3, stride-1 conv.
Output = (W โ F + 2P)/S + 1. For "same" output with stride 1, P = โF/2โ = 1 for a 3ร3 filter.