mindspore.mint.nn.ConstantPad3d

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

Pad the last 3-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, pads all boundaries with the same amount.

    • If a tuple or list, it should be in the order \((\text{padding_left}, \text{padding_right}, \text{padding_top}, \text{padding_bottom}, \\ \text{padding_front}, \text{padding_back})\).

  • 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, 1, 0)
>>> value = 0.5
>>> pad3d = mindspore.mint.nn.ConstantPad3d(padding, value)
>>> out = pad3d(x)
>>> print(out)
[[[[0.5 0.5 0.5 0.5 0.5 0.5]
   [0.5 0.5 0.5 0.5 0.5 0.5]
   [0.5 0.5 0.5 0.5 0.5 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]]
  [[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, 3, 4, 6)