Convolutional Networks
A convolutional network replaces the dense layer's all-to-all weight matrix with a small kernel slid across the input. Three structural commitments (sparse connectivity, parameter sharing, and translation equivariance) collapse the parameter count by orders of magnitude and bake the right prior for images directly into the architecture.
╌╌╌╌
A dense layer treats an image as a flat vector and connects every input pixel to every output unit. For a image that is inputs; a single dense layer of units carries weights, and learns nothing about the fact that a cat shifted three pixels right is still a cat. A convolutional network discards that wasteful matrix. It connects each output to a small local patch of the input and reuses one tiny set of weights, a kernel, at every position. The cat-detector learned at the top-left corner is, for free, a cat-detector everywhere.
The convolution operation
The discrete 2D convolution slides a kernel of size across an input and, at each position, takes the sum of element-wise products of the kernel with the underlying patch. Writing for the output position:
Each output value is one inner product between the kernel and a window of the input. The kernel is the layer's only learnable object; sliding it produces a feature map , one scalar per spatial position.1
The canonical picture: place the kernel over a patch, multiply, sum, write one cell of the feature map, then step over by the stride and repeat.
Channels
Real inputs are not flat grids but stacks of them: an RGB image is . A kernel spans all input channels, so a kernel for a - channel input has shape and produces a single feature map by summing over channels too:
A convolutional layer learns such kernels, stacking their feature maps into an output volume of depth . The layer's full weight tensor is — note it is independent of the input's spatial size .
For a worked shape trace, take an RGB input of
and a conv layer with kernels of size
, same
padding (), stride . Each kernel has shape
weights plus one bias, so the layer's weight tensor is
weights and biases, parameters
total. The output geometry from per spatial axis gives an output volume of . Every one
of those output scalars is an inner product over
input values, so the layer costs multiply-adds. The single fact to carry: the parameter
count does not mention or , so the same
weights process a image or a one; only the
compute scales with resolution.
Three ideas that beat the dense layer
Convolution wins for images because of three structural commitments, each cutting a different cost the dense layer pays.2
Sparse connectivity
A dense layer connects every output to every input: inputs and outputs cost weights and multiply-adds. A conv layer connects each output only to a patch, so each output unit has just incoming weights regardless of input size.
Parameter sharing
The deeper saving is parameter reuse: the conv layer uses the same weights at every position. The dense layer learns an independent weight for every (input, output) pair; the conv layer learns one kernel and applies it everywhere. The weights are tied across space.
One kernel slides across the input and writes each feature-map cell. Every output position is computed by the same three weights; the network stores one filter, not one weight per location.
Take a input mapped to a output, comparing a dense layer to a conv:
| Quantity | Dense layer | Conv layer () |
|---|---|---|
| Inputs | ||
| Outputs | ||
| Weights | ||
| Weights scale with input size? | yes () | no (fixed at ) |
| Multiply-adds |
The conv layer carries weights against the dense layer's million, a reduction, and the gap widens with input size, since the dense count grows as while the kernel stays fixed at .
Translation equivariance
Parameter sharing gives a structural property for free: shifting the input shifts the output the same way. Let be a translation by pixels. Then
so detecting a feature and shifting commute. The kernel responds identically to a pattern no matter where it sits — exactly the right prior for images, where an object's identity is independent of its position.3
Equivariance is not invariance: the output moves with the input. Pooling, below, converts a small amount of this equivariance into outright invariance.
Convolution arithmetic
The kernel cannot be centered on the boundary pixels, so a valid convolution shrinks the output. Two knobs control the output geometry: the stride (how far the kernel hops between positions) and the padding (how many zero rows and columns ring the input).
Deriving the output size
Consider one spatial dimension of size , padded to . A kernel of width has its leftmost valid position at index and its rightmost when its right edge hits the padded boundary, i.e. at start index . Stepping by , the valid start positions are up to , so their count is
The floor handles a final partial step that does not fit; the counts the starting position itself. Several special cases recover familiar layers:
| Configuration | Output size | Effect | ||
|---|---|---|---|---|
| Valid (no pad) | shrinks by | |||
| Same (preserve size) | output matches input | |||
| Strided downsample | halves resolution | |||
| No pad, stride | shrink + downsample |
A worked instance: , , , gives .
Pooling
A pooling layer summarizes each small region of a feature map by a single statistic (its maximum for max pooling, or mean for average pooling) over a window, typically with stride equal to the window so the regions tile without overlap. Pooling has no learnable weights; it exists to downsample and to add local invariance.4
The invariance is the point. If the strongest activation shifts by one position but stays inside the same pooling window, the max is unchanged — the output is locally invariant to small translations, not merely equivariant. Max pooling keeps the strongest evidence; average pooling keeps the typical level.
| Property | Max pooling | Average pooling |
|---|---|---|
| Statistic | over window | mean over window |
| Keeps | strongest activation | overall level |
| Gradient | flows to the argmax only | spread evenly |
| Best for | sharp feature presence | smooth global context |
The receptive field
The receptive field of a unit is the region of the original input that can influence it. A single conv sees a patch; stack another on top and each of its units sees a patch of the layer below, which already each saw of the input, so the second layer's units see of the input. The field grows linearly with depth for stride- convs.
Stride and pooling accelerate the growth: a stride- layer multiplies the
spacing, so receptive fields expand geometrically rather than linearly once
downsampling is interleaved. This is why deep stacks of small convs
can, with a few pooling steps, end up seeing
the entire image — the late layers
have receptive fields spanning the input, which is what lets them represent whole
objects.
The convolution algorithm
The forward pass of a single convolutional layer is a direct transcription of the definition: for each output channel, slide that channel's kernel over the padded input, summing products across the window and the input channels.
- 1pad with zeros on each side
- 2
- 3
- 4for each output channel to do
- 5for to do
- 6for to do
- 7accumulator for cell
- 8for each input channel , offset do
- 9
- 10add per-channel bias
- 11return
The five nested loops make the cost explicit: multiply-adds. Optimized implementations recast the inner
loops as a single matrix multiply (im2col
), but the arithmetic is unchanged.5
A typical convolutional stack
A convolutional network alternates convolution, a nonlinear activation, and pooling, each block shrinking spatial size while growing channel depth, then flattens and hands off to a dense classifier head.6
The geometry follows a consistent pattern: each conv block enlarges receptive fields and adds channels (more pattern detectors), while pooling discards spatial resolution that is no longer needed. By the flatten, each unit summarizes a large region through a deep feature, and a small dense head suffices to read off the class.
| Stage | Spatial size | Channels | Role |
|---|---|---|---|
| input | raw pixels | ||
| conv + ReLU | local feature detectors | ||
| pool | downsample, local invariance | ||
| conv + ReLU | compose into richer features | ||
| pool | downsample again | ||
| flatten + dense | classes | global readout |
A worked shape and parameter trace
Instantiate the stack with real numbers on a input, two
conv-pool blocks with same
-padded convs (, ) and
stride- pooling, then a dense head to classes. Following one
tensor through, with the parameter count at each conv:
| Layer | Output shape | Parameters |
|---|---|---|
| input | ||
| conv , | ||
| max pool | ||
| conv , | ||
| max pool | ||
| flatten | ||
| dense |
Two observations fall out of the numbers. First, spatial size halves at every pool () while depth grows (): the network trades resolution for richer per-position features. Second, the convolutional feature extractor holds parameters against the dense head's — most of the weights live in that final flatten-to-dense step, which is exactly why the flatten happens only after pooling has shrunk the map to ; flattening the map straight after the first conv would feed features into the dense layer and inflate that head by a factor of eight.
Convolution variants in production
Goodfellow, Chollet, and Stevens stop at the standard dense convolution; two variants that reshape the cost and the receptive field are now everywhere in production vision models.
- Depthwise-separable convolution. A standard layer with input and output channels costs multiply-adds per output position. Split it into a depthwise step (one filter per input channel, no channel mixing) followed by a pointwise step (mixing channels, no spatial extent), and the cost drops to . For a layer with , that is versus , an reduction, with almost no accuracy loss. This factorization underlies MobileNet (Howard et al., 2017) and Xception (Chollet, 2017), the standard for on-device vision.
- Dilated (atrous) convolution. Insert gaps of size between kernel taps,
so a kernel covers a span while touching only
weights. The receptive field then grows exponentially with depth if doubles
each layer, instead of the linear derived above, which
is why dilation dominates dense-prediction tasks like segmentation (Yu & Koltun,
Multi-Scale Context Aggregation by Dilated Convolutions,
ICLR 2016) and audio generation (WaveNet, van den Oord et al., 2016).
The Vision Transformer drops this same locality prior that the three ideas encode, trading the built-in bias for data; the convolution and the attention block are two ends of one design axis.
Takeaways
- A convolution slides a small learnable kernel over the input; each kernel yields one feature map, and a layer stacks of them across input channels.
- Three commitments beat the dense layer: sparse connectivity (each output sees only a patch), parameter sharing (one kernel reused everywhere), and translation equivariance () — together collapsing a million weights to nine for a kernel.
- Output geometry obeys ;
same
padding with preserves size, stride downsamples. - Pooling (max or average) is parameter-free downsampling that turns local equivariance into local invariance; the receptive field grows as with depth, so deep stacks eventually see the whole image.
- The canonical stack — conv → activation → pool → … → flatten → dense — deepens channels while shrinking space, trained end-to-end, and is the backbone the next lesson's architectures refine.
Footnotes
- Goodfellow, Deep Learning, §9.1 — The Convolution Operation: the discrete cross-correlation a
convolution
layer actually computes, and the feature map it produces. ↩ - Goodfellow, Deep Learning, §9.2 — Motivation: sparse interactions, parameter sharing, and equivariant representations as the three levers convolution pulls against the dense layer. ↩
- Goodfellow, Deep Learning, §9.2 — Equivariance to translation: why shared kernels commute with shifts, and why this is equivariance rather than invariance. ↩
- Goodfellow, Deep Learning, §9.3 — Pooling: max/average pooling as parameter-free downsampling that buys approximate invariance to small translations. ↩
- Stevens, Deep Learning with PyTorch, Ch. 8 — Using Convolutions to Generalize: the
Conv2dforward pass, padding/stride arithmetic, and channel bookkeeping in practice. ↩ - Chollet, Deep Learning with Python, Ch. 5 — Deep Learning for Computer Vision: the canonical conv → ReLU → pool → flatten → dense convnet and why it dominates image tasks. ↩
╌╌ END ╌╌