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.mint.nn.functional.fold

mindspore.mint.nn.functional.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]dilation[d]×(kernel_size[d]1)1stride[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

Currently, only unbatched(3D) or batched(4D) image-like output tensors are supported.

Parameters
  • input (Tensor) – 2-D or 3-D Tensor.

  • output_size (Union[int, tuple[int], list[int]]) – The shape of the spatial dimensions of the output(i.e., output.shape[2:]).

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

Shape:
  • Input: (N,C×(kernel_size),L) or (C×(kernel_size),L)

  • Output: (N,C,output_size[0],output_size[1],...) or (C,output_size[0],output_size[1],...)

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

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

  • ValueError – If input.shape[-2] can't be divisible by the product of kernel_size.

  • ValueError – If input.shape[-1] is not equal to the calculated number of sliding blocks L.

Supported Platforms:

Ascend

Examples

>>> import numpy as np
>>> from mindspore import Tensor, mint
>>> x = Tensor(np.random.rand(16, 64, 25).astype(np.float32))
>>> output = mint.nn.functional.fold(x, (8, 8), [2, 2], [2, 2], [2, 2], [2, 2])
>>> print(output.shape)
(16, 16, 8, 8)