mindspore.ops.lp_pool2d

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

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

Typically the input is of shape \((N, C, H_{in}, W_{in})\), the output is of shape \((N, C, H_{in}, W_{in})\), with the same shape as input, the operation is as follows.

\[f(X) = \sqrt[p]{\sum_{x \in X} x^{p}}\]

Note

This interface currently does not support Atlas A2 training series products.

Parameters
  • x (Tensor) – Tensor of shape \((N, C, H_{in}, W_{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 (Union[int, tuple[int]]) – The size of kernel window. The data type of kernel_size must be int and the value represents the height and width, or a tuple of two int numbers that represent height and width respectively.

  • stride (Union[int, tuple[int]]) – The distance of kernel moving, an int number that represents the height and width of movement are both strides, or a tuple of two int numbers that represent height and width of movement respectively. 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) - LPPool2d result, with shape \((N, C, H_{in}, W_{in})\), It has the same data type as x, where

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

Raises
  • TypeError – If x is not a Tensor.

  • TypeError – If kernel_size or stride is neither int nor tuple.

  • 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 kernel_size or stride is a tuple whose length is not equal to 2.

  • ValueError – If length of shape of x is not equal to 4.

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 * 5).reshape((2, 3, 4, 5)), dtype=ms.float32)
>>> out = ops.lp_pool2d(x, norm_type=1, kernel_size=3, stride=1, ceil_mode=False)
>>> print(out)
[[[[  54.   63.   72.]
   [  99.  108.  117.]]
  [[ 234.  243.  252.]
   [ 279.  288.  297.]]
  [[ 414.  423.  432.]
   [ 459.  468.  477.]]]
 [[[ 594.  603.  612.]
   [ 639.  648.  657.]]
  [[ 774.  783.  792.]
   [ 819.  828.  837.]]
  [[ 954.  963.  972.]
   [ 999. 1008. 1017.]]]]