mindspore.nn.ReflectionPad3d

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

Pad the given tensor in a reflecting way using the input boundaries as the axis of symmetry.

Note

ReflectionPad3d has not supported 5D tensor yet.

Parameters

padding (union[int, tuple]) – The padding size to pad the input tensor. If padding is an integer: all directions will be padded with the same size. If padding is a tuple: uses \((pad\_left, pad\_right, pad\_up, pad\_down, pad\_front, pad\_back)\) to pad.

Inputs:
  • x (Tensor) - 4D Tensor, shape: \((N, D_{in}, H_{in}, W_{in})\).

Outputs:

Tensor, after padding. Shape: \((N, D_{out}, H_{out}, W_{out})\), where \(D_{out} = D_{in} + pad\_front + pad\_back\), \(H_{out} = H_{in} + pad\_up + pad\_down\) \(W_{out} = W_{in} + pad\_left + pad\_right\).

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

  • TypeError – If there is an element in 'padding' that is not int.

  • ValueError – If the length of 'padding' is not divisible by 2.

  • ValueError – If there is an element in 'padding' that is negative.

  • ValueError – If the there is a dimension mismatch between the padding and the tensor.

Supported Platforms:

Ascend GPU CPU

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.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.]]]]