adaptive_max_pool1d

paddle.nn.functional. adaptive_max_pool1d ( x, output_size, return_mask=False, name=None ) [source]

This API implements adaptive max pooling 1d operation. See more details in AdaptiveMaxPool1D .

Parameters
  • x (Tensor) – The input tensor of pooling operator, which is a 3-D tensor with shape [N, C, L]. The format of input tensor is NCL, where N is batch size, C is the number of channels, L is the length of the feature. The data type is float32 or float64.

  • output_size (int) – The pool kernel size. The value should be an integer.

  • return_mask (bool) – 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.

Returns

The output tensor of adaptive pooling result. The data type is same

as input tensor.

Return type

Tensor

Examples

>>> # 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.functional as F

>>> data = paddle.uniform([1, 3, 32], paddle.float32)
>>> pool_out = F.adaptive_max_pool1d(data, output_size=16)
>>> print(pool_out.shape)
[1, 3, 16]
>>> pool_out, indices = F.adaptive_max_pool1d(data, output_size=16, return_mask=True)
>>> print(pool_out.shape)
[1, 3, 16]
>>> print(indices.shape)
[1, 3, 16]