mindspore.ops.MaxUnpool2D

class mindspore.ops.MaxUnpool2D(ksize, strides=0, pads=0, output_shape=(), data_format='NCHW')[source]

Calculates the partial inverse of MaxPool2D operation.

Since MaxPool2D loses non-maximal values, it is not fully invertible. Therefore, MaxUnpool2D takes the output of MaxPool2D, including the indices of the maximal values, and computes a partial inverse where all non-maximal values are set to zero. Typically the input is of shape \((N, C, H_{in}, W_{in})\) , the output is of shape \((N, C, H_{out}, W_{out})\) , the operation is as follows:

\[\begin{split}\begin{array}{ll} \\ H_{out} = (H{in} - 1) \times strides[0] - 2 \times pads[0] + ksize[0] \\ W_{out} = (W{in} - 1) \times strides[1] - 2 \times pads[1] + ksize[1] \\ \end{array}\end{split}\]

Warning

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

Parameters
  • ksize (Union[int, tuple[int]]) – The size of kernel used to take the maximum value, is an int number that represents height and width of the kernel, or a tuple of two int numbers that represent height and width respectively.

  • strides (Union[int, tuple[int]], optional) –

    The strides of kernel moving. If strides is 0 or (0, 0), then strides equal to ksize . Default: 0 .

    • An int number that represents the height and width of movement are both strides .

    • A tuple of two int numbers that represent height and width of movement respectively.

  • pads (Union[int, tuple[int]], optional) –

    The pad value to be filled. Default: 0 .

    • If pads is an integer, the paddings of height and width are the same, equal to pads.

    • If pads is a tuple of two integers, the padding of height and width equal to pads[0] and pads[1] correspondingly.

  • output_shape (tuple[int], optional) –

    The target output size is an optional input. Default: () .

    • If \(output\_shape == ()\) , then the shape of output computed by kszie, strides and pads .

    • If \(output\_shape != ()\) , then output_shape must be \((N, C, H, W)\) or \((N, H, W, C)\) and output_shape must belong to \([(N, C, H_{out} - strides[0], W_{out} - strides[1]), (N, C, H_{out} + strides[0], W_{out} + strides[1])]\).

  • data_format (str, optional) – The optional value for data format. Currently support "NCHW" and "NHWC" . Default: "NCHW" .

Inputs:
  • x (Tensor) - The input Tensor to invert. Tensor of shape \((N, C, H_{in}, W_{in})\) or \((N, H_{in}, W_{in}, C)\).

  • argmax (Tensor) - Max values' index represented by the argmax. Tensor of shape must be same with input x. Values of argmax must belong to \([0, H_{in} \times W_{in} - 1]\). Data type must be in int32 or int64.

Outputs:

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

Raises
  • TypeError – If data type of x or argmax is not supported.

  • TypeError – If ksize, strides or pads is neither int nor tuple.

  • ValueError – If numbers in strides (also support 0 and (0, 0)) or ksize is not positive.

  • ValueError – If numbers in pads is negative.

  • ValueError – If ksize, strides or pads is a tuple whose length is not equal to 2.

  • ValueError – If data_format is not a str or is neither NCHW nor NHWC.

  • ValueError – If output_shape whose length is neither 0 or 4.

  • ValueError – If output_shape is not close to output size computed by attr ksize, strides and pads.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import numpy as np
>>> from mindspore import Tensor, ops
>>> x = Tensor(np.array([[[[0, 1], [8, 9]]]]).astype(np.float32))
>>> argmax = Tensor(np.array([[[[0, 1], [2, 3]]]]).astype(np.int64))
>>> maxunpool2d = ops.MaxUnpool2D(ksize=1, strides=1, pads=0)
>>> output = maxunpool2d(x, argmax)
>>> print(output.asnumpy())
[[[[0. 1.]
    [8. 9.]]]]