Kernel size is the spatial size of the filter, or receptive window, that a convolutional layer moves across an input image. In PyTorch, kernel_size=3 creates a 3 × 3 filter, while kernel_size=2 creates a 2 × 2 filter. Smaller windows inspect local regions; the selected size helps determine which spatial patterns the layer can extract. section 4.2.1 section 4.2
Read kernel size alongside the settings that control how a filter scans the image:
- Stride specifies how many pixels the filter moves horizontally or vertically after each operation; larger strides downsample more. section 4.2.1
- Padding adds rows of zeros around the input; its default is zero and it changes how the filter fits near image boundaries. section 4.2.1
- Kernel size differs from transposed convolution: convolution extracts features, whereas transposed convolution upsamples feature maps. section 4.0 section 4.2
A 2 × 2 convolution
A 3 × 3 grayscale image can be passed to nn.Conv2d with in_channels=1, out_channels=1, kernel_size=2, and stride=1. Replacing the learned weights with [[1, 2], [3, 4]] and setting the bias to 0 produces a 2 × 2 output tensor: [[7, 14], [54, 50]]. The output is smaller because the 2 × 2 window moves across the 3 × 3 input without padding. section 4.2.1
Figure 4.5 A numerical example of how convolutional operations work, with stride equal to 1 and no padding
Use the numerical figure to trace a 2 × 2 filter across a 3 × 3 input with stride 1 and no padding. section 4.2.1



