mindspore.nn.MaxUnpool1d

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

Computes the inverse of mindspore.nn.MaxPool1d.

MaxUnpool1d keeps the maximal value and set all position of non-maximal values to zero. Typically the input is of shape \((N, C, H_{in})\) or \((C, H_{in})\), and the output is of shape \((N, C, H_{out})\) or \((C, H_{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] \\ \end{array}\end{split}\]
Parameters
  • kernel_size (Union[int, tuple[int]]) – The size of kernel used to take the maximum value.

  • stride (Union[int, tuple[int]]) – The distance of kernel moving, 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 .

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

  • 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, H_{in} - 1]\). 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, H)\) , \((C, H)\) or \((H)\) and output_size must belong to \([(N, C, H_{out} - stride[0]), (N, C, H_{out} + stride[0])]\).

Outputs:

Tensor, with shape \((N, C, H_{out})\) or \((C, H_{out})\), 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, padding (also support 0 and (0)) or kernel_size is not positive.

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

  • ValueError – If x whose length is not 2 or 3.

  • ValueError – If type of output_size is not tuple.

  • ValueError – If output_size whose length is not 0, 2 or 3.

  • 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([[2, 4, 6, 8]]).astype(np.float32))
>>> indices = ms.Tensor(np.array([[1, 3, 5, 7]]).astype(np.int64))
>>> maxunpool1d = ms.nn.MaxUnpool1d(kernel_size =2, stride=2, padding=0)
>>> output = maxunpool1d(x, indices)
>>> print(output.asnumpy())
[[0. 2. 0. 4. 0. 6. 0. 8.]]