mindspore.ops.fractional_max_pool3d

View Source On Gitee
mindspore.ops.fractional_max_pool3d(input, kernel_size, output_size=None, output_ratio=None, return_indices=False, _random_samples=None)[source]

Applies the 3D FractionalMaxPool operation over input. The output Tensor shape can be determined by either output_size or output_ratio, and the step size is determined by _random_samples. output_size will take effect when output_size and output_ratio are set at the same time. And output_size and output_ratio can not be None at the same time.

Refer to the paper Fractional MaxPooling by Ben Graham for more details.

The input and output data format can be "NCDHW". N is the batch size, C is the number of channels, D the feature depth, H is the feature height, and W is the feature width.

Warning

This is an experimental API that is subject to change or deletion.

Parameters
  • input (Tensor) – The input of FractionalMaxPool3d, which is a 4D or 5D tensor. Tensor of data type: float16, float32, double. Supported shape \((N, C, D_{in}, H_{in}, W_{in})\) or \((C, D_{in}, H_{in}, W_{in})\).

  • 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. The value must be a positive integer.

  • output_size (Union[int, tuple[int]], optional) – The shape of the target output_size, is an int number that represents depth, height and width, or a tuple of three int numbers that represent depth, height and width respectively. The value must be a positive integer. Default: None .

  • output_ratio (Union[float, tuple[float]], optional) – The ratio of target output shape to input shape. Specifying the size of the output tensor by using a ratio of the input size. Data type: float16, float32, double, and value is between (0, 1). Default: None .

  • return_indices (bool, optional) – Whether to return the indices of max value. Default: False .

  • _random_samples (Tensor, optional) – The random step of fractional_max_pool3d, which is a 3D tensor. Tensor of data type: float16, float32, double, and value is between [0, 1). Supported shape \((N, C, 3)\) or \((1, C, 3)\) . Default: None, the values of _random_samples will be randomly distributed using uniform distribution over an interval [0,1).

Returns

  • y (Tensor) - A tensor, the output of FractionalMaxPool3d. Has the same data type with input. Has the shape \((N, C, D_{out}, H_{out}, W_{out})\) or \((C, D_{out}, H_{out}, W_{out})\) , where \((D_{out}, H_{out}, W_{out})\) = output_size or \((D_{out}, H_{out}, W_{out})\) = output_ratio * \((D_{in}, H_{in}, W_{in})\) .

  • argmax (Tensor) - The indices along with the outputs, which is a Tensor, with the same shape as the y and int32 data type. It will output only when return_indices is True.

Raises
  • TypeError – If input is not a 4D or 5D tensor.

  • TypeError – If _random_samples is not a 3D tensor.

  • TypeError – If data type of input is not float16, float32, double, int32, int64.

  • TypeError – If dtype of _random_samples is not float16, float32, double.

  • TypeError – If dtype of argmax is not int32, int64.

  • TypeError – if _random_samples to have the different dtypes as input.

  • ValueError – If output_size is a tuple and if output_size length is not 3.

  • ValueError – If kernel_size is a tuple and if kernel_size length is not 3.

  • ValueError – If numbers in output_size or kernel_size is not positive.

  • ValueError – if output_size and output_ratio are None at the same time.

  • ValueError – If the first dimension size of input and _random_samples is not equal.

  • ValueError – If the second dimension size of input and _random_samples is not equal.

  • ValueError – If the third dimension size of _random_samples is not 3.

Supported Platforms:

GPU CPU

Examples

>>> import numpy as np
>>> from mindspore import Tensor, ops
>>> from mindspore import dtype as mstype
>>> x = Tensor(np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16])
...            .reshape([1, 1, 2, 2, 4]), mstype.float32)
>>> _random_samples = Tensor(np.array([0.7, 0.7, 0.7]).reshape([1, 1, 3]), mstype.float32)
>>> output, argmax = ops.fractional_max_pool3d(x, kernel_size=(1, 1, 1), output_size=(1, 1, 3),
...                                            _random_samples=_random_samples, return_indices=True)
>>> print(output)
[[[[[13. 14. 16.]]]]]
>>> print(argmax)
[[[[[12 13 15]]]]]
>>> output, argmax = ops.fractional_max_pool3d(x, kernel_size=(1, 1, 1), output_ratio=(0.5, 0.5, 0.5),
...                                            _random_samples=_random_samples, return_indices=True)
>>> print(output)
[[[[[13. 16.]]]]]
>>> print(argmax)
[[[[[12 15]]]]]