What shape does it eat?
Move a handwritten digit one pixel to the right. The bright pixels now sit in different input slots, and it is still the same digit. How does a model reuse what it learned at one location somewhere else in the image? Take the local window calculation from loops to matrices and put it inside the training loop.
A convolutional neural network applies shared local filters over a grid. A channel is one aligned grid of input or feature values. A filter is a small array of weights that combines a local patch across those channels. Our input digits have one brightness channel, so a batch enters as (batch,1,8,8). The rows and columns are neighboring locations, and that adjacency is part of the model’s assumption.
The digit CNN’s first convolution makes four channels on the 8×8 grid. ReLU follows, then max pooling cuts the spatial grid to 4×4. The second convolution mixes those four input channels into eight output channels. Another ReLU and pool give (batch,8,2,2). Adaptive average pooling to (2,2) keeps that size here. Flatten the array into 32 ordered values per example, then a dense layer makes ten digit scores.
One rule visits every location
Weight sharing means reusing the same parameter at many positions. A filter doesn’t get a different rightmost weight when its window moves to the next column. That forces the network to use one local rule across the grid. A receptive field is the set of input locations that can influence a particular output. Later layers gather information from a wider area, because their inputs already summarize smaller neighborhoods.
Pooling summarizes neighboring responses into fewer entries. Max pooling keeps the largest value in a patch. It can preserve a strong response when that response moves inside the patch, and crossing a pooling boundary can change the answer. A stride is the distance between consecutive window positions; padding supplies values outside the original image so edge locations can take part in a chosen way.
Compute the filter cells
Our hand image has five identical rows: [0,1,2,1,0]. The kernel has three identical rows: [1,0,−1]. Use stride one, no padding, and zero bias. The output has three rows and three columns, because the 3×3 window fits in three positions along each input axis. These are hand-picked numbers, easy to multiply.
Two full filter cells
At the first output, the top patch row contributes 0×1+1×0+2×(−1)=−2. The next two rows give the same three products, so the output is −2−2−2=−6. Move one column right. Each row now contributes 1×1+2×0+1×(−1)=0, and the output is 0+0+0=0. Move right again: each row gives 2×1+1×0+0×(−1)=2, so the result is 6.
Every vertical placement meets the same row pattern, so the complete output has three identical rows [−6,0,6]. ReLU turns each into [0,0,6]. Call the image entries X, the kernel entries K, and the feature-map entries F. The indices i,j locate an output; a,b range over the kernel offsets:
$$F_{ij}=\sum_{a,b}K_{ab}X_{i+a,j+b}$$In words: multiply the patch by the shared filter entry by entry, then add the products; add the filter’s bias afterward if present.
A pooling cell
The 2×2 response patch [[0,6],[0,6]] becomes max(0,6,0,6)=6. Pooling chooses a value; it doesn’t multiply by a new learned row. Keep the raw filter result, the activated response, and the pooled result apart when you explain a prediction. A negative raw response can become zero at ReLU before any pooling happens. The widget shows the full product list, the preactivation, and the final activation for a selected output location.
Replay filters as the model trains
Training adjusts the filter entries and the dense head together. The labels grade the final digit probabilities; nothing tells an early filter to become a vertical edge detector. An early weight gets its gradient through all the operations in between. It is the same backward computation as before, applied to a different arrangement of shared parameters.
The run ends at step 3000 with training loss 0.0082, validation loss 0.13, and validation accuracy 96.1%. A good classification rate can sit beside a noticeable loss gap, because loss also measures how confidently the probabilities were assigned.
Where this shows up when you train
The final confusion matrix counts observed mistakes. Read its rows as true digit labels and its columns as chosen digit labels. Diagonal entries count correct predictions. The final correct counts for digits 0 to 9 are [58,58,57,58,59,58,59,58,52,57]. The row totals matter too, because a count on its own is not a per-class success rate.
An off-diagonal cell is a real error category from this validation split. Compare initial and final counts on the same scale and see which mistakes fell. Then inspect individual examples before you blame an error on a particular stroke, filter, or preprocessing choice.
Convolution fits images and other grids where local adjacency means something. It can be wrong for an ordinary table whose adjacent columns are unrelated measurements, where swapping columns shouldn’t create a spatial relationship. Choose the architecture because its sharing rule matches the data’s structure, then check the result on an appropriate split.
What you now know
- A convolution shares a local filter across a grid.
- Feature maps and pooling preserve or reduce spatial structure.
- A confusion matrix records specific errors that accuracy alone hides.
Where we’re headed
A sequence needs a shared rule too, and its next state also depends on the state it carries. Continue the story.