mindspore.mint.nn.MaxUnpool2d

View Source On AtomGit
class mindspore.mint.nn.MaxUnpool2d(kernel_size, stride=None, padding=0)[source]

Compute the inverse of MaxPool2d.

MaxUnpool2d keeps the maximal value and sets all positions of non-maximal values to zero. Typically the input is of shape \((N, C, H_{in}, W_{in})\) or \((C, H_{in}, W_{in})\), and the output is of shape \((N, C, H_{out}, W_{out})\) or \((C, H_{out}, W_{out})\). The operation is as follows.

\[\begin{split}\begin{array}{ll} \\ H_{out} = (H_{in} - 1) \times stride[0] - 2 \times padding[0] + kernel\_size[0] \\ W_{out} = (W_{in} - 1) \times stride[1] - 2 \times padding[1] + kernel\_size[1] \\ \end{array}\end{split}\]

Warning

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

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

  • stride (Union[int, tuple[int]], optional) – The distance of kernel moving, an int number that represents the height and width of movement are both stride, 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.

  • padding (Union[int, tuple[int]], optional) – The pad value to be filled. Default 0. If padding is an integer, the paddings of height and width are the same, equal to padding. If padding is a tuple of two integers, the padding of height and width equal to padding[0] and padding[1] correspondingly.

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

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

  • output_size (tuple[int], optional) - The target output size. Default None. If output_size == (), then the shape of output is computed by kernel_size, stride and padding. If output_size != (), then output_size must be \((N, C, H, W)\), \((C, H, W)\) or \((H, W)\) and output_size must belong to \([(N, C, H_{out} - stride[0], W_{out} - stride[1]), (N, C, H_{out} + stride[0], W_{out} + stride[1])]\).

Outputs:

Tensor, with shape \((N, C, H_{out}, W_{out})\) or \((C, H_{out}, W_{out})\).

Supported Platforms:

Ascend

Examples

>>> import mindspore
>>> input = mindspore.tensor([[[[0, 1], [8, 9]]]], mindspore.float32)
>>> indices = mindspore.tensor([[[[0, 1], [2, 3]]]], mindspore.int64)
>>> net = mindspore.mint.nn.MaxUnpool2d(1, stride=1, padding=0)
>>> output = net(input, indices)
>>> print(output.asnumpy())
[[[[0. 1.]
   [8. 9.]]]]