Skip to content
fn

adaptive_max_pool2d

→Tensor
adaptive_max_pool2d(input: Tensor, output_size: int | tuple[int | None, ...], return_indices: bool = False)

Implementing kernel

C++ engine symbols that back this Python API.

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

inputTensor
Input of shape (N, C, H, W), or (C, H, W) unbatched.
output_sizeint or (int or None, int or None)
Desired spatial output shape.
return_indicesbool= False
Also return (output, indices): each output cell's maximum as a flat position in the input's spatial extent.

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)

Used by 3