← Lessons

quiz vs the machine

Gold1330

Machine Learning

Padding and Stride

Two knobs that control output size and how far the kernel hops.

4 min read · core · beat Gold to climb

Padding and Stride

Convolution shrinks an image because the kernel cannot fully overlap the edges. Padding and stride are the two settings that control output size and how the kernel moves.

Padding

Padding adds a border of extra values, usually zeros, around the image before convolving.

  • Valid padding adds nothing, so the output is smaller than the input.
  • Same padding adds just enough border so the output keeps the input size.

Padding preserves spatial size and lets edge pixels be seen by more kernel positions, which matters in deep stacks where shrinking adds up.

Stride

Stride is how many pixels the kernel jumps between applications.

  • A stride of one moves one pixel at a time and keeps full resolution.
  • A stride of two skips every other position and roughly halves the output dimensions.

Larger strides downsample the feature map cheaply, reducing computation and giving each output a wider view of the input.

Output size

With input size n, kernel size k, padding p, and stride s, the output side is floor of n plus two p minus k over s plus one. Knowing this lets you design layers that hit a target shape.

Key idea

Padding adds a border to control output size, and stride sets how far the kernel hops, together shaping resolution and cost.

Check yourself

Answer to earn rating on the learn ladder.

1. What does same padding achieve?

2. What happens with a stride of two?