Document feedback

Question document fragment

When a question document fragment contains a formula, it is displayed as a space.

Submission type
issue

It's a little complicated...

I'd like to ask someone.

Please select the submission type

Problem type
Specifications and Common Mistakes

- Specifications and Common Mistakes:

- Misspellings or punctuation mistakes,incorrect formulas, abnormal display.

- Incorrect links, empty cells, or wrong formats.

- Chinese characters in English context.

- Minor inconsistencies between the UI and descriptions.

- Low writing fluency that does not affect understanding.

- Incorrect version numbers, including software package names and version numbers on the UI.

Usability

- Usability:

- Incorrect or missing key steps.

- Missing main function descriptions, keyword explanation, necessary prerequisites, or precautions.

- Ambiguous descriptions, unclear reference, or contradictory context.

- Unclear logic, such as missing classifications, items, and steps.

Correctness

- Correctness:

- Technical principles, function descriptions, supported platforms, parameter types, or exceptions inconsistent with that of software implementation.

- Incorrect schematic or architecture diagrams.

- Incorrect commands or command parameters.

- Incorrect code.

- Commands inconsistent with the functions.

- Wrong screenshots.

- Sample code running error, or running results inconsistent with the expectation.

Risk Warnings

- Risk Warnings:

- Lack of risk warnings for operations that may damage the system or important data.

Content Compliance

- Content Compliance:

- Contents that may violate applicable laws and regulations or geo-cultural context-sensitive words and expressions.

- Copyright infringement.

Please select the type of question

Problem description

Describe the bug so that we can quickly locate the problem.

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.

Consider a batched input tensor of shape (N,C,), where N is the batch dimension, C is the channel dimension, and represent arbitrary spatial dimensions. This operation flattens each sliding Kernel_size- sized block within the spatial dimensions of input x into a column (i.e., last dimension) of a 3-D output tensor of shape (N,C×(kernel_size),L), where C×(kernel_size) is the total number of values within each block (a block has (kernel_size) spatial locations each containing a C-channeled vector), and L is the total number of such blocks:

L=dspatial_size[d]+2×pads[d]dilations[d]×(kernel_size[d]1)1strides[d]+1,

where spatial_size is formed by the spatial dimensions of input x ( above), and d is over all spatial dimensions.

Therefore, indexing output at the last dimension (column dimension) gives all values within a certain block.

The dilation, padding and stride arguments specify how the sliding blocks are retrieved.

Warning

  • The output is a 3-dimensional Tensor whose shape is (N,C×(kernel_size),L) .

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

Parameters
  • input (Tensor) – 4-D Tensor, supported dtypes: float16, float32, float64, complex64 and complex128.

  • 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 int for height and width. Default: 0 .

    • If one int, pad_height = pad_width.

    • If two int, pad_height = padding[0], pad_width = padding[1].

  • 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 . And its shape is as described above.

Raises
  • TypeError – If any data type of kernel_size, stride, dilation, padding 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 GPU CPU

Examples

>>> import mindspore
>>> import numpy as np
>>> from mindspore import Tensor, ops
>>> x = Tensor(np.random.rand(4, 4, 32, 32), mindspore.float64)
>>> output = ops.unfold(x, kernel_size=3, dilation=1, stride=1)
>>> print(output.shape)
(4, 36, 900)