3.4.1 · D3Convolutional Neural Networks

Worked examples — Convolution operation and filters

2,366 words11 min readBack to topic

This page is the "flight simulator" for the convolution operation. The parent note gave you the formula; here we fly it through every kind of situation you can meet — every sign, every degenerate size, every edge case — one fully worked example per situation, so you never hit a scenario you have not seen.

Before we start, one reminder in plain words. Convolution here means: lay a small grid of numbers (the filter, a box of weights) on top of a patch of the picture, multiply each filter number by the picture number underneath it, and add all those products into a single number. Slide the box one step and repeat. Every symbol below is earned from that one sentence.


The scenario matrix

Every convolution problem is really one of these case classes. Each row is a "cell" you must be able to handle; the last column names the example that covers it.

# Case class What makes it tricky Covered by
A Positive output (bright-on-right edge) sign of the sum is + Ex 1
B Negative output (bright-on-left edge) sign of the sum is Ex 2
C Zero output (flat region / no pattern) perfect cancellation → 0 Ex 3
D Padding changes the answer zeros bleed in at the border Ex 4
E Stride (which positions survive?) output positions are skipped Ex 5
F Degenerate filter: no spatial mixing at all Ex 6
G Multi-channel (RGB) sum-across-depth three products stacked into one Ex 7
H Limiting size: filter = whole image output collapses to Ex 8
I Word problem (real image, real filter) translate English → numbers Ex 9
J Exam twist: solve for an unknown stride/padding run the size formula backwards Ex 10

Two formulas we will reuse constantly — from the parent note, restated in words:

We use the same input throughout so you can compare cases. Here it is, with rows down and columns across:

Figure — Convolution operation and filters

Look at the figure: the red box is the filter's footprint. As we move it, the nine numbers under it change — that is the only thing that changes between Examples 1–3.


Example 1 — Cell A: a positive output (right side brighter)

Forecast: the filter's right column is and left column is . It fires positive when the right side of the patch is brighter than the left. Guess the sign before reading on.

  1. List the patch under the filter. Why this step? The formula only ever multiplies the filter by the numbers directly beneath it, so we must read them off first. Rows 0–2, columns 0–2:
  2. Multiply element-by-element with . Why? That is the "picture value filter value" inside the sum. The middle column is killed by , so only the outer columns matter:
  3. Add. Why? The single collapses nine products into one number:

Verify: each row contributes (right − left): , , ; total . Positive, as forecast — the right column of the patch () does outweigh the left (). ✓


Example 2 — Cell B: a negative output (left side brighter)

Forecast: now the patch's left column is the bright strip. A left-bright patch through a right-positive filter should give a negative number.

  1. Read the patch at rows 0–2, columns 2–4. Why? New position ⇒ new nine numbers:
  2. Apply (right − left) per row (middle column is ). Why? Same reasoning as Ex 1, just faster:

Verify: the sign is negative, matching the forecast. The magnitude is larger than Example 1's because the brightness drop from left to right is steeper here. ✓ (This is the entry of the full feature map.)


Example 3 — Cell C: a zero output (no edge, perfect cancellation)

Forecast: a flat region has no edge, so an edge detector should report exactly 0.

  1. Sum the filter weights first. Why this step? When every picture value equals a constant , the output is — the constant factors out. Sum of : each row is , so total .
  2. Multiply out. Why? Confirms the shortcut: .

Verify: directly, per row , three rows . A zero-sum filter is blind to flat brightness — it only sees change. That is why edge detectors have weights summing to zero. ✓


Example 4 — Cell D: padding changes the border answer

Forecast: padding surrounds the top-left corner with zeros, so the filter now sees mostly s. The corner answer should shrink toward a small number, not .

Figure — Convolution operation and filters
  1. Build the padded patch. Why? With the filter's top-left position sits over the zero ring; only the bottom-right of the filter overlaps real pixels. In the figure the gray ring is the padding, the red box is the filter:
  2. Multiply with . Why? Same formula; the zeros simply drop out: Wait — recompute carefully with 's middle-column-zero: row 1 gives ; row 2 gives . Sum .

