class
AdaptiveMaxPool2d
extends
ModuleAdaptiveMaxPool2d(output_size: _Size2d, 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= FalseNot yet supported. 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)Methods (3)
dunder
__init__
→None__init__(output_size: _Size2d, return_indices: bool = False)Initialise the AdaptiveMaxPool2d module. See the class docstring for parameter semantics.
fn
forward
→Tensorforward(x: Tensor)Apply the pooling operation to the input tensor.
Parameters
inputTensorInput tensor of shape where are the
spatial dimensions appropriate for this pooling layer.
Returns
TensorPooled output tensor.
fn
extra_repr
→strextra_repr()Return a string representation of the layer's configuration.