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.fold

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

Combines an array of sliding local blocks into a large containing tensor.

Consider a batched input tensor of shape (N,C×(kernel_size),L) , where N is the batch dimension, 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=doutput_size[d]+2×padding[d]dilations[d]×(kernel_size[d]1)1strides[d]+1,

where d is over all spatial dimensions.

Therefore, output_size is the spatial shape of the large containing tensor of the sliding local blocks.

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

Warning

  • The input must be a 3-dimensional Tensor with shape (N,C×(kernel_size),L) .

  • The output must be a 4-dimensional Tensor with shape (N,C,output_size[0],output_size[1],...) .

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

  • output_size (Tensor) – 1D tensor with 2 elements of data type int.

  • 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 size of the dilation, 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 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 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 output_size, kernel_size, stride, dilation, padding data type is not int, tuple or list.

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

  • ValueError – If padding value is less than zero or elements number more than 2.

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

  • ValueError – If input.shape[2] 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, 64, 25), dtype=mstype.float32)
>>> output_size = Tensor(input_data=[8, 8], dtype=mstype.int32)
>>> output = ops.fold(x, output_size, [2, 2], [2, 2], [2, 2], [2, 2])
>>> print(output.shape)
(16, 16, 8, 8)