mindspore.nn.ConstantPad3d

class mindspore.nn.ConstantPad3d(padding, value)[source]

Using a given constant value to pads the last three dimensions of input tensor.

Parameters
  • padding (Union[int, tuple]) – The padding size to pad the last three dimensions of input tensor. If is int, uses the same padding in boundaries of input’s last three dimensions. If is tuple and length of padding is 6 uses (padding_0, padding_1, padding_2, padding_3, padding_4, padding_5) 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 size of 3rd to last dimension of output is \(padding\_4 + x.shape[-3] + padding\_5\). The remaining dimensions of the output are consistent with those of the input.

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

Returns

Tensor, the tensor after padding.

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

  • TypeError – If value is not int or float.

  • ValueError – If the length of padding is more than 6 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 ConstantPad3d
>>> x = np.ones(shape=(1, 2, 3, 4)).astype(np.float32)
>>> x = Tensor(x)
>>> padding = (-1, 1, 0, 1, 1, 0)
>>> value = 0.5
>>> pad3d = 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]]
  [[1.  1.  1.  0.5]
   [1.  1.  1.  0.5]
   [1.  1.  1.  0.5]
   [0.5 0.5 0.5 0.5]]
  [[1.  1.  1.  0.5]
   [1.  1.  1.  0.5]
   [1.  1.  1.  0.5]
   [0.5 0.5 0.5 0.5]]]]
>>> print(out.shape)
(1, 3, 4, 4)