class
AdaptiveMaxPool2d
extends
ModuleAdaptiveMaxPool2d(output_size: _OutSize, return_indices: bool = False)Applies adaptive 2-D max pooling to produce a fixed output size.
The window boundaries for each output position are computed the same
way as in AdaptiveAvgPool2d, but instead of averaging the
module returns the maximum value in each window:
Parameters
output_ sizeint or tuple[int, int]Target
(H_out, W_out). A scalar is broadcast to both
dimensions.return_ indicesbool= FalseIf
True, returns (output, indices). Default: False.Attributes
output_ sizeint or tuple[int, int]Notes
- Input:
(N, C, H_in, W_in) - Output:
(N, C, H_out, W_out)
- Adaptive max pooling preserves the strongest activations in each spatial region, making it useful for detection and segmentation tasks where precise location of features matters.
- Like
AdaptiveAvgPool2d, this layer accepts any input spatial size, which simplifies transfer learning from different input resolutions.
Examples
Reduce arbitrary feature map to a fixed 3 × 3 grid:
>>> import lucid
>>> import lucid.nn as nn
>>> pool = nn.AdaptiveMaxPool2d(output_size=(3, 3))
>>> x = lucid.ones((1, 64, 20, 20))
>>> y = pool(x)
>>> y.shape
(1, 64, 3, 3)
Single-pixel summary (spatial global max):
>>> pool = nn.AdaptiveMaxPool2d(output_size=1)
>>> x = lucid.ones((4, 128, 13, 13))
>>> y = pool(x)
>>> y.shape
(4, 128, 1, 1)