mindspore.nn.ReflectionPad3d

class mindspore.nn.ReflectionPad3d(padding)[源代码]

使用反射的方式,以 input 的边界为对称轴,对 input 进行填充。

参数:
  • padding (union[int, tuple]) - 填充大小,如果输入为int,则对所有边界进行相同大小的填充;如果是tuple,则顺序为 \((pad\_left, pad\_right, pad\_up, pad\_down, pad\_front, pad\_back)\)

说明

ReflectionPad3d尚不支持5D Tensor输入。

输入:
  • x (Tensor) - 4D Tensor, shape为 \((N, D_{in}, H_{in}, W_{in})\)

输出:

Tensor,填充后的Tensor, shape为 \((N, D_{out}, H_{out}, W_{out})\)。其中 \(H_{out} = H_{in} + pad\_up + pad\_down\), \(W_{out} = W_{in} + pad\_left + pad\_right\), \(D_{out} = D_{in} + pad\_front + pad\_back\)

异常:
  • TypeError - padding 不是tuple或int。

  • TypeError - padding 中存在不是int的元素。

  • ValueError - padding 是tuple,且长度不能被2整除。

  • ValueError - padding 是tuple,且存在负数。

  • ValueError - padding 是tuple,且长度和Tensor的维度不匹配。

支持平台:

Ascend GPU CPU

样例:

>>> import numpy as np
>>> from mindspore import Tensor
>>> from mindspore.nn import ReflectionPad3d
>>> arr = np.arange(8).astype(np.float32).reshape((1, 2, 2, 2))
>>> x = Tensor(arr)
>>> # x has shape (1, 2, 2, 2)
>>> padding = (1, 1, 1, 0, 0, 1)
>>> pad3d = 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.]]]]