Skip to content
AI360XpertBeta
Core ML

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.

Position-specific weights can respond differently after an input shift.
Position-specific weights can respond differently after an input shift.

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 (1,0,0,0,0)(1,0,0,0,0). Input A (1,0,0,0,0)(1,0,0,0,0) scores 1; shifting its nonzero value two places gives B (0,0,1,0,0)(0,0,1,0,0), 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

A kernel assigns a local weight to each patch position.
A kernel assigns a local weight to each patch position.

Our two-dimensional kernel has three identical rows (1,0,−1)(1,0,-1). 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 contributes four minus three to output one.
The first patch contributes four minus three to output one.

The first patch has rows (1,2,0)(1,2,0), (3,1,2)(3,1,2) and (0,2,1)(0,2,1). Multiplication by the kernel gives left contribution 1+3+0=41+3+0=4, middle contribution zero and right contribution −(0+2+1)=−3-(0+2+1)=-3. 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

Nine valid windows fill a three-by-three feature map.
Nine valid windows fill a three-by-three feature map.

Use this complete synthetic input, with image row indices increasing downward:

X=[1201031201021302010213021].X=\begin{bmatrix} 1&2&0&1&0\\ 3&1&2&0&1\\ 0&2&1&3&0\\ 2&0&1&0&2\\ 1&3&0&2&1 \end{bmatrix}.

There are 5−3+1=35-3+1=3 valid origins along each axis. Evaluating all nine windows gives output rows (1,1,2)(1,1,2), (1,0,1)(1,0,1) and (1,0,−1)(1,0,-1), 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 (0,0)=1(0,0)=1. A feature map preserves where responses occur; it is not one position-invariant class prediction.

Reuse The Same Coefficients

The same kernel gives the same result on identical patches.
The same kernel gives the same result on identical patches.

For this controlled comparison, place two identical copies of the first patch at origins (0,0)(0,0) and (3,3)(3,3) in a separate 6×66\times6 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 5×55\times5 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

Stride two samples fewer window origins.
Stride two samples fewer window origins.

Return to the primary 5×55\times5 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 2×22\times2, with rows (1,2)(1,2) and (1,−1)(1,-1) selected from the earlier feature map. Stride changes where the kernel is evaluated, not its size or weights.

For each axis, output size is ⌊(W+2P−D(K−1)−1)/S⌋+1\lfloor(W+2P-D(K-1)-1)/S\rfloor+1, where WW is input size, PP padding, DD dilation, KK kernel size and SS stride. These examples use D=1D=1.

Trace A Receptive Field

One output depends only on its receptive field.
One output depends only on its receptive field.

Change only the primary input's bottom-right entry from 1 to 9. It lies outside the first 3×33\times3 window, so output (0,0)(0,0) 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

Zero padding changes which values the border window sees.
Zero padding changes which values the border window sees.

Restore the original input and add one zero around every edge. The first padded window contains rows (0,0,0)(0,0,0), (0,1,2)(0,1,2) and (0,3,1)(0,3,1). The dashed L-shaped outline identifies the padding entries. Left contribution is zero, right sum is 0+2+1=30+2+1=3, 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 5×55\times5 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

One output adds contributions across input channels and a bias.
One output adds contributions across input channels and a bias.

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 1+9+.5=10.51+9+.5=10.5. 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 3×33\times3 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

A one-pixel shift can disappear under stride-two sampling.
A one-pixel shift can disappear under stride-two sampling.

This final, explicitly one-dimensional counterexample isolates sampling phase. Use unflipped kernel (1,0,−1)(1,0,-1), zero bias, valid windows and stride two. Input (1,0,0,0,0)(1,0,0,0,0) produces (1,0)(1,0). Shift it right one position to (0,1,0,0,0)(0,1,0,0,0) and the sampled output becomes (0,0)(0,0): the response disappears instead of becoming a translated copy.

At stride one, the corresponding responses are (1,0,0)(1,0,0) and (0,1,0)(0,1,0). 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.