5.6.11 · D4Machine Learning (Aerospace Applications)

Exercises — Convolutional neural networks — convolution operation, pooling

2,441 words11 min readBack to topic

The two workhorse formulas we will lean on all page:


Level 1 — Recognition

Problem 1.1

Which of the following operations has zero learnable parameters? (a) a convolution, (b) max-pooling, (c) a fully-connected layer, (d) the bias term.

Recall Solution 1.1

Answer: (b) max-pooling. What we did: recalled that pooling is a fixed function — it computes a max (or average) over a window and there is nothing to train inside it. A convolution has trainable numbers per filter; a fully-connected layer has one weight per input–output pair; the bias term is a parameter. Only pooling learns nothing.

Problem 1.2

State, from memory, the output-size formula and name each of its four inputs.

Recall Solution 1.2

= input width, = kernel size, = padding, = stride. Mnemonic (parent note): "I-Kicked-2-Pads-per-Stride-plus-one."

Problem 1.3

Input width , kernel , padding , stride . Compute .

Recall Solution 1.3

What it looks like: a -wide kernel can start at columns — that's 5 positions, so 5 outputs. The chops off the room the kernel body needs; the puts back the very first position (column 0), which the subtraction never counted.


Level 2 — Application

Problem 2.1

Input , kernel , padding , stride . Find and say in words what this padding choice achieves.

Recall Solution 2.1

Why this padding: with we added two zero-rings, exactly enough to cancel the shrink for a kernel at stride 1 (). This is "same" padding — output size equals input size. Useful when you want to stack many conv layers without the map vanishing.

Problem 2.2

Compute the full output of convolving with stride 1, no padding.

Recall Solution 2.2

Output size: , so a map. Overlay on each window and sum element-wise products (cross-correlation, parent §1).

  • What it looks like: this kernel fires positively when the two diagonal pixels are large and the two anti-diagonal pixels are small — a checkerboard / corner detector.

Problem 2.3

Max-pool the map below with a window, stride 2. Then average-pool it.

Recall Solution 2.3

Stride 2 with a window ⇒ non-overlapping blocks. Output , a map. Max-pool (keep the loudest in each block):

  • TL , TR
  • BL , BR Average-pool (mean of each block):
  • TL , TR
  • BL , BR

Level 3 — Analysis

Problem 3.1

A conv layer takes a image with channels, uses filters of size . How many learnable parameters? Now the image becomes — how many parameters now? Explain the result.

Recall Solution 3.1

For the image: still 1792. The formula contains no . Why: the same kernel is slid over the whole image (weight sharing), so making the image bigger just means more slides, not more weights. This size-independence is the defining advantage of convolution over a fully-connected layer.

Problem 3.2

Take the map (values are activations). Shift the "8" one cell left to get . Apply a single max-pool to each. What do you observe, and what property does this demonstrate?

Recall Solution 3.2

and . Both pool to the same value 8. What this shows: local translation invariance — the feature (the strong activation "8") moved by one pixel, yet the pooled output did not change. Max-pooling reports "the feature is present in this window" without caring exactly where in the window. See the figure.

Problem 3.3

You stack two stride-1 conv layers (no padding). A single neuron in the second layer's output — how many input pixels does it ultimately depend on (its receptive field width)?

Recall Solution 3.3

One conv gives a neuron a receptive field of width 3. Feeding that into a second conv: the second neuron combines 3 first-layer neurons, and those 3 neighbours cover input columns — together columns through , i.e. width 5. General rule for stacked stride-1 conv: receptive field grows by per layer, so after two layers it is . Two small kernels see as far as one kernel, with fewer parameters — that's why deep stacks of small kernels are preferred.


Level 4 — Synthesis

Problem 4.1 — trace a small pipeline

An aerospace crack-inspection net receives a grayscale patch (). It applies:

  1. Conv: , , ,
  2. Max-pool: ,
  3. Conv: , , ,
  4. Max-pool: ,

