fn

adaptive_max_pool2d

Tensor
adaptive_max_pool2d(x: Tensor, output_size: int | tuple[int, int], return_indices: bool = False)
source

2-D adaptive max pooling — fixed-shape (H, W) via per-cell max.

Like adaptive_avg_pool2d but takes the maximum over each dynamically computed window instead of the mean. Useful when salient peaks should drive the downstream representation (e.g. object detectors that rely on strong activations).

Parameters

xTensor
Input of shape (N, C, H, W).
output_sizeint or (int, int)
Desired spatial output shape.
return_indicesbool= False
Must currently be False.

Returns

Tensor

Output of shape (N, C, oH, oW).

Notes

For each output cell, the window definition is the same as in adaptive_avg_pool2d; the cell value is

yi,c,h,w=max(m,n)R(h,w)xi,c,m,ny_{i,c,h,w} = \max_{(m, n) \in R(h, w)} x_{i,\,c,\,m,\,n}

Gradient flows only through the per-window argmax position.

Examples

>>> import lucid
>>> from lucid.nn.functional import adaptive_max_pool2d
>>> x = lucid.randn(1, 64, 11, 13)
>>> y = adaptive_max_pool2d(x, output_size=(3, 3))
>>> y.shape
(1, 64, 3, 3)