Convolution
Cross-correlation, filters, padding and stride, receptive field, weight sharing, shapes and FLOPs of a conv layer — the layer that made vision workable.
Why convolution
The topic Optimizing deep networks closed the training loop: a stable loss, normalization, and an optimizer that takes useful steps. Every network there was fully connected and read an image as a flat vector of pixels. That works for tiny digits and collapses for photographs. This topic introduces the layer that replaced it in vision: the convolution, which looks at small neighbourhoods and uses the same weights at every position.
A fully connected layer on a colour image that maps to a feature map needs about weights — roughly two terabytes in float32. It also has a separate weight for every pixel, so an edge detector learned in one corner says nothing about an edge in the centre, and permuting all pixels the same way would leave training equally easy. Images have the opposite structure: what matters is local, and a cat is a cat wherever it stands.
A convolution is that dense layer with two constraints. Each output looks only at a small window (locality), and every window is processed with the same weights (weight sharing). Locality cuts the parameters from the size of the image to the size of the window; sharing makes the layer translation-equivariant: a pattern is detected wherever it appears.
Convolution as cross-correlation
For one input channel, one output channel and stride 1, a layer with kernel and bias computes
wherever the window fits, so the output is . Strictly this is a cross-correlation: a true convolution flips the kernel. The two differ only by that flip, and since the kernel is learned, libraries compute the cross-correlation and call it a convolution.
Worked example. A input whose right half is brighter, and a kernel with columns :
The top-left output is ; sliding gives , then and . All four are positive: every window is darker on the left than on the right. Flattened, is still a linear map — a sparse matrix whose rows share the same nine entries of . Everything said about linear layers in Backpropagation still applies; the gradient w.r.t. sums the contributions of all positions that share it.
Channels, parameters and FLOPs
A colour image has three channels; a hidden map has dozens or hundreds. Output channel uses a filter and adds a bias :
The weight tensor is . The layer has parameters — independent of image size — and costs multiply-adds, which papers usually call FLOPs.
The first layer of a ResNet for images is a convolution from 3 to 64 channels with stride 2 and padding 3, no bias (BatchNorm follows). It has weights and about multiply-adds on a map — roughly 3% of ResNet-50. A convolution from the same input to has parameters, against for the dense baseline.
Padding, stride and dilation
Three hyperparameters change which inputs each output reads; none of them changes the number of weights.
- Padding adds zero rows and columns on every side. For odd and stride 1, keeps the side (“same” padding).
- Stride moves the window by pixels. Stride 2 halves resolution and cuts cost by about 4.
- Dilation spreads the taps: a kernel with covers with nine weights.
With all three,
(and the same for ). The ResNet stem: . When does not divide the numerator, the floor drops the last rows: they are never read.
The receptive field
The receptive field of a unit is the set of input pixels that can affect it. One layer sees ; a second on top sees . With kernel sizes , strides and dilations ,
where is the jump: the distance in input pixels between neighbouring units of layer .
With stride 1 throughout, : five layers see . Alternating stride 2 grows the field much faster. Doubling dilations at stride 1 gives with no loss of resolution — the context module used in segmentation. The theoretical field is an upper bound: in a trained net the effective field is concentrated near the centre (Luo et al., 2016).
Pooling and equivariance
Pooling summarizes each window of every channel with no weights. Max or average pooling with halves height and width. Max pooling passes the backward gradient only to the argmax; average pooling spreads it evenly. Global average pooling turns into a length- vector and makes a classifier accept any input size.
Write for a shift by pixels. A map is equivariant if and invariant if . A stride-1 convolution (circular padding, or away from borders with zero padding) is equivariant; a stack of such layers stays so. Stride and pooling break exact equivariance for shifts that are not multiples of the stride. Global pooling of an equivariant map is invariant. Equivariance does not extend to rotations or rescalings — those come from data and augmentation.
1×1 and transposed convolution
With the layer becomes a linear map at every pixel: the (pointwise) convolution. From 256 to 64 channels it costs weights and as many multiply-adds per pixel — a ninth of a between the same channels. The next topic uses it as a bottleneck before expensive branches and after depthwise filters.
Transposed convolution implements the adjoint of a convolution: each input paints a copy of the kernel onto a larger map, copies pixels apart. It is not an inverse. When is not a multiple of , copies overlap unevenly and even a constant input yields a checkerboard (Odena, Dumoulin and Olah, 2016). A common remedy is fixed upsampling followed by an ordinary convolution.
One layer’s shapes, cost and field of view are now in place. What remains open is how to stack them: deeper stacks see more, but plain depth stops training well past a point. The next topic, Convolutional architectures, follows the designs that answered that — from VGG’s stacks through Inception and ResNet to MobileNet-style blocks.
Check your understanding
The same questions as in Pulse. Answers are shared between modes.
Go deeper — optional
Code and labs do not count toward the main percentage or the certificate.
- Convolution output size and parametersoptional
H′ formula and NumPy cross-correlation on the topic example; ResNet stem parameter count. Self-check in the notebook.
~20 min · easier on a computer · The Convolution topic read.
Self-check in the notebook — not part of mastery or the certificate.
Answers are saved on the server and tied to this browser until you sign in.