liveBook · Manning

Padding

As explained in Deep Learning with Python, Third Edition

Padding is the addition of extra space, values, or data around or within a structure to satisfy size, alignment, layout, or processing requirements.

Convolution windows near an input’s edges have fewer valid positions, so the output feature map can shrink. Padding adds rows and columns around the input, allowing windows to be centered at every input location and preserving spatial dimensions. section 8.1.1

A 5 × 5 feature map

A 3 × 3 window fits at only nine centered positions without padding, producing a 3 × 3 output. Adding one row and column on each side allows 25 window positions. In Conv2D, `valid` means no padding; `same` pads to preserve input width and height. The default is `valid`. section 8.1.1

Figure 8.6 Padding a 5 × 5 input to be able to extract 25 3 × 3 patches
padding of 5x5 input

See how padding a 5 × 5 input enables 25 extracted 3 × 3 patches. section 8.1.1

How Deep Learning with Python, Third Edition covers it

How deep it goes
Explains border effects with a 5 × 5 example and defines `valid` and `same`, without detailing padding implementation.
Examples
Compares 3 × 3 windows on a 5 × 5 feature map with and without padding.
What you can do after
Configure padding in Conv2D using `valid` for no padding or `same` to preserve spatial dimensions.
How it connects
Relates padding to convolution windows, feature-map dimensions, and strides as causes of output-size changes.

Also explained in

Compare how 19 books explain padding →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with Python, Third Edition. The section links point to the parts of the book it draws on.