mindspore.ops.MaxPool3D

View Source On Gitee
class mindspore.ops.MaxPool3D(kernel_size=1, strides=1, pad_mode='VALID', pad_list=0, ceil_mode=None, data_format='NCDHW')[source]

Applies a 3D max pooling over an input Tensor which can be regarded as a composition of 3D planes.

Typically the input is of shape \((N_{in}, C_{in}, D_{in}, H_{in}, W_{in})\), MaxPool outputs regional maximum in the \((D_{in}, H_{in}, W_{in})\)-dimension. Given kernel size \(ks = (d_{ker}, h_{ker}, w_{ker})\) and stride \(s = (s_0, s_1, s_2)\), the operation is as follows:

\[\text{output}(N_i, C_j, d, h, w) = \max_{l=0, \ldots, d_{ker}-1} \max_{m=0, \ldots, h_{ker}-1} \max_{n=0, \ldots, w_{ker}-1} \text{input}(N_i, C_j, s_0 \times d + l, s_1 \times h + m, s_2 \times w + n)\]
Parameters
  • kernel_size (Union[int, tuple[int]]) – The size of kernel used to take the maximum value, is an int number that represents depth, height and width of the kernel, or a tuple of three int numbers that represent depth, height and width respectively. Default: 1 .

  • strides (Union[int, tuple[int]]) – The distance of kernel moving, an int number that represents not only the depth, height of movement but also the width of movement,, or a tuple of three int numbers that represent depth, height and width of movement respectively. Default: 1 .

  • pad_mode (str, optional) –

    Specifies the padding mode with a padding value of 0. It can be set to: "SAME" , "VALID" or "PAD" . Default: "VALID" .

    • "SAME": Pad the input around its depth/height/width dimension so that the shape of input and output are the same when stride is set to 1. The amount of padding to is calculated by the operator internally. If the amount is even, it isuniformly distributed around the input, if it is odd, the excess amount goes to the front/right/bottom side. If this mode is set, pad_list must be 0.

    • "VALID": No padding is applied to the input, and the output returns the maximum possible depth, height and width. Extra pixels that could not complete a full stride will be discarded. If this mode is set, pad_list must be 0.

    • "PAD": Pad the input with a specified amount. In this mode, the amount of padding in the depth, height and width dimension is determined by the pad_list parameter. If this mode is set, pad_list must be greater than or equal to 0.

  • pad_list (Union(int, tuple[int])) – The pad value to be filled. Default: 0 . If pad is an integer, the paddings of head, tail, top, bottom, left and right are the same, equal to pad. If pad is a tuple of six integers, the padding of head, tail, top, bottom, left and right equals to pad[0], pad[1], pad[2], pad[3], pad[4] and pad[5] correspondingly.

  • ceil_mode (Union[bool, None]) – Whether to use ceil instead of floor to calculate output shape. Only effective in “pad” mode. When pad_mode is "pad" and “ceil_mode” is None , ceil_mode will be set as False. Default: None .

  • data_format (str) – The optional value for data format. Currently only support "NCDHW" . Default: "NCDHW" .

Inputs:
  • x (Tensor) - Tensor of shape \((N, C, D_{in}, H_{in}, W_{in})\). Data type must be float16, float32 or float64.

Outputs:

Tensor, with shape \((N, C, D_{out}, H_{out}, W_{out})\). Has the data type of x.

Raises
  • TypeError – If kernel_size or strides is neither an int nor a tuple.

  • TypeError – If pad_mode or data_format is not a string.

  • ValueError – If numbers in kernel_size or strides are not positive.

  • ValueError – If pad_mode is not one of "SAME", "VALID" or "PAD".

  • ValueError – If pad_mode is "SAME" or "VALID", ceil_mode is not None.

  • ValueError – If kernel_size or strides is a tuple whose length is not equal to 3.

  • ValueError – If data_format is not "NCDHW".

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> import numpy as np
>>> from mindspore import Tensor, ops
>>> x = Tensor(np.arange(1 * 2 * 2 * 2 * 3).reshape((1, 2, 2, 2, 3)), mindspore.float32)
>>> max_pool3d = ops.MaxPool3D(kernel_size=2, strides=1, pad_mode="VALID")
>>> output = max_pool3d(x)
>>> print(output)
[[[[[10. 11.]]]
  [[[22. 23.]]]]]