mindspore.ops.lp_pool1d

View Source On Gitee
mindspore.ops.lp_pool1d(x, norm_type, kernel_size, stride=None, ceil_mode=False)[source]

Applying 1D LPPooling operation on an input Tensor can be regarded as forming a 1D input plane.

Typically the input is of shape \((N, C, L_{in})\) or \((C, L_{in})\), the output is of shape \((N, C, L_{out})\) or \((C, L_{out})\).

\[L_{out} = \left\lfloor\frac{L_{in} - \text{kernel_size}}{\text{stride}} + 1\right\rfloor\]

The operation is as follows.

\[f(X) = \sqrt[p]{\sum_{x \in X} x^{p}}\]
Parameters
  • x (Tensor) – Tensor of shape \((N, C, L_{in})\) or \((C, L_{in})\).

  • norm_type (Union[int, float]) –

    Type of normalization, represents p in the formula, can not be 0,

    • if p = 1, the result obtained is the sum of elements in the pool nucleus(Proportional to average pooling).

    • if p = \(\infty\), the result is the result of maximum pooling.

  • kernel_size (int) – The size of kernel window.

  • stride (int) – The distance of kernel moving, an int number that represents the width of movement is stride. Default: None , which indicates the moving step is kernel_size .

  • ceil_mode (bool) – Whether to use ceil or floor to calculate output shape. Default: False .

Returns

  • output (Tensor) - LPPool1d result, with shape \((N, C, L_{out})\) or \((C, L_{out})\), It has the same data type as x, where

    \[L_{out} = \left\lfloor\frac{L_{in} - \text{kernel_size}}{\text{stride}} + 1\right\rfloor\]

Raises
  • TypeError – If x is not a Tensor.

  • TypeError – If kernel_size or stride is not an int.

  • TypeError – If ceil_mode is not a bool.

  • TypeError – If norm_type is neither float nor int.

  • ValueError – If norm_type is equal to 0.

  • ValueError – If kernel_size or stride is less than 1.

  • ValueError – If length of shape of x is not equal to 2 or 3.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore as ms
>>> from mindspore import ops
>>> from mindspore import Tensor
>>> import numpy as np
>>> x = Tensor(np.arange(2 * 3 * 4).reshape((2, 3, 4)), dtype=ms.float32)
>>> out = ops.lp_pool1d(x, norm_type=1, kernel_size=3, stride=1, ceil_mode=False)
>>> print(out)
[[[ 3.  6.]
  [15. 18.]
  [27. 30.]]
 [[39. 42.]
  [51. 54.]
  [63. 66.]]]