forked from mindspore-Ecosystem/mindspore
35 lines
2.3 KiB
ReStructuredText
35 lines
2.3 KiB
ReStructuredText
mindspore.ops.pad
|
||
==================
|
||
|
||
.. py:function:: mindspore.ops.pad(input_x, padding, mode='constant', value=None)
|
||
|
||
根据参数 `padding` 对输入进行填充。
|
||
|
||
参数:
|
||
- **input_x** (Tensor) - 输入Tensor,shape为 :math:`(N, *)`, :math:`*` 代表任意附加维度。
|
||
- **padding** (Union[tuple[int], list[int], Tensor]) - pad的填充位置。
|
||
:math:`\left\lfloor\frac{\text{len(padding)}}{2}\right\rfloor` 维度的 `input_x` 将会被填充。
|
||
|
||
- 示例:若只需要填充输入tensor的最后一个维度,则 `padding` 则的填充方式为 :math:`(\text{padding_left}, \text{padding_right})`;
|
||
- 示例:若只需要填充输入tensor的最后两个维度,则 `padding` 则的填充方式为 :math:`(\text{padding_left}, \text{padding_right}, \text{padding_top}, \text{padding_bottom})`;
|
||
- 示例:若只需要填充输入tensor的最后三个维度,则 `padding` 则的填充方式为 :math:`(\text{padding_left}, \text{padding_right}, \text{padding_top}, \text{padding_bottom}, \text{padding_front}, \text{padding_back}))`;
|
||
|
||
以此类推。
|
||
|
||
- **mode** (str,可选) - Pad的填充模式,可选择 "constant", "reflect" 或者 "replicate"。 默认值: "constant"。
|
||
|
||
- 对于 "constant" 模式,请参考 :class:`mindspore.nn.ConstantPad1d` 作为示例来理解这个填充模式,并将这个模式扩展到n维。
|
||
- 对于 "reflect" 模式,请参考 :class:`mindspore.nn.ReflectionPad1d` 作为示例来理解这个填充模式,并将这个模式扩展到n维。
|
||
- 对于 "replicate" 模式,请参考 :class:`mindspore.nn.ReplicationPad1d` 作为示例来理解这个填充模式,并将这个模式扩展到n维。
|
||
|
||
- **value** (Union[int, float, None],可选) - 仅在 "constant" 模式下生效,设置在 "constant" 模式下的填充值,如果值为None,则会使用0作为默认填充值。
|
||
|
||
返回:
|
||
填充后的Tensor。
|
||
|
||
异常:
|
||
- **TypeError** - `padding` 不是全为int的tuple或者list。
|
||
- **TypeError** - `input_x` 不是Tensor。
|
||
- **ValueError** - `paddings` 的shape不等于 2 * len(input_x)。
|
||
- **ValueError** - mode不为"constant"并且value不为None。
|