mindspore.ops.FractionalMaxPool3DWithFixedKsize

View Source On Gitee
class mindspore.ops.FractionalMaxPool3DWithFixedKsize(ksize, output_shape, data_format='NCDHW')[source]

Applies a 3D fractional max pooling to an input signal composed of multiple input planes. The max-pooling operation is applied in \((kD, kH, kW)\) regions by a stochastic step size determined by the target output size output_shape.

The number of output features is equal to the number of input planes.

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

The input and output data format can be “NCDHW” and “NDHWC”. 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
  • ksize (Union[float, tuple]) – Size of the pooling window. ksize can be a tuple of three values specify a shape \((k_D, k_H, k_W)\), or a single int K for \((K, K, K)\).

  • output_shape (Union[int, tuple]) – The target output shape. output_shape can be a tuple of three values specify a shape \((D_{out}, H_{out}, W_{out})\), or a single float S for \((S, S, S)\).

  • data_format (str, optional) – The optional value for data format. Currently support 'NCDHW' and 'NHDWC' . Default: 'NCDHW' .

Inputs:
  • x (Tensor) - The input of FractionalMaxPool3DWithFixedKsize, which is a 4D or 5D tensor. Tensor of data type : float16, float32, double, int32, int64. Supported shape \((N, C, D_{in}, H_{in}, W_{in})\) or \((N, D_{in}, H_{in}, W_{in}, C)\).

  • random_samples (Tensor) - The random step of FractionalMaxPool3DWithFixedKsize, which is a 3D tensor. Tensor of data type : float16, float32, double, and value is between (0, 1). Supported shape \((N, C, 3)\)

Outputs:
  • y (Tensor) - A tensor, the output of FractionalMaxPool3DWithFixedKsize. Has the same data type with x. Tensor of shape \((N, C, D_{out}, H_{out}, W_{out})\) or \((N, D_{out}, H_{out}, W_{out}, C)\).

  • argmax (Tensor) - A tensor, the indices along with the outputs. Has the same shape as the y and int32 or int64 data type.

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

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

  • TypeError – If data type of x 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.

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

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

  • ValueError – If numbers in output_shape or ksize is not positive.

  • ValueError – If data_format is neither ‘NCDHW’ nor ‘NDHWC’.

  • ValueError – If the first dimension size of input_x and random_samples is not equal.

  • ValueError – If the second dimension size of input_x and random_samples is not equal.

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

Supported Platforms:

Ascend 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)
>>> ksize = (1, 1, 1)
>>> output_shape = (1, 1, 2)
>>> net = ops.FractionalMaxPool3DWithFixedKsize(ksize = ksize, output_shape = output_shape)
>>> output, argmax = net(x, random_samples)
>>> print(output)
[[[[[13. 16.]]]]]
>>> print(argmax)
[[[[[12 15]]]]]