Start studying
Module 3 · Computer Vision Module contents
Module 3  ·  Card 4 / 22beginner

Padding

Padding adds a border of extra pixels, usually zeros, around the image.

Without it, every convolution shrinks the output slightly.

Same padding sizes the border so the output matches the input dimensions.

Valid padding adds nothing and lets the output shrink.

Padding also stops edge pixels from being under-used by the filter.

Learn in depth ↓
Module 03 · Computer Vision · 22 concepts
In depth  /  15 lines

Padding, in more detail

A convolution cannot centre its kernel on a pixel at the very edge, since part of it hangs off.

So without help the output comes back slightly smaller than the input.

A 3 by 3 kernel on a 32 by 32 image gives 30 by 30.

Do that twenty times and there is nothing left to convolve.

Padding adds a border of extra pixels around the image, usually zeros.

Same padding sizes that border so the output matches the input exactly.

Valid padding adds nothing and accepts the shrinkage, which is the other common setting.

Same padding is the usual default, since it keeps the architecture easy to reason about.

It also fixes a subtler problem at the edges.

Without padding, a corner pixel is covered by far fewer kernel positions than a central one.

The model therefore sees the edges of every image less often than the middle.

That matters when the subject is not neatly centred.

Zeros are the standard filler, and reflecting or repeating the edge pixels is also used.

Zero padding does introduce a thin artificial border the network learns to recognise.

It is a small distortion and universally accepted as worth the convenience.

Want the full technical article? Wikipedia ↗
Test yourself

One question on this card. Every option explains itself once you pick, right or wrong.

Question 1
What happens to a feature map if you use no padding?
Computer Vision

22 concepts in this module, then a graded test with every answer explained.

Study this module →
↑↓ move↵ openesc close