mindspore.nn.ReplicationPad3d

查看源文件
class mindspore.nn.ReplicationPad3d(padding)[源代码]

根据 padding 对输入 x 的DHW维度进行填充。

参数:
  • padding (union[int, tuple]) - 填充 x 最后三个维度的大小。

    • 如果输入为int,则对所有边界进行相同大小的填充。

    • 如果是tuple,则顺序为 \((\text{padding_left}, \text{padding_right}, \text{padding_top}, \text{padding_bottom}, \text{padding_front}, \text{padding_back})\)

输入:
  • x (Tensor) - 维度为4D或5D的Tensor,shape为 \((C, D_{in}, H_{in}, W_{in})\)\((N, C, D_{in}, H_{in}, W_{in})\)

输出:

Tensor,填充后的Tensor,shape为 \((C, D_{out}, H_{out}, W_{out})\)\((N, C, D_{out}, H_{out}, W_{out})\)。 其中 \(D_{out} = D_{in} + \text{padding_front} + \text{padding_back}\)\(H_{out} = H_{in} + \text{padding_top} + \text{padding_bottom}\)\(W_{out} = W_{in} + \text{padding_left} + \text{padding_right}\)

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

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

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

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

支持平台:

GPU

样例:

>>> import numpy as np
>>> import mindspore as ms
>>> pad3d = ms.nn.ReplicationPad3d(1)
>>> input = ms.Tensor(np.arange(0, 9).reshape(1, 1, 1, 3, 3), ms.float32)
>>> out = pad3d(input)
>>> print(out)
[[[[[0. 0. 1. 2. 2.]
    [0. 0. 1. 2. 2.]
    [3. 3. 4. 5. 5.]
    [6. 6. 7. 8. 8.]
    [6. 6. 7. 8. 8.]]
   [[0. 0. 1. 2. 2.]
    [0. 0. 1. 2. 2.]
    [3. 3. 4. 5. 5.]
    [6. 6. 7. 8. 8.]
    [6. 6. 7. 8. 8.]]
   [[0. 0. 1. 2. 2.]
    [0. 0. 1. 2. 2.]
    [3. 3. 4. 5. 5.]
    [6. 6. 7. 8. 8.]
    [6. 6. 7. 8. 8.]]]]]