Visual explainer
Convolution Operation
Trace a shared kernel through a checked numerical image, then inspect stride, padding, input-channel sums and the limits of shift correspondence.
A convolutional layer reuses a local kernel at many spatial positions. At each position it multiplies matching input and kernel entries and sums them to produce one output. Weight sharing differs from choosing an independent weight for every input position.
The opening one-dimensional example uses fixed weights . Input A scores 1; shifting its nonzero value two places gives B , which scores 0. The middle row shows the weights, and the dashed column selects the only nonzero coefficient. This is a particular position-dependent detector, not a claim that every dense model must fail after a shift.
Specify The Kernel
Our two-dimensional kernel has three identical rows . It keeps each left-column value, ignores the middle and flips the sign on the right before summing. This measures a left-versus-right contrast over three rows; reversing the contrast reverses the response sign. The nine coefficients are shared at every valid position.
The operation used by common neural-network layers is technically cross-correlation, because the kernel is not spatially flipped. PyTorch Conv2d documents that convention. Here bias is zero, stride is one, dilation is one and there is no padding unless explicitly changed below.
Compute One Output
The first patch has rows , and . Multiplication by the kernel gives left contribution , middle contribution zero and right contribution . The signed arrows share a length scale: move four units right, then three left, ending at output 1. Their vertical separation is for readability, not another variable.
This is a dot product of nine matching entries. A filter can learn other coefficients during training; the chosen contrast kernel is an illustrative fixture, not a universal learned edge detector.
Fill The Feature Map
Use this complete synthetic input, with image row indices increasing downward:
There are valid origins along each axis. Evaluating all nine windows gives output rows , and , exactly as drawn. The input grid is a spatial overview of this matrix; its selected top-left window is the numerical patch from the previous scene. The upper connector maps that window to output . A feature map preserves where responses occur; it is not one position-invariant class prediction.
Reuse The Same Coefficients
For this controlled comparison, place two identical copies of the first patch at origins and in a separate image. Their nine displayed values match, so the same kernel and bias return 1 at both locations. This comparison changes the surrounding image from the earlier fixture explicitly; it is not claiming those two origins both exist in the valid output of the earlier input.
Sharing reuses nine coefficients rather than learning a new kernel for every location. Equal responses by themselves do not prove two patches are identical: different patches can have the same dot product. Translation equivariance means responses move with inputs under the appropriate sampling and boundary conditions; it is different from discarding position entirely.
Sample Different Origins
Return to the primary input. The dots are window-origin coordinates, not output pixel areas. Stride one uses row and column origins 0, 1 and 2. Stride two uses only 0 and 2; both diagrams keep the same origin spacing. The output becomes , with rows and selected from the earlier feature map. Stride changes where the kernel is evaluated, not its size or weights.
For each axis, output size is , where is input size, padding, dilation, kernel size and stride. These examples use .
Trace A Receptive Field
Change only the primary input's bottom-right entry from 1 to 9. It lies outside the first window, so output remains 1. Among these valid windows, only the bottom-right output contains that input pixel. Its kernel coefficient is −1, so increasing the pixel by 8 changes that output from −1 to −9. The complete edited output is drawn.
One local response cannot inspect pixels outside its receptive field. Later processing can combine wider context, but a single local kernel does not identify an entire object merely because it responds to a local contrast.
Include Padded Border Values
Restore the original input and add one zero around every edge. The first padded window contains rows , and . The dashed L-shaped outline identifies the padding entries. Left contribution is zero, right sum is , and the output is −3. This is a different window alignment from the earlier valid top-left output of 1.
At stride one and dilation one, this padding yields a output. Keeping the dimensions does not preserve all input information: weighted sums can discard distinctions, and the boundary response depends on the chosen padding rule.
Sum Across Input Channels
Now use two input channels at one spatial position. Channel 1 is the first numerical patch with the earlier contrast kernel, contributing 1. Channel 2 has a patch of nine ones and a kernel of nine ones, contributing 9. Adding the output channel's bias .5 gives . The three separate ports distinguish channel contributions from the bias.
With ordinary groups-one convolution, one output channel uses a kernel spanning all input channels. For two channels and a spatial kernel, that is 18 weights plus one bias for this output channel. Another output channel has its own coefficients and produces another feature map; input-channel slices are not automatically separate output channels.
Where It Breaks
This final, explicitly one-dimensional counterexample isolates sampling phase. Use unflipped kernel , zero bias, valid windows and stride two. Input produces . Shift it right one position to and the sampled output becomes : the response disappears instead of becoming a translated copy.
At stride one, the corresponding responses are and . Stride two samples only origins 0 and 2, missing the shifted response at origin 1. Weight sharing alone therefore does not guarantee robustness to arbitrary shifts. Stride, padding and finite boundaries qualify equivariance, and a later classifier can introduce additional sensitivity to position.
The Quick Version
- Each local output is a weighted sum of matching entries.
- Shared coefficients reuse the same operation across positions.
- Stride selects window origins; padding supplies boundary values.
- Each output has a specific receptive field.
- Input-channel contributions add before the output channel's bias.
- Sampling can break simple shift correspondence despite shared weights.