Skip to content
class

AdaptiveMaxPool1d

extendsModule
AdaptiveMaxPool1d(output_size: _OutSize, return_indices: bool = False)

Applies adaptive 1-D max pooling to produce a fixed output length.

For each output position ii, the window boundaries are:

start(i)=⌊i⋅LinLout⌋,end(i)=⌈(i+1)LinLout⌉\text{start}(i) = \left\lfloor \frac{i \cdot L_{in}}{L_{out}} \right\rfloor, \quad \text{end}(i) = \left\lceil \frac{(i+1) L_{in}}{L_{out}} \right\rceil

and the output is:

y[n,c,i]=max⁡k∈[start(i),  end(i))x[n,c,k]y[n, c, i] = \max_{k \in [\text{start}(i),\; \text{end}(i))} x[n, c, k]

Parameters

output_sizeint or tuple[int, ...]
Desired output length.
return_indicesbool= False
If True, returns (output, indices). Default: False.

Attributes

output_sizeint or tuple[int, ...]

Notes

  • Input: (N, C, L_in)
  • Output: (N, C, output_size)
  • Adaptive max pooling retains the strongest activation in each adaptively-sized segment, combining the spatial invariance of max pooling with input-size flexibility.
  • This layer is frequently used in region-proposal networks and variable-length sequence encoders.

Examples

Compress sequence to fixed length 4:
>>> import lucid
>>> import lucid.nn as nn
>>> pool = nn.AdaptiveMaxPool1d(output_size=4)
>>> x = lucid.ones((2, 32, 50))
>>> y = pool(x)
>>> y.shape
(2, 32, 4)
Global max pooling (output_size=1):
>>> gmp = nn.AdaptiveMaxPool1d(output_size=1)
>>> x = lucid.ones((4, 128, 200))
>>> y = gmp(x)
>>> y.shape
(4, 128, 1)

Used by 1

Constructors

1
dunder

__init__

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

Initialise the AdaptiveMaxPool1d 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.