class paddle.nn. AdaptiveMaxPool1D ( output_size, return_mask=False, name=None ) [source]

This operation applies a 1D adaptive max pooling over an input signal composed of several input planes, based on the input, output_size, return_mask parameters. Input(X) and output(Out) are in NCL format, where N is batch size, C is the number of channels, L is the length of the feature. The output tensor shape will be [N, C, output_size].

For max adaptive pool1d:

\[ \begin{align}\begin{aligned}lstart &= floor(i * L_{in} / L_{out})\\lend &= ceil((i + 1) * L_{in} / L_{out})\\Output(i) &= max(Input[lstart:lend])\end{aligned}\end{align} \]
  • output_size (int|list|tuple) – The pool kernel size. If pool kernel size is a tuple or list, it must contain one int.

  • return_mask (bool, optional) – If true, the index of max pooling point will be returned along with outputs. It cannot be set in average pooling type. Default False.

  • name (str, optional) – For detailed information, please refer to Name. Usually name is no need to set and None by default.


A callable object of AdaptiveMaxPool1D.

  • x(Tensor): The input tensor of adaptive max pool1d operator, which is a 3-D tensor. The data type can be float32, float64.

  • output(Tensor): The output tensor of adaptive max pool1d operator, which is a 3-D tensor. The data type is same as input x.


# max adaptive pool1d
# suppose input data in shape of [N, C, L], `output_size` is m or [m],
# output shape is [N, C, m], adaptive pool divide L dimension
# of input data into m grids averagely and performs poolings in each
# grid to get output.
# adaptive max pool performs calculations as follow:
#     for i in range(m):
#         lstart = floor(i * L / m)
#         lend = ceil((i + 1) * L / m)
#         output[:, :, i] = max(input[:, :, lstart: lend])
import paddle
import paddle.nn as nn

data = paddle.uniform([1, 3, 32], dtype="float32", min=-1, max=1)
AdaptiveMaxPool1D = nn.AdaptiveMaxPool1D(output_size=16)
pool_out = AdaptiveMaxPool1D(data)
# pool_out shape: [1, 3, 16]

# for return_mask = true
AdaptiveMaxPool1D = nn.AdaptiveMaxPool1D(output_size=16, return_mask=True)
pool_out, indices = AdaptiveMaxPool1D(data)
# pool_out shape: [1, 3, 16], indices shape: [1, 3, 16]
forward ( input )


Defines the computation performed at every call. Should be overridden by all subclasses.

  • *inputs (tuple) – unpacked tuple arguments

  • **kwargs (dict) – unpacked dict arguments

extra_repr ( )


Extra representation of this layer, you can have custom implementation of your own layer.