This Machine Learning concept is the current idea: keep the same invariant visible across Intuition, Math, Code, Interactive Demo.
Machine Learning
CNN Shape Mechanics: Convolution, Padding, Stride, Pooling, and Channels
Convolutional layers scan shared local filters over grid data; padding, stride, channels, filters, and pooling decide the output tensor shape.
Concept Structure
CNN Shape Mechanics: Convolution, Padding, Stride, Pooling, and Channels
Start with the picture, metaphor, or geometric mechanism.
Make the objects explicit and connect them with notation.
Mirror the equations with runnable implementation details.
Manipulate the mechanism and watch the idea respond.
Learner Contract
What this page should let you do.
2 prerequisites listed; refresh them before leaning on the math or code.
Explain the mechanism, trace the main notation, and test one prediction in the live demo.
Read the intuition before the notation; the math should name a mechanism you already felt.
Follow this edge after making one prediction here; the next page should reuse the result, not restart the route.
Claim/source review status
Substantive review recorded
1/1 claims have bounded review metadata; still check caveats and source scope.Metadata-derived; review may be AI-assisted. Not a human certification.01
Intuition
Build the mental picture first so the rest of the page has something to attach to.
You are here because CNNs are often taught as pictures with arrows, but the learner still leaves unsure where the output shape came from. The useful mental model is simpler: a small filter looks at one local patch, writes one output value, then the same filter moves to the next allowed patch.
Before this, know linear transformations and matrices. By the end, you should be able to predict the output tensor shape of a convolutional layer, explain why channels are mixed by each filter, and tell convolution apart from pooling.
Convolution uses locality. Instead of connecting every input pixel to every output unit, a filter sees a small receptive field such as . The same filter weights are reused at many spatial positions. That is weight sharing: one learned detector can look for the same local pattern in different places.
Padding changes the border canvas. If you add zeros around the image, the kernel can be centered closer to the edge and the output can stay larger. Stride changes how far the kernel jumps. A stride of skips every other starting position, so the output gets smaller.
Channels are the common hidden confusion. An RGB image is not three independent convolutions unless you choose to view the calculation that way. A single output filter has weights for all input channels; it multiplies a patch and sums across space and channels to produce one output channel. Multiple filters produce multiple output channels.
Pooling is separate. A pooling window aggregates nearby activations, often to downsample a feature map. It has a shape formula like a sliding window, but it usually has no learned weights.
One caveat that keeps implementation intuition honest: many deep-learning libraries compute cross-correlation while calling the layer convolution. The kernel is not flipped in the usual forward operation. For learning CNN mechanics, the important object is the shared local filter scan.
02
Math
Translate the story into symbols, assumptions, and a derivation you can inspect.
Let the input tensor have shape
Let a convolutional layer use square kernels of size , symmetric padding , stride , and filters. Each filter has weights
plus one optional bias , where indexes the output channel.
For an output location and output channel , the cross-correlation-style forward value is
where is the padded input. This one equation says the whole mechanism: local patch, shared weights, sum over input channels, one output channel per filter.
The spatial output size is
and
provided the kernel can fit at least once. If or , there is no valid spatial position. The floor means some border pixels may be left unused when the numerator is not divisible by the stride.
The learned parameter count, with one bias per output channel, is
Notice what does not appear in that parameter count: and . The same filter is reused across positions, so larger images create more output values, not more filter weights.
For a pooling layer with window and stride applied after convolution, the same spatial-size pattern appears:
Pooling usually keeps the channel count fixed and adds no learned parameters.
03
Code
Keep the implementation aligned with the notation so the algorithm is legible.
import numpy as np
def conv2d_shape(H, W, K, P, S, Cin, Cout, bias=True):
if H + 2 * P < K or W + 2 * P < K:
return None
Hout = (H + 2 * P - K) // S + 1
Wout = (W + 2 * P - K) // S + 1
params = (K * K * Cin + int(bias)) * Cout
leftover_h = (H + 2 * P - K) % S
leftover_w = (W + 2 * P - K) % S
return Hout, Wout, Cout, params, leftover_h, leftover_w
X = np.arange(5 * 5 * 3).reshape(5, 5, 3)
kernel = np.ones((3, 3, 3))
patch = np.pad(X, ((1, 1), (1, 1), (0, 0)))[0:3, 0:3, :]
one_cell = np.sum(patch * kernel)
print("output shape/params:", conv2d_shape(5, 5, 3, 1, 1, 3, 4))
print("one output cell:", one_cell)
The first function is the shape witness. The second part shows the mechanism: after padding, one patch is multiplied by one filter and summed into one scalar output cell.
04
Interactive Demo
Use direct manipulation to connect the explanation to a moving system.
Choose a setup and predict both the spatial behavior and the parameter-count scale before reveal:
- Same spatial size: padding and stride preserve .
- Downsampled: the output is smaller, usually because stride or pooling jumps over positions.
- Leftover border: the floor in the formula drops a partial final step.
- Invalid: the kernel cannot fit at least once.
Before reveal, the exact output shape, parameter count, sliding positions, and one-cell calculation stay locked. After reveal, inspect the highlighted receptive field, the top-left output cell, the output tensor shape, and the caveat strip. The demo is not a full CNN architecture. It is the tensor-shape and locality grammar that later CNN architectures rely on.
Live Concept Demo
Explore CNN Shape Mechanics: Convolution, Padding, Stride, Pooling, and Channels
The stage is code-native and interactive. Use it to test the explanation against the mechanism.
Manipulate one control and predict the visible change.
Commit to what CNN Shape Mechanics: Convolution, Padding, Stride, Pooling, and Channels should make visible before reading the result.
After The First Pass
Turn the concept into an inspected object.
Once the invariant is visible in the intuition, math, code, and demo, use these panels to inspect the mechanism visually, check source support, practice the idea, and attach a grounded research question.
Mechanism Storyboard
See the idea move before the page explains it
Convolutional layers scan shared local filters over grid data; padding, stride, channels, filters, and pooling decide the output tensor shape.
Start with the picture, metaphor, or geometric mechanism.
Before reading further, choose the kind of change CNN Shape Mechanics: Convolution, Padding, Stride, Pooling, and Channels should make visible.
Visual Inquiry
Make the image answer a mathematical question
Convolutional layers scan shared local filters over grid data; padding, stride, channels, filters, and pooling decide the output tensor shape.
Which visible object should carry the first intuition?
Pick the cue that should make CNN Shape Mechanics: Convolution, Padding, Stride, Pooling, and Channels easier to reason about before the page gives the answer.
Source Grounding
Canonical references for the mechanism on this page.
Primary course-note source for local receptive fields, depth/filters, stride, zero padding, output volume sizing, and parameter sharing.
Open sourceSource for padding and stride mechanics in 2D convolutional layers.
Open sourceSource for multi-channel convolution: filters span all input channels and output channels correspond to learned filters.
Open sourceSource for max/average pooling as a separate local aggregation/downsampling operation.
Open sourceFrames convolutional networks through sparse interactions, parameter sharing, equivariance, and grid-structured data.
Open sourceCompact reference for convolution/pooling output dimensions and parameter counts.
Open sourceClaim Review
Convolutional layers scan shared local filters over grid data; padding, stride, channels, filters, and pooling decide the output tensor shape.
Claims without a substantive review badge still need exact source-support review.
cs231n-convnets, d2l-padding-stride, d2l-channels, d2l-pooling, goodfellow-2016-convnets, cs230-cnn-cheatsheet
Use equations, runnable code, and demos to check whether the source support is operational.
CS231n and Deep Learning Book support local receptive fields, full-depth shared filters, and parameter sharing; D2L supports padding/stride formulas, channel summation, output-channel filters, and pooling; CS230 supports compact shape and parameter-count formulas.
Sources: CS231n: Convolutional Neural Networks, Dive into Deep Learning: Padding and Stride, Dive into Deep Learning: Multiple Input and Multiple Output Channels, Dive into Deep Learning: Pooling, Deep Learning, Chapter 9: Convolutional Networks, CS230: Convolutional Neural Networks CheatsheetToy shape witness only; not full CNN architecture history, performance, optimized kernels, dilation/groups/depthwise variants, exact framework conventions, complete equivariance guarantees, or GPT Pro publication approval.A bounded review summary is present; still check caveats and exact reference scope.Checked CS231n for local receptive fields, full-depth filters, padding/stride sizing, parameter sharing, and parameter counts; D2L for padding/stride formulas, multi-channel summation, output-channel filters, and pooling; Deep Learning Book for sparse interactions, parameter sharing, grid data, and cross-correlation framing; and CS230 for compact output-size/parameter formulas. GPT Pro publish critique remains pending.
Reviewer: codex-local-primary-source-audit; reviewed 2026-07-01Source support candidates
course-notes 2026CS231n: Convolutional Neural NetworksPrimary course-note source for local receptive fields, depth/filters, stride, zero padding, output volume sizing, and parameter sharing.
book 2026Dive into Deep Learning: Padding and StrideSource for padding and stride mechanics in 2D convolutional layers.
book 2026Dive into Deep Learning: Multiple Input and Multiple Output ChannelsSource for multi-channel convolution: filters span all input channels and output channels correspond to learned filters.
book 2026Dive into Deep Learning: PoolingSource for max/average pooling as a separate local aggregation/downsampling operation.
Practice Loop
Try the idea before it explains itself
Convolutional layers scan shared local filters over grid data; padding, stride, channels, filters, and pooling decide the output tensor shape.
Before touching the demo, predict one visible change that should happen in CNN Shape Mechanics: Convolution, Padding, Stride, Pooling, and Channels.
Reveal when your model needs a nudge.
Reveal when your model needs a nudge.
Reveal when your model needs a nudge.
A concrete answer is on the canvas.
The answer names why the claim should hold.
It touches the page context or a neighboring idea.
Research Room
Attach the question to a claim, equation, code, or demo
Pick the concept, equation, source, runnable code, claim, misconception, or demo state before asking for help. The handoff keeps that page item in context.Open the draft below to save one note and next action in this browser.
CNN Shape Mechanics: Convolution, Padding, Stride, Pooling, and Channels
What is the smallest example that makes CNN Shape Mechanics: Convolution, Padding, Stride, Pooling, and Channels click without losing the math?
Local action draftNo local draft saved yetExpand only when ready to capture one local next action
This draft stays in this browser, attached to the selected learning item.
- References to inspect: attached references on this page.
- Definition, prerequisite, and contrast concept links
- The equation or runnable code that makes the concept operational
- One demo state that shows the invariant instead of a slogan
- The learner can state the mechanism in their own words
- The learner can name the prerequisite that would repair confusion
- The learner can predict how the mechanism changes under one perturbation
I am working in Continuous Function's research reading room. Object: concept - CNN Shape Mechanics: Convolution, Padding, Stride, Pooling, and Channels Selected item key: recorded for copy. Context: Machine Learning Page anchor: recorded for copy. Open question: What is the smallest example that makes CNN Shape Mechanics: Convolution, Padding, Stride, Pooling, and Channels click without losing the math? Evidence to inspect: - References to inspect: attached references on this page. - Definition, prerequisite, and contrast concept links - The equation or runnable code that makes the concept operational - One demo state that shows the invariant instead of a slogan What would resolve this: - The learner can state the mechanism in their own words - The learner can name the prerequisite that would repair confusion - The learner can predict how the mechanism changes under one perturbation Answer as a careful research tutor: stay source-grounded, separate verified evidence from assumptions, name the relevant math objects, and end with one next action.
concept/concept-notebook/machine-learning/cnn-convolution-padding-stride-channels
concept:machine-learning/cnn-convolution-padding-stride-channels