class

AdaptiveMaxPool2d

extendsModule
AdaptiveMaxPool2d(output_size: _Size2d, return_indices: bool = False)
source

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:

y[n,c,h,w]=maxi[hs,he),  j[ws,we)x[n,c,i,j]y[n, c, h, w] = \max_{i \in [h_s, h_e),\; j \in [w_s, w_e)} x[n, c, i, j]

Parameters

output_sizeint or tuple[int, int]
Target (H_out, W_out). A scalar is broadcast to both dimensions.
return_indicesbool= False
Not 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)
source

Initialise the AdaptiveMaxPool2d module. See the class docstring for parameter semantics.

fn

forward

Tensor
forward(x: Tensor)
source

Apply the pooling operation to the input tensor.

Parameters

inputTensor
Input tensor of shape (N,C,)(N, C, *) where * are the spatial dimensions appropriate for this pooling layer.

Returns

Tensor

Pooled output tensor.

fn

extra_repr

str
extra_repr()
source

Return a string representation of the layer's configuration.