Verify: the padded corner value is — coincidentally equal here, but now it is a border pixel of a larger output (padding preserves size). Compare Ex 1's which was an interior value of a output. Same number, different role. The key lesson: the zero ring participates in the sum, so border outputs are systematically dimmer wherever the filter would have seen bright pixels. ✓ See receptive fields for how this ring grows over layers.


Example 5 — Cell E: stride , which positions survive?

Forecast: stride 2 keeps every other starting column and row. From starts we drop the odd ones, keeping and → a output.

  1. Run the size formula. Why? It tells us how many positions fit before we compute any values: So output is .
  2. List the top-left corners of each filter placement. Why? Stride means the corner index jumps by 2: . The corners would push the filter off the edge, so the floor correctly excluded them.

Verify: four positions ⇒ , matching the formula. Contrast with stride 1 which gave positions (Ex 1's full map). Stride 2 roughly quarters the output — the downsampling the parent note promised. ✓


Example 6 — Cell F: the degenerate filter

Forecast: a filter cannot mix neighbours — it just rescales every pixel. Output should be times , same shape.

  1. Check the output size. Why? To confirm nothing shrinks: Output is , identical shape.
  2. Apply the formula. Why? With the double sum has just one term: . So , , etc.

Verify: every value doubles, no spatial change. This is why convolutions are used only to mix channels (see depthwise-separable convolutions), never spatial patterns. output . ✓


Example 7 — Cell G: multi-channel (RGB) — summing across depth

Forecast: for multi-channel input we multiply per channel then add the three channels together into one number: expect .

  1. Multiply each channel. Why this step? The 3D formula has an extra sum over channels ; each channel is a separate multiply:
  2. Sum across channels. Why? The output of one filter is a single number per location — depth collapses:

Verify: , as forecast. Note the output has depth 1 even though input had depth 3 — one filter always produces one feature map. Stack 64 filters ⇒ output depth 64, exactly the parent note's rule. ✓


Example 8 — Cell H: limiting case, filter = whole image

Forecast: the filter fits in exactly one position — the output must be a single number ().

  1. Size formula. Why? To see the collapse: Output .
  2. Interpret the single value. Why? With , the sum runs over all 25 pixels — it is a global weighted sum of the whole image. If were all-ones, this would be the total pixel sum. For above, all-ones filter gives .

Verify: total of : rows sum to , grand total . So an all-ones filter outputs the single value . This is the limiting behaviour: as image size, convolution degenerates into one global feature — which is what a global pooling layer approximates (pooling layers). ✓


Example 9 — Cell I: the word problem

Forecast: "same" size for a filter needs one ring of padding, ; output stays ; cost = (positions) (filter cells).

  1. Solve for padding. Why? "Same" means . Set the formula equal to :
  2. Output shape. Why? Plug back: . Output .
  3. Count operations. Why? Each of the output pixels needs one multiply-add per filter cell, and the filter has cells:

Verify: is exactly from the parent's padding rule ✓. ✓. Contrast a fully-connected layer on 36 pixels → weights: convolution is far cheaper, the parameter-sharing win from the parent note.


Example 10 — Cell J: the exam twist (solve backwards for stride)

Forecast: big input → small output means we skipped positions, so . Guess .

  1. Write the size formula and isolate . Why? We know everything except ; run the equation backwards:
  2. Solve the floor equation. Why? Subtract 1: . We need with landing in : , and . ✓ So .
  3. Reject nearby values. Why? Always check the floor didn't hide another answer. ; . Only works.

Verify: plug forward: . Matches. ✓ The floor is the subtle part — many students forget that still gives a valid whole-number output because we round down.


Recall Self-test before you leave

A edge filter on a flat gray patch outputs what? ::: Zero — its weights sum to zero, so it is blind to constant brightness. Input , , , : output size? ::: , so . Why does a filter never detect edges? ::: It covers a single pixel, so it cannot compare neighbours — it only rescales. Input , , , output : stride? ::: (since ). An all-ones filter over our input outputs? ::: The single number (the sum of all pixels).

Where to go next: stack these outputs and downsample in pooling, see how these filter weights are learned in backpropagation, and how whole trained stacks compose in CNN architectures.