What Does MaxPool2d Output with Kernel 2, Stride 2?

MaxPool2d with kernel_size=2, stride=2 halves spatial dimensions. Input (batch, C, 14, 14) produces output (batch, C, 7, 7). Channels are unchanged. Zero trainable parameters.

Formula

output_size = floor((input_size - kernel_size + 2 * padding) / stride) + 1

For kernel=2, stride=2, padding=0:

output = floor((14 - 2 + 0) / 2) + 1
output = floor(12 / 2) + 1
output = 6 + 1
output = 7

Common MaxPool2d Configurations

# MaxPool2d(2, stride=2) — standard halving
(batch, 64, 224, 224)  -> (batch, 64, 112, 112)
(batch, 128, 56, 56)   -> (batch, 128, 28, 28)
(batch, 256, 14, 14)   -> (batch, 256, 7, 7)

# MaxPool2d(3, stride=2, padding=1) — ResNet style
(batch, 64, 112, 112)  -> (batch, 64, 56, 56)

# MaxPool2d(3, stride=2) — no padding
(batch, 64, 112, 112)  -> (batch, 64, 55, 55)

PyTorch Code

import torch
import torch.nn as nn

pool = nn.MaxPool2d(kernel_size=2, stride=2)
x = torch.randn(1, 64, 14, 14)
output = pool(x)
print(output.shape)  # torch.Size([1, 64, 7, 7])

Key Points

Related Questions

Try the MaxPool2d Calculator