fn
adaptive_avg_pool2d
→Tensoradaptive_avg_pool2d(x: Tensor, output_size: int | tuple[int, int])2-D adaptive average pooling — produces a fixed (H, W).
Computes per-axis kernel / stride so the output shape exactly
matches output_size regardless of the input spatial size. The
workhorse "global pool to fixed grid" used by virtually every
modern classification network (output_size=(1, 1) collapses
the spatial axes entirely).
Parameters
xTensorInput of shape
(N, C, H, W).output_sizeint or (int, int)Desired spatial shape of the output. Scalar duplicates per
axis;
(1, 1) performs global average pooling.Returns
TensorOutput of shape (N, C, oH, oW).
Notes
For each output cell the corresponding input window is
Foundational to Spatial Pyramid Pooling and the "global average pool + linear classifier" pattern introduced by NIN / ResNet-style architectures.
Examples
>>> import lucid
>>> from lucid.nn.functional import adaptive_avg_pool2d
>>> x = lucid.randn(1, 512, 7, 9)
>>> y = adaptive_avg_pool2d(x, output_size=(1, 1))
>>> y.shape
(1, 512, 1, 1)