modify pad docs

This commit is contained in:
fengyihang 2022-11-17 19:47:28 +08:00
parent 79d497a087
commit 0c1ec2c269
2 changed files with 21 additions and 10 deletions

View File

@ -1,5 +1,5 @@
mindspore.ops.pad
=================
==================
.. py:function:: mindspore.ops.pad(input_x, padding, mode='constant', value=None)
@ -9,14 +9,19 @@ mindspore.ops.pad
- **input_x** (Tensor) - 输入Tensorshape为 :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}))`;
- 示例若只需要填充输入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维。
- 对于 "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作为默认填充值。
返回:

View File

@ -2407,17 +2407,22 @@ def pad(input_x, padding, mode='constant', value=None):
padding (Union[tuple[int], list[int], Tensor]): Filling position of pad.
:math:`\left\lfloor\frac{\text{len(padding)}}{2}\right\rfloor` dimensions
of `input_x` will be padded.
Example: to pad only the last dimension of the input tensor, then
:attr:`padding` has the form
:math:`(\text{padding\_left}, \text{padding\_right})`;
Example: to pad the last 2 dimensions of the input tensor, then use
:math:`(\text{padding\_left}, \text{padding\_right},`
:math:`\text{padding\_top}, \text{padding\_bottom})`;
Example: to pad the last 3 dimensions, use
:math:`(\text{padding\_left}, \text{padding\_right},`
:math:`\text{padding\_top}, \text{padding\_bottom}`
:math:`\text{padding\_front}, \text{padding\_back})`.and so on.
:math:`\text{padding\_front}, \text{padding\_back})` and so on.
mode (str, optional): Pad filling mode, "constant", "reflect" or "replicate". Default: "constant".
For "constant" mode, please refer to :class:`mindspore.nn.ConstantPad1d` as an example to understand
this filling pattern and extend the padding pattern to n dimensions.
@ -2426,8 +2431,9 @@ def pad(input_x, padding, mode='constant', value=None):
For "replicate" mode, please refer to :class:`mindspore.nn.ReplicationPad1d` as an example
and extend the padding pattern to n dimensions.
value (Union[int, float, None], optional): Valid only in "constant" mode, fill value for 'constant' padding,
if the value is None, the default value 0 is used.
value (Union[int, float, None], optional): Valid only in "constant" mode.
Set the padding value in "constant" mode. If the value is None, 0 is used as the default padding value.
Returns:
Tensor, the tensor after padding.