mindspore.ops.Col2Im

class mindspore.ops.Col2Im(kernel_size, dilation=1, padding=0, stride=1)[source]

Combines an array of sliding local blocks into a large containing tensor. It is usually used to reconstruct an image from a set of image patches(or sliding local blocks).

Consider a batched input tensor containing sliding local blocks, e.g., patches of images, of shape \((N, C, \prod(\text{kernel_size}), L)\), where \(N\) is batch dimension, \(C\) is channel dimension, \(\prod(\text{kernel_size})\) is the block size, and \(L\) is the total number of blocks. This operation combines these local blocks into the large output tensor of shape \((N, C, \text{output_size}[0], \text{output_size}[1], \dots)\) by summing the overlapping values.

\[L = \prod_d \left\lfloor\frac{\text{output_size}[d] + 2 \times \text{padding}[d] % - \text{dilation}[d] \times (\text{kernel_size}[d] - 1) - 1}{\text{stride}[d]} + 1\right\rfloor\]

where \(d\) is over all spatial dimensions. The padding, stride and dilation arguments specify how the sliding blocks are retrieved.

Warning

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

Parameters
  • kernel_size (Union[int, tuple[int], list[int]]) – The size of the kernel, should be two positive int for height and width. If type is int, it means that height equal with width. Must be specified.

  • dilation (Union[int, tuple[int], list[int]], optional) – The size of the dilation, should be two positive int for height and width. If type is int, it means that height equal with width. Default: 1 .

  • padding (Union[int, tuple[int], list[int]], optional) – The size of the padding, should be two int for height and width. If type is int, it means that height equal with width. Default: 0 .

  • stride (Union[int, tuple[int], list[int]], optional) – The size of the stride, should be two positive int for height and width. If type is int, it means that height equal with width. Default: 1 .

Inputs:
  • x (Tensor) - 4D input Tensor.

  • output_size (Tensor) - 1D tensor with 2 elements of data type int32 or int64.

Outputs:

Tensor, a 4-D Tensor with same type of input x.

Raises
  • TypeError – If dtype of kernel_size , dilation , padding or stride is not in Union[int, tuple[int], list[int]].

  • ValueError – If values in kernel_size , dilation , padding or stride are not greater than zero or any one of them has more than 2 elements.

  • ValueError – If x.shape[2] != kernel_size[0] * kernel_size[1].

  • ValueError – If x.shape[3] does not match the calculated number of sliding blocks.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import numpy as np
>>> from mindspore import Tensor, ops
>>> from mindspore import dtype as mstype
>>> x = Tensor(input_data=np.random.rand(16, 16, 4, 25), dtype=mstype.float32)
>>> output_size = Tensor(input_data=[8, 8], dtype=mstype.int32)
>>> col2im = ops.Col2Im(kernel_size=[2, 2], dilation=[2, 2], padding=[2, 2], stride=[2, 2])
>>> y = col2im(x, output_size)
>>> print(y.shape)
(16, 16, 8, 8)