Convolution and inductive bias
Derive convolution shapes and costs while separating locality, weight sharing, and translation behavior.
On this page
The question for today
What you’ll understand
- Compute output dimensions with stride, padding, and dilation.
- Count convolution parameters and multiply-accumulate operations.
- Explain when translation equivariance survives an implementation choice.
An image is an array with spatial structure, not merely a long vector. Convolution commits an architecture to local interactions and repeated use of the same weights at different locations. This is an inductive bias: some relationships become easy to express while others require more layers or larger receptive fields. Understanding the bias lets you decide whether a convolution suits a task, rather than assuming that fewer parameters automatically imply a better model.
A shared local linear operator
For an input shaped B by C_in by H by W, a dense two-dimensional convolution has weights shaped C_out by C_in by K_h by K_w. At each output location it multiplies a local patch by the same filter bank and sums over input channels and kernel positions. Most deep learning APIs implement cross-correlation without reversing the kernel, although the layer is called convolution. The learned parameter count is unaffected by the image width and height; the amount of computation is not.
Locality says each output initially sees a small neighborhood. Weight sharing says the detector is reused spatially. On an infinite grid, stride-one shared filtering commutes with integer translation. Finite boundaries, padding choices, striding, and subsequent pooling qualify that statement. A classifier can become approximately invariant to position through aggregation and training, but a convolutional feature map is generally equivariant rather than invariant: translating an input translates its internal response instead of leaving every response unchanged.
Receptive field and cost are different quantities
Stacked stride-one three-by-three layers enlarge the theoretical receptive field by two pixels per axis per layer. Nonlinearities between layers add representational capacity. The effective influence learned from data can be concentrated in a smaller region, so the theoretical receptive field is only a connectivity bound. Dilation expands spacing between sampled positions without increasing the number of filter coefficients. It can also create sampling artifacts that dense connectivity would not produce.
A standard convolution performs one dot product of length C_in times K_h times K_w for each output channel and spatial position. Count multiply-accumulate operations explicitly because FLOP conventions differ: one multiply plus one add is often counted as two floating-point operations. Depthwise convolution filters each channel separately; a following pointwise layer mixes channels. This changes both capacity and arithmetic. Lower arithmetic does not ensure lower latency when memory traffic, small kernels, or hardware utilization dominate.
Choose a bias that matches the data
Local shared patterns are useful for many images and time signals, but they are assumptions. A task depending on distant interactions may need depth, dilation, global pooling, or another mixing mechanism. A coordinate-dependent sensor calibration may require position information because complete weight sharing alone cannot express arbitrary location-specific rules. On irregular graphs, neighboring array indices may not correspond to meaningful physical neighbors at all. Start by stating what a one-step neighborhood means.
When comparing a convolutional model with a token mixer, align input resolution, augmentation, training examples, and compute budgets. Report memory at the intended batch size and measure the deployed kernel implementation. Strided downsampling can alias high-frequency content; anti-aliasing or different sampling choices alter behavior, rather than simply improving every model. Use controlled translations and boundary cases to test the invariance you actually need, including whether a one-pixel shift changes a safety-relevant prediction.
Work it through
Audit a convolution layer
Use one 32×32 RGB image, eight output channels, a 3×3 kernel, padding one, stride two, and dilation one. Include a bias per output channel.
The spatial formula gives floor((32+2−2−1)/2)+1=16 on both axes, so output shape is 1×8×16×16.
Weights number 8×3×3×3=216. Eight biases raise the trainable parameter count to 224.
Each of 8×16×16 outputs uses 27 multiply-accumulates, giving 55,296 MACs. Counting each multiplication and addition separately gives roughly 110,592 arithmetic FLOPs before biases.
Spatial downsampling reduces output sites, while sharing keeps the weight count independent of the input resolution.
The living notebook
Explore the model
Interactive lab · spectral
Inspect spatial frequency before sampling
The lab plots a finite sine sum Σ sin(nx−t)/nᵖ with mode count N and decay p. Higher modes expose finer spatial variation that downsampling can lose. This is a frequency illustration, not an image convolution, anti-alias filter, or learned receptive-field simulator.
- Sum at x = π/2
- 0.867
- Smallest wavelength
- 2π / 5
- Highest-mode coefficient
- 0.2
A finite sum of sin(nx − t)/nᵖ. Playback changes t; increasing the cutoff includes finer spatial scales. This is not a proof about a continuum limit or renormalization. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forInput spatial scale matters when a layer discards positions; a smaller output shape alone says nothing about which information survived.
Pause & reason
Check your understanding
Your turn
Try it yourself
Compare weights for a 3×3 dense convolution from 32 to 64 channels against depthwise 3×3 followed by pointwise 1×1 from 32 to 64. Ignore biases.
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
A depthwise filter has one 3×3 kernel per input channel; pointwise mixing has one coefficient per input-output channel pair.
Compare with the solution
Dense weights total 3×3×32×64=18,432. Depthwise weights total 3×3×32=288; pointwise weights total 32×64=2,048. The combined total is 2,336, about 12.7% of the dense count. This factorization restricts the operator family and does not guarantee the same accuracy or measured latency.
Keep the idea
Take it with you
- Shared local weights impose a useful but task-dependent spatial assumption.
- Equivariance has boundary and sampling qualifications.
- Parameter count, arithmetic, activation memory, and latency are separate measurements.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.