Skip to content
class

AdaptiveMaxPool2d

extendsModule
AdaptiveMaxPool2d(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:

y[n,c,h,w]=max⁡i∈[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
If 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)

Used by 1

Constructors

1
dunder

__init__

→None
__init__(output_size: _OutSize, return_indices: bool = False)

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

Instance methods

2
fn

extra_repr

→str
extra_repr()

Return a string representation of the layer's configuration.