liveBook · Manning

Kernel size

As explained in Inside Deep Learning: Math, Algorithms, Models

The spatial extent of a convolutional filter.

Kernel size is the spatial extent of a convolutional or pooling window. In PyTorch, it is the numeric argument that determines how many neighboring pixels each operation considers. section 3.4.2 section 3.5

Use kernel size to control the local operation and its interaction with stride and padding:

  • Convolutions commonly use stride 1, evaluating every possible location; padding can preserve height and width. section 3.4.2 section 3.5
  • Max pooling uses the kernel as its selection window and commonly sets stride equal to kernel size, shrinking each dimension by that factor. section 3.5
  • GAN architectures may choose kernel size 5 for ordinary convolutions and 4 for transposed convolutions to produce smoother, evenly contributed expansions. section 9.4.1

PyTorch choices

A same-sized convolution can use nn.Conv2d(..., 3, padding=3//2). A GAN helper instead passes k_size=5 to nn.Conv2d and uses k_size_t=4 with nn.ConvTranspose2d(..., stride=2, padding=1). section 3.4.2 section 9.4.1

Figure 3.14 Example of max pooling for K = 2 (top) and K = 3 (bottom). Each region of the input (left) has a color indicating the group of pixels participating in the pooling, and the output (right) shows which value was selected from the input region. Note that the output is smaller than the input by a factor of K.

Compare K=2 and K=3 max-pooling windows and see how kernel size reduces the output. section 3.5

How Inside Deep Learning: Math, Algorithms, Models covers it

How deep it goes
Defines window size and relates it to stride and padding, but does not derive convolution output-size formulas.
Examples
Uses K=3 convolutions, K=2 and K=3 pooling windows, and GAN settings k_size=5 and k_size_t=4.
What you can do after
Apply it via PyTorch by selecting kernel size alongside padding and stride in convolutional and pooling layers.
How it connects
Connects convolution, pooling, stride, padding, and transposed convolution through shared spatial-window choices.

Also explained in

Compare how 4 books explain kernel size →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Inside Deep Learning: Math, Algorithms, Models. The section links point to the parts of the book it draws on.