mindspore.ops.unfold

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

Extracts sliding local blocks from a batched input tensor. Format of the input Tensor is (N, C, H, W).

Warning

  • Currently, only 4-D input tensors (batched image-like tensors) are supported.

Parameters
  • input (Tensor) – 4-D Tensor. Support all real number data type.

  • kernel_size (Union[int, tuple[int], list[int]]) – The size of the kernel, should be two 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 dilation of the window, should be two 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 pad of the window, that must be a tuple/list of one or two or four int for height and width. If one int, pad_height = pad_width. If two int, pad_height = padding[0], pad_width = padding[1]. If four int, padding = [pad_height_top, pad_height_bottom, pad_width_left, pad_width_right] Default: 0.

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

Returns

A Tensor, with same type as input.

Raises
  • TypeError – If any data type of kernel_size, stride, dilation, kernel_size is not int, tuple or list.

  • ValueError – If kernel_size, dilation, stride value is not greater than zero or elements number more than 2.

  • ValueError – If padding value is less than zero.

Supported Platforms:

Ascend CPU

Examples

>>> x = Tensor(np.random.rand(4, 4, 32, 32), mindspore.float16)
>>> output = ops.unfold(x, kernel_size=3, dilation=1, stride=1)
>>> print(output.shape)
(4, 36, 30, 30)