liveBook · Manning

Convolution kernel

As explained in Grokking AI Algorithms, Second Edition

A convolutional filter is a small learned grid of weights that detects a particular local pattern in image data.

A convolution kernel, also called a filter, is a small grid of learned weights that looks for a local pattern in an image. Think of it as a tiny magnifying glass: one filter may become sensitive to vertical edges, while another responds to textures. A common size is 3×3. The network starts with random weights and adjusts them during training rather than being told which patterns to find. section 12.14

To use a filter, place it over a patch of pixels. Multiply each weight by the pixel beneath it, then add the results. That sum becomes one value in a feature map—a grid showing where the filter responds. Slide the same filter across the image and repeat. section 12.14

One small calculation

For one row, suppose the filter weights are [2, 7, 2] and the pixels beneath them are [11, 2, 1]. Their contribution is (2×11) + (7×2) + (2×1) = 38. A full 3×3 calculation also includes the other two rows. The filter then moves to the next position and performs the calculation again. section 12.14

Figure 12.24 How a CNN filter scans an image
12_24

See how a small filter moves across an image, producing a calculation at each position. section 12.14

Different filters produce different feature maps. In a U-Net encoder example, eight distinct 3×3 filters scan an 8×8 noisy image, producing eight 8×8 feature maps. Each filter also has a learnable bias added to its calculated values. Padding around the image lets the filters calculate values at its edges while keeping these feature maps 8×8. section 12.17 section 12.17

Filter size and movement also affect resolution. The first encoder convolution uses a 3×3 filter with a one-pixel stride; a later downsampling convolution uses 4×4 filters with a two-pixel stride. In the decoder, a transposed convolution uses trainable filters differently: each input value contributes a larger patch to the output, and overlapping contributions are added. section 12.17 section 12.19

The practical takeaway: a kernel is not a fixed edge-finding rule. It is a reusable set of weights whose responses help a convolutional network extract useful image features—or, in a transposed convolution, help enlarge a feature map. section 12.14 section 12.19

How Grokking AI Algorithms, Second Edition covers it

How deep it goes
Works through sliding dot products and feature-map shapes, then sketches NumPy implementations; does not derive weight updates.
Examples
Uses a numeric filter-row calculation and eight 3×3 filters scanning an 8×8 noisy image.
What it assumes
Assumes basic familiarity with images and pixels while defining filters and explaining the dot-product calculation.
What you can do after
Build it from scratch using NumPy-style loops to scan image patches and calculate feature maps.
How it connects
Connects convolutional layers, feature maps, backpropagation, padding, downsampling, and transposed convolution.

Also explained in

Compare how 11 books explain convolution kernel →

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.