liveBook · Manning

Padding

As explained in Grokking AI Algorithms, Second Edition

Padding is the addition of extra border values around an input array before an operation is applied.

Padding adds a border of extra values—usually zeros—around an input image or tensor before convolution. It gives a filter room to reach edge and corner pixels instead of hanging outside the input. section 12.14

Padding is useful when a convolution should:

  • Preserve spatial size, allowing the output feature map to keep the input’s height and width. section 12.14
  • Process borders properly, so features near edges are not lost or represented less often during training. section 12.14

A 3×3 filter at an image corner

Without padding, a 3×3 filter centered on a corner would extend beyond the image. With one layer of zero padding, the filter can start at the top-left position, multiply its values by the available pixels and added zeros, sum the results, and continue scanning every original pixel. With stride 1 and the right amount of padding, the output retains the input dimensions. section 12.14

How Grokking AI Algorithms, Second Edition covers it

How deep it goes
Explains zero borders, edge coverage, and output sizing, then demonstrates 2D and 3D implementations without deeper convolution theory.
Examples
Uses a 3×3 filter scan, zero-padded image, NumPy functions, and a padded multi-channel tensor.
What it assumes
Assumes basic images, arrays, filters, and convolution while explaining border handling from first principles.
What you can do after
Builds padding from scratch for 2D images and 3D feature-map tensors using zero-filled borders.
How it connects
Connects padding to convolution, filters, feature maps, stride, downsampling, and U-Net layers.

Also explained in

Compare how 19 books explain padding →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking AI Algorithms, Second Edition. The section links point to the parts of the book it draws on.