Code QuizIntermediate

MaxPool Stride and Downsampling

Spotting why a max pooling layer fails to halve the spatial dimensions.

Codepython
import torch
import torch.nn as nn

# Goal: downsample a 32x32 feature map to 16x16
pool = nn.MaxPool2d(kernel_size=2, stride=1)

x = torch.randn(1, 8, 32, 32)
y = pool(x)
print(y.shape)  # expected: [1, 8, 16, 16]

The output is [1, 8, 31, 31] instead of [1, 8, 16, 16]. What is the bug?