Give the spatial size and channel count after each stage, and the total conv parameters.

Recall Solution 4.1

Track . Start: .

  • Stage 1 conv ( = "same"): . → .
  • Stage 2 pool (): . → .
  • Stage 3 conv (same padding): .
  • Stage 4 pool: . → .

Parameters (pooling has none):

  • Conv 1:
  • Conv 3:
  • Total .

Why "same"-padding matters here: it lets the conv layers keep the spatial size fixed, so all the shrinking is done by pooling in a controlled, predictable pattern — easy to reason about.

Problem 4.2 — build the equivalent FC count for contrast

For Stage 1 above, how many weights would a fully-connected layer need to map every input pixel to every output unit (ignore bias)? Compare to the conv's 160.

Recall Solution 4.2

Input has units. Output has units. Fully-connected weights . Conv used 160. Ratio — the conv is over a million times leaner. Why: locality (each output only touches a neighbourhood) + weight sharing (one kernel reused everywhere) together collapse that quarter-billion matrix into 160 numbers. This is the parent's "convolution is a constrained fully-connected layer" made concrete.


Level 5 — Mastery

Problem 5.1 — hit a target output size

You must design one conv layer that takes a input and produces a output using a kernel. Choose padding and stride , and prove it works.

Recall Solution 5.1

Try stride (to roughly halve). Solve for that gives exactly 112: We need . Check with : Answer: . Why stride 2, not padding tricks: halving is fundamentally a stride job (stride sets the rate of down-sampling); padding then fine-tunes the edge so the floor lands exactly on 112.

Problem 5.2 — defend max vs average for a crack detector

For classifying whether a composite panel image contains a crack (yes/no), argue which pooling — max or average — better preserves the decisive signal, and give the failure mode of the wrong one.

Recall Solution 5.2

Choose max-pooling. A crack is a sparse, high-contrast feature: a thin bright line covering a tiny fraction of the panel. A conv filter tuned to that line produces one or a few large activations surrounded by near-zero background.

  • Max-pool keeps that large activation intact — it answers "did the crack feature appear at all in this window?", which is exactly the yes/no question.
  • Average-pool divides the strong activation by the whole window's cell count, drowning a single hot pixel in a sea of zeros. A real crack could be averaged down below the decision threshold — a missed defect, the worst error in inspection. When average wins instead: tasks about overall magnitude / texture (e.g. estimating mean surface roughness), where the smoothing is a feature, not a bug.

Problem 5.3 — the flip question, defended

A colleague hand-codes the Sobel edge kernel from a signal-processing textbook and drops it into a Conv2d layer, expecting mathematically exact convolution. Where might results differ, and does it matter for a learned network?

Recall Solution 5.3

Conv2d computes cross-correlation (no kernel flip), while the textbook's true convolution flips the kernel by 180° first (parent §1). For a hand-designed asymmetric kernel like Sobel, cross-correlation applies the mirrored filter — the detected edge orientation can invert. Fix for hand-coded kernels: pre-flip the kernel (rotate 180°) before loading it. For a learned network: it does not matter at all — gradient descent simply learns whichever orientation of weights minimizes loss, i.e. it learns the flipped values automatically. The flip is only a concern when you inject a fixed, meaningful kernel.


Recall One-line self-check before you leave

Cover the answers: ::: Params of a conv layer ::: , image-size independent Pooling params ::: zero Best pool for sparse crack signal ::: max

Connections

  • Parent topic
  • Padding and stride — the and every L2–L5 problem tuned.
  • Feature maps and receptive fields — the receptive-field growth in Problem 3.3.
  • Translation equivariance vs invariance — the pooling-invariance demo in Problem 3.2.
  • Image classification for aerospace inspection — the crack-detector design in L4/L5.
  • Fully-connected neural networks — the -weight contrast in Problem 4.2.
  • Backpropagation — how the 4800 learnable params of Problem 4.1 actually get trained.