๐Ÿ“š Study Notes / Home / Neural Nets / Exam Notes / Convolutions
Exam Notes ยท W4S1

Convolutions

Why FC layers fail on images, and how local connectivity, learnable filters, padding, stride, receptive fields and pooling build up a CNN.

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.
ComponentDimensions
InputH ร— W ร— C
One filterF ร— F ร— C (spans all input channels)
N filters โ†’ outputHโ€ฒ ร— 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


Must-know for exam
Output = (W - F + 2P) / S + 1
W = input size, F = filter size, P = padding, S = stride. Apply per spatial dimension; floor the result.
WFPSOutput
7301(7-3+0)/1+1 = 5
7311(7-3+2)/1+1 = 7 (same!)
7312(7-3+2)/2+1 = 4
32521(32-5+4)/1+1 = 32 (same!)

Rule of thumb: for "same" padding with stride 1, set P = โŒŠF/2โŒ‹.

7 Parameter sharing


  • Parameter sharing: the same filter weights are used at every spatial location.
  • Why: a vertical edge looks the same top-left or bottom-right โ†’ no need to learn a separate detector per position.
  • Result: one 3ร—3 filter = 9 parameters, reused at all positions; FC equivalent โ‰ˆ 150M.
  • Makes sense for images (a pattern can appear anywhere) but NOT for tabular data, where each feature has a distinct meaning.

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).
Must-know tradeoff Pooling discards spatial precision โ€” you know a feature exists but lose exactly where. Hurts pixel-precise tasks (segmentation, super-resolution).

โ˜… 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.