class
AdaptiveMaxPool1d
extends
ModuleAdaptiveMaxPool1d(output_size: int | tuple[int, ...], return_indices: bool = False)Applies adaptive 1-D max pooling to produce a fixed output length.
For each output position , the window boundaries are:
and the output is:
Parameters
output_sizeint or tuple[int, ...]Desired output length.
return_indicesbool= FalseNot 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)Initialise the AdaptiveMaxPool1d 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.