class

AdaptiveMaxPool1d

extendsModule
AdaptiveMaxPool1d(output_size: int | tuple[int, ...], return_indices: bool = False)
source

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

For each output position ii, the window boundaries are:

start(i)=iLinLout,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]=maxk[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
Not yet supported. 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)

Methods (3)

dunder

__init__

None
__init__(output_size: int | tuple[int, ...], return_indices: bool = False)
source

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