mindspore.nn.MaxUnpool3d

View Source On Gitee
class mindspore.nn.MaxUnpool3d(kernel_size, stride=None, padding=0)[source]

Computes the inverse of mindspore.nn.MaxPool3d.

MaxUnpool3d keeps the maximal value and set all position of non-maximal values to zero. Typically the input is of shape (N,C,Din,Hin,Win) or (C,Din,Hin,Win), and the output is of shape (N,C,Dout,Hout,Wout) or (C,Dout,Hout,Wout). The operation is as follows.

Dout=(Din1)×stride[0]2×padding[0]+kernel_size[0]Hout=(Hin1)×stride[1]2×padding[1]+kernel_size[1]Wout=(Win1)×stride[2]2×padding[2]+kernel_size[2]
Parameters
  • kernel_size (Union[int, tuple[int]]) – The size of kernel used to take the maximum value, 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.

  • stride (Union[int, tuple[int]]) – The distance of kernel moving, an int number that represents the depth, height and width of movement are both stride, or a tuple of three int numbers that represent depth, height and width of movement respectively. If stride is None, then stride equal to kernel_size. Default: None .

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

Inputs:
  • x (Tensor) - The input Tensor to invert. Tensor of shape (N,C,Din,Hin,Win) or (C,Din,Hin,Win).

  • indices (Tensor) - Max values' index represented by the indices. Tensor of shape must be same with input 'x'. Values of indices must belong to [0,Din×Hin×Win1]. Data type must be in int32 or int64.

  • output_size (tuple[int], optional) - The output size. Default: None . If output_size is None, then the shape of output computed by kernel_size, stride and padding. If output_size is not None, then output_size must be (N,C,D,H,W) , (C,D,H,W) or (D,H,W) and output_size must belong to [(N,C,Doutstride[0],Houtstride[1],Woutstride[2]),(N,C,Dout+stride[0],Hout+stride[1],Wout+stride[2])].

Outputs:

Tensor, with shape (N,C,Dout,Hout,Wout) or (C,Dout,Hout,Wout), with the same data type with x.

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

  • TypeError – If kernel_size, stride or padding is neither an int nor a tuple.

  • ValueError – If numbers in stride or padding (also support 0 and (0, 0, 0)) or kernel_size is not positive.

  • ValueError – If the shape of x and indices are not equal.

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

  • ValueError – If x whose length is not 4 or 5.

  • ValueError – If output_size whose length is not 0, 4 or 5.

  • ValueError – If output_size whose type is not tuple.

  • ValueError – If output_size is not close to output size computed by attr kernel_size, stride, padding.

Supported Platforms:

GPU CPU

Examples

>>> import mindspore as ms
>>> import numpy as np
>>> x = ms.Tensor(np.array([[[[[0, 1], [8, 9]]]]]).astype(np.float32))
>>> indices= ms.Tensor(np.array([[[[[0, 1], [2, 3]]]]]).astype(np.int64))
>>> maxunpool3d = ms.nn.MaxUnpool3d(kernel_size=1, stride=1, padding=0)
>>> output = maxunpool3d(x, indices)
>>> print(output.asnumpy())
[[[[[0. 1.]
    [8. 9.]]]]]