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.

PR

Just a small problem.

I can fix it online!

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

View Source On Gitee
mindspore.mint.nn.functional.pad(input, pad, mode='constant', value=None)[source]

Pads the input tensor according to the pad.

Warning

circular mode has poor performance and is not recommended.

Parameters
  • input (Tensor) – Tensor of shape (N,), where means, any number of additional dimensions.

  • pad (Union[tuple[int], list[int], Tensor]) –

    Filling position of pad. len(pad)2 dimensions of input will be padded.

    Example: to pad only the last dimension of the input tensor, then pad has the form (padding_left,padding_right);

    Example: to pad the last 2 dimensions of the input tensor, then use (padding_left,padding_right,padding_top,padding_bottom);

    Example: to pad the last 3 dimensions, use (padding_left,padding_right,padding_top,padding_bottom,padding_front,padding_back) and so on.

  • mode (str, optional) –

    Pad filling mode, 'constant' , 'reflect' , 'replicate' or 'circular' . Default: 'constant' .

    For 'constant' mode, please refer to mindspore.nn.ConstantPad1d as an example to understand this filling pattern and extend the padding pattern to n dimensions.

    For 'reflect' mode, please refer to mindspore.nn.ReflectionPad1d as an example to understand this filling pattern. The reflect mode is used to pad the last three dimensions of 4D or 5D input, the last two dimensions of 3D or 4D input, or the last dimension of 2D or 3D input.

    For 'replicate' mode, please refer to mindspore.nn.ReplicationPad1d as an example to understand this filling pattern. The replicate mode is used to pad the last three dimensions of 4D or 5D input, the last two dimensions of 3D or 4D input, or the last dimension of 2D or 3D input.

    For 'circular' mode, the pixels from one edge of the image are wrapped around to the opposite edge, such that the pixel on the right edge of the image is replaced with the pixel on the left edge, and the pixel on the bottom edge is replaced with the pixel on the top edge. The circular mode is used to pad the last three dimensions of 4D or 5D input, the last two dimensions of 3D or 4D input, or the last dimension of 2D or 3D input.

  • value (Union[int, float, None], optional) – Valid only in 'constant' mode. Set the padding value in 'constant' mode. If the value is None, 0 is used as the default padding value. Default: None .

Returns

Tensor, the tensor after padding.

Raises
  • TypeError – If pad is not an int of tuple or int of list.

  • TypeError – If input is not a Tensor.

  • ValueError – If length of pad is not even.

  • ValueError – If length of pad is greater than 6.

  • ValueError – If mode is not 'constant' and value is neither None nor 0.

Supported Platforms:

Ascend

Examples

>>> import mindspore as ms
>>> from mindspore import mint
>>> import numpy as np
>>> x = ms.Tensor(np.arange(1 * 2 * 2 * 2).reshape((1, 2, 2, 2)), dtype=ms.float64)
>>> output = mint.nn.functional.pad(x, [1, 0, 0, 1], mode='constant', value=6.0)
>>> print(output)
[[[[6. 0. 1.]
   [6. 2. 3.]
   [6. 6. 6.]]
  [[6. 4. 5.]
   [6. 6. 7.]
   [6. 6. 6.]]]]