mindspore.mint.nn.ConstantPad2d

View Source On AtomGit
class mindspore.mint.nn.ConstantPad2d(padding, value)[source]

Pad the last 2-D dimensions of input tensor using padding and value.

For more information, please refer to mindspore.mint.nn.functional.pad().

Warning

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

Parameters
  • padding (Union[int, tuple, list]) –

    Specifies padding size.

    • If an int, the same padding is applied to all boundaries.

    • If a tuple or list, the order is \((\text{padding_left}, \text{padding_right}, \text{padding_top}, \text{padding_bottom})\).

  • value (Union[int, float]) – Specifies padding value.

Inputs:
  • input (Tensor) - The input tensor with shape \((N, *)\), where \(*\) means any number of additional dimensions.

Outputs:

Tensor, the tensor after padding.

Supported Platforms:

Ascend

Examples

>>> import mindspore
>>> x = mindspore.mint.ones((1, 2, 3, 4), dtype=mindspore.float32)
>>> padding = (1, 1, 0, 1)
>>> value = 0.5
>>> pad2d = mindspore.mint.nn.ConstantPad2d(padding, value)
>>> out = pad2d(x)
>>> print(out)
[[[[0.5  1.  1.  1.  1.  0.5]
   [0.5  1.  1.  1.  1.  0.5]
   [0.5  1.  1.  1.  1.  0.5]
   [0.5  0.5 0.5 0.5 0.5 0.5]]
  [[0.5  1.  1.  1.  1.  0.5]
   [0.5  1.  1.  1.  1.  0.5]
   [0.5  1.  1.  1.  1.  0.5]
   [0.5  0.5 0.5 0.5 0.5 0.5]]]]
>>> print(out.shape)
(1, 2, 4, 6)