Convolution under the microscope
Convolution is a repeated local dot product whose shape and spatial behavior follow directly from kernel, padding, stride, and dilation.
A factory has few positive examples of costly visual defects.
This chapter moves from compute one window by hand to probe equivariance and borders. We will make the idea concrete in a small code example before placing it back inside a production system with one shift for inference and review.
Shift a simple pattern through the image and compare feature maps, paying special attention to padded boundaries and strided layers.
Verify the behavior illustrated in convolution_by_hand.py, then measure decision utility, slice reliability, and system latency.
Random burst-frame splitting puts near-duplicates of one product in train and validation. An unsafe release must degrade to a named baseline or the last known-good version.
Build the idea one layer at a time.
A convolution learns one small pattern and looks for it everywhere. Local connectivity and shared weights make images tractable while preserving where a detected feature appeared.
At each output position, a kernel multiplies a local input patch element by element and sums the result, optionally adding bias. Multiple input channels contribute to each output channel. Padding controls border context, stride controls sampling distance, and dilation spreads kernel taps without adding parameters.
Convolution is translation equivariant in its ideal interior: shifting the input shifts the feature map. It is not automatically invariant, and padding, downsampling, pooling, augmentation, and boundaries modify the behavior. Always calculate output shapes and test a hand-built kernel before trusting a deep stack.
- convolution
- receptive fields
- augmentation
- transfer learning
Follow the reasoning before touching the code.
- 01
Compute one window by hand
Multiply a 3×3 patch by an edge kernel and sum it so the operation has a concrete geometric meaning.
- 02
Account for spatial parameters
Use input size, kernel, padding, stride, and dilation to calculate the output dimensions before building downstream layers.
- 03
Probe equivariance and borders
Shift a simple pattern through the image and compare feature maps, paying special attention to padded boundaries and strided layers.
import numpy as np
image = np.array([[0, 0, 0, 1, 1],
[0, 0, 0, 1, 1],
[0, 0, 0, 1, 1],
[0, 0, 0, 1, 1],
[0, 0, 0, 1, 1]], dtype=float)
kernel = np.array([[-1, 0, 1], [-1, 0, 1], [-1, 0, 1]])
out = np.empty((3, 3))
for row in range(3):
for col in range(3):
out[row, col] = np.sum(image[row:row + 3, col:col + 3] * kernel)
print(out)Slide a vertical-edge kernel over a five-by-five image.
What to notice
- The strongest positive response appears where a dark patch transitions to a bright patch in the kernel’s left-to-right direction.
- With no padding and stride one, a 5×5 input and 3×3 kernel produce a 3×3 output.
YOUR TURN Pause and predict before revealing the answer.
Transpose the kernel. Which visual structure does it detect now?
Need a hint?
The negative and positive lobes move from left/right to top/bottom.
Check your reasoning
It becomes a horizontal-edge detector, responding to vertical changes in intensity rather than horizontal changes.
Lessons 1 in this course.
Connect the chapter to the course’s quantitative spine.
Convolution is a repeated local dot product whose shape and spatial behavior follow directly from kernel, padding, stride, and dilation. The convolution output size below is the shared course-level lens that helps quantify the surrounding system. Name each symbol, check its units or shape, and use only values that were available at the production cutoff.
Convolution output size
| Symbol | Meaning / shape / unit |
|---|---|
in, out | spatial input/output size |
k | kernel size |
s | stride |
p | padding |
d | dilation |
Open derivation and numerical substitution
Start from the production quantity being optimized, substitute the observed values with their declared units, then isolate the model-controlled term. Preserve shape annotations at each step so broadcasting or aggregation cannot silently change the result.
- Write the named inputs: in, out, k, s, p, d.
- Substitute one small, hand-checkable batch before vectorizing.
- Calculate an independent reference value and compare within a declared tolerance.
# equation → code contract
inputs = validate_shapes_and_units(batch)
value = compute_c10(inputs)
assert is_finite(value)Change one assumption and make the tradeoff visible.
Use the worked chapter as your prediction, then change one input in the lab and explain why the output moves. The lab runs predefined TypeScript and never executes learner code, so the focus stays on the concept rather than setup.
Receptive-field assembler
Stack kernels and see receptive field, parameter count, and output size.
Assumption: 3×3 stride-one convolutions, 32 channels, 64×64 input, no dilation.
Open nonvisual data table
| Item | Computed state | Interpretation |
|---|---|---|
| layer 1 | 3×3 | 62×62 |
| layer 2 | 5×5 | 60×60 |
| layer 3 | 7×7 | 58×58 |
| layer 4 | 9×9 | 56×56 |
Trace the complete operating path.
Carry the chapter’s central idea into the system: Convolution is a repeated local dot product whose shape and spatial behavior follow directly from kernel, padding, stride, and dilation. The path below shows where that reasoning needs an artifact, a test, an owner, or a fallback.
- 01
Turn “Compute one window by hand” into a written invariant and a failing test.
- 02
Promote convolution_by_hand.py from illustration to a versioned implementation with representative fixtures.
- 03
Use “Probe equivariance and borders” as the release checkpoint: Shift a simple pattern through the image and compare feature maps, paying special attention to padded boundaries and strided layers.
- 04
Serve or materialize behind explicit one shift for inference and review.
- 05
Join telemetry to mature outcomes and retain a rollback path.
Observability
Join service health, input quality, prediction distributions, slice behavior, and mature outcomes by exact version.
Cost
Measure storage, preprocessing, compute, queueing, and human review under a representative arrival pattern.
Failure modes
Random burst-frame splitting puts near-duplicates of one product in train and validation. Add a detector, owner, mitigation, and stop condition for this class of failure.
Alternatives
Compare a rule, a simpler statistical baseline, and a different system boundary before adding model complexity.
Explain the contract, not just the vocabulary.
Rare-defect vision system
Design grouped evaluation, transfer learning, calibration, batch-one export, and camera-drift monitoring.
- Grouped split and audit
- Transfer-learning ablations
- PR and calibration report
- Export/latency/monitoring
Read primary material with a purpose.
Return to the opening failure.
Version color, resize, orientation, normalization, class map, and threshold; monitor camera/site slices.
For this lesson, the release evidence is the worked code example, a hand-checked formal result, deterministic simulation output, a ≥80% checkpoint, the production rubric, and a named fallback. The course resolves when the system can produce cnn and transfer-learning baselines with augmentation, calibration, and monitoring.