mindspore.mint.nn.ReflectionPad3d

class mindspore.mint.nn.ReflectionPad3d(padding)[source]

Pad the last 3 dimension of input tensor using the reflection of the input boundary.

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.

Inputs:
  • input (Tensor) - 4D or 5D input Tensor with shape: \((N, D_{in}, H_{in}, W_{in})\) or \((N, C, D_{in}, H_{in}, W_{in})\).

Outputs:

Tensor, the tensor after padding.

Raises
  • TypeError – If padding is not an integer of a list or tuple of 6 integers.

  • TypeError – If input is not Tensor.

  • ValueError – If padding contains negative value.

  • ValueError – If padding is a tuple or list, and the length does not match the tensor dimension.

Supported Platforms:

Ascend

Examples

>>> import numpy as np
>>> import mindspore as ms
>>> arr = np.arange(8).astype(np.float32).reshape((1, 2, 2, 2))
>>> x = ms.Tensor(arr)
>>> # x has shape (1, 2, 2, 2)
>>> padding = (1, 1, 1, 0, 0, 1)
>>> pad3d = ms.mint.nn.ReflectionPad3d(padding)
>>> out = pad3d(x)
>>> # The first dimension of x remains the same.
>>> # The second dimension of x: D_out = D_in + pad_front + pad_back = 2 + 0 + 1 = 3
>>> # The third dimension of x: H_out = H_in + pad_up + pad_down = 2 + 1 + 0 = 3
>>> # The last dimension of x: W_out = W_in + pad_left + pad_right = 2 + 1 + 1 = 4
>>> # The shape of out is (1, 3, 3, 4)
>>> print(out)
[[[[3. 2. 3. 2.]
   [1. 0. 1. 0.]
   [3. 2. 3. 2.]]
  [[7. 6. 7. 6.]
   [5. 4. 5. 4.]
   [7. 6. 7. 6.]]
  [[3. 2. 3. 2.]
   [1. 0. 1. 0.]
   [3. 2. 3. 2.]]]]