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.

Problem description

Agree to Privacy Statement

mindspore.nn.ZeroPad2d

class mindspore.nn.ZeroPad2d(padding)[source]

Pads the last two dimensions of input tensor with zero.

Parameters

padding (union[int, tuple]) – The padding size to pad the last two dimensions of input tensor. If is int, uses the same padding in boundaries of input’s last two dimensions. If is tuple and length of padding is 4 uses (padding_0, padding_1, padding_2, padding_3) to pad. If the input is x, the size of last dimension of output is padding_0+x.shape[1]+padding_1. The size of penultimate dimension of output is padding_2+x.shape[2]+padding_3. The remaining dimensions of the output are consistent with those of the input.

Returns

Tensor, the tensor after padding.

Raises
  • TypeError – If padding is not a tuple or int.

  • ValueError – If the length of padding is more than 4 or not a multiple of 2.

  • ValueError – If the output shape after padding is not positive.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import numpy as np
>>> from mindspore import Tensor
>>> from mindspore.nn import ZeroPad2d
>>> x = np.ones(shape=(1, 2, 3, 4)).astype(np.float32)
>>> x = Tensor(x)
>>> padding = (-1, 1, 0, 1)
>>> pad = ZeroPad2d(padding)
>>> out = pad(x)
>>> print(out)
[[[[1. 1. 1. 0.]
   [1. 1. 1. 0.]
   [1. 1. 1. 0.]
   [0. 0. 0. 0.]]
  [[1. 1. 1. 0.]
   [1. 1. 1. 0.]
   [1. 1. 1. 0.]
   [0. 0. 0. 0.]]]]
>>> print(out.shape)
(1, 2, 4, 4)