未验证 提交 526f2136 编写于 作者: L littletomatodonkey 提交者: GitHub

fix pad2d example code (#2697)

* test=develop, add addmm doc

* add addmm doc

* test=develop, add addmm doc

* fix pad2d example code

* revert addmm

* fix doc
上级 565c3d49
......@@ -11,16 +11,14 @@ pad2d
该OP依照 paddings 和 mode 属性对input进行2维 ``pad`` 。
参数:
- **input** (Variable) - 类型为float32的4-D Tensor, format为 `[N, C, H, W]` 或 `[N, H, W, C]` 。
- **paddings** (Variable | List[int32]) - 填充大小。如果paddings是一个List,它必须包含四个整数 `[padding_top, padding_bottom, padding_left, padding_right]` 。
如果paddings是Variable, 则是类型为int32 的1-D Tensor,shape是 `[4]` 。默认值为 `[0,0,0,0]` 。
- **input** (Tensor) - 类型为float32的4-D Tensor, 格式为 `[N, C, H, W]` 或 `[N, H, W, C]` 。
- **paddings** (Tensor | List[int32]) - 填充大小。如果paddings是一个List,它必须包含四个整数 `[padding_top, padding_bottom, padding_left, padding_right]` 。
如果paddings是Tensor, 则是类型为int32 的1-D Tensor,形状是 `[4]` 。默认值为 `[0,0,0,0]` 。
- **mode** (str) - padding的三种模式,分别为 `'constant'` (默认)、 `'reflect'` 、 `'edge'` 。 `'constant'` 为填充常数 `pad_value` , `'reflect'` 为填充以input边界值为轴的映射, `'edge'` 为填充input边界值。具体结果可见以下示例。默认值为 `'constant'` 。
- **pad_value** (float32) - 以 `'constant'` 模式填充区域时填充的值。默认值为0.0。
- **data_format** (str) - 指定input的format,可为 `'NCHW'` 和 `'NHWC'` ,默认值为 `'NCHW'` 。
- **name** (str, 可选) - 该参数供开发人员打印调试信息时使用,具体用法请参见 :ref:`api_guide_Name` ,缺省值为None。
返回: 对input进行2维 ``pad`` 的结果,数据类型和input一样的4-D Tensor。
返回类型:Variable
- **data_format** (str) - 指定input的格式,可为 `'NCHW'` 和 `'NHWC'` ,默认值为 `'NCHW'` 。
- **name** (str, 可选) - 该参数供开发人员打印调试信息时使用,具体用法请参见 :ref:`api_guide_Name` ,默认值为None。
返回:Tensor,对input进行2维 pad 的结果,数据类型和input一样的4-D Tensor。
**示例**:
......@@ -57,6 +55,30 @@ pad2d
.. code-block:: python
import paddle.fluid as fluid
data = fluid.data(name='data', shape=[None, 3, 32, 32], dtype='float32')
result = fluid.layers.pad2d(input=data, paddings=[0, 1, 2, 3], mode='reflect')
import numpy as np
import paddle
import paddle.nn.functional as F
# example 1
x_shape = (1, 1, 3, 4)
x = np.arange(np.prod(x_shape), dtype=np.float32).reshape(x_shape) + 1
tensor_x = paddle.to_tensor(x)
y = F.pad2d(tensor_x, paddings=[1, 2, 2, 1], pad_value=1, mode='constant')
print(y.numpy())
# [[[[ 1. 1. 1. 1. 1. 1. 1.]
# [ 1. 1. 1. 2. 3. 4. 1.]
# [ 1. 1. 5. 6. 7. 8. 1.]
# [ 1. 1. 9. 10. 11. 12. 1.]
# [ 1. 1. 1. 1. 1. 1. 1.]
# [ 1. 1. 1. 1. 1. 1. 1.]]]]
# example 2
x_shape = (1, 1, 2, 3)
x = np.arange(np.prod(x_shape), dtype=np.float32).reshape(x_shape) + 1
tensor_x = paddle.to_tensor(x)
y = F.pad2d(tensor_x, paddings=[1, 1, 1, 1], mode='reflect')
print(y.numpy())
# [[[[5. 4. 5. 6. 5.]
# [2. 1. 2. 3. 2.]
# [5. 4. 5. 6. 5.]
# [2. 1. 2. 3. 2.]]]]
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册