-
Notifications
You must be signed in to change notification settings - Fork 875
【PaddlePaddle Hackathon】6、在 Paddle 中新增 ZeroPad2d #4111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f996ff1
add doc of zeropad2d
gsq7474741 89a287d
add doc of zeropad2d v0.2
gsq7474741 5d16517
add doc of zeropad2d v0.2
gsq7474741 39b3446
add doc of zeropad2d v0.3
gsq7474741 f6b65b1
Update ZeroPad2D_cn.rst
TCChenlong aff38e7
add doc of zeropad2d v0.4
gsq7474741 412cd78
Merge remote-tracking branch 'origin/add_zeropad2d' into add_zeropad2d
gsq7474741 892d88d
Update Overview_cn.rst
TCChenlong 8000a9a
Update ZeroPad2D_cn.rst
TCChenlong 891deb0
add doc of zeropad2d v0.5
gsq7474741 d2e09c7
Merge remote-tracking branch 'origin/add_zeropad2d' into add_zeropad2d
gsq7474741 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| .. _cn_api_nn_ZeroPad2D: | ||
|
|
||
| ZeroPad2D | ||
| ------------------------------- | ||
| .. py:class:: paddle.nn.ZeroPad2D(padding, data_format="NCHW", name=None) | ||
|
|
||
| **ZeroPad2D** | ||
|
|
||
| 按照 padding 属性对输入进行零填充。 | ||
|
|
||
| 参数 | ||
| ::::::::: | ||
|
|
||
| - **padding** (Tensor | List[int] | int]) - 填充大小。如果是int,则在所有待填充边界使用相同的填充, | ||
| 否则填充的格式为[pad_left, pad_right, pad_top, pad_bottom]。 | ||
| - **data_format** (str) - 指定输入的format,可为 ``'NCHW'`` 或者 ``'NHWC'``,默认值为 ``'NCHW'``。 | ||
| - **name** (str, 可选) - 该参数供开发人员打印调试信息时使用,具体用法请参见 :ref:`api_guide_Name` ,缺省值为None。 | ||
|
|
||
| 返回:无 | ||
|
|
||
| 形状 | ||
| ::::::::: | ||
|
|
||
| - x(Tensor): ZeroPadD层的输入,要求形状为4-D,dtype为 ``'float32'`` 或 ``'float64'`` | ||
| - output(Tensor): 输出,形状为4-D,dtype与 ``'input'`` 相同 | ||
|
|
||
| 代码示例 | ||
| ::::::::: | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| import paddle | ||
| import paddle.nn as nn | ||
| import numpy as np | ||
|
|
||
| input_shape = (1, 1, 2, 3) | ||
| pad = [1, 0, 1, 2] | ||
| data = paddle.arange(np.prod(input_shape), dtype="float32").reshape(input_shape) + 1 | ||
|
|
||
| my_pad = nn.ZeroPad2D(padding=pad) | ||
| result = my_pad(data) | ||
|
|
||
| print(result) | ||
| # [[[[0. 0. 0. 0.] | ||
| # [0. 1. 2. 3.] | ||
| # [0. 4. 5. 6.] | ||
| # [0. 0. 0. 0.] | ||
| # [0. 0. 0. 0.]]]] | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| .. _cn_api_nn_functional_zeropad2d: | ||
|
|
||
| zeropad2d | ||
| ------------------------------- | ||
| .. py:function:: paddle.nn.functional.zeropad2d(x, padding, data_format="NCHW", name=None) | ||
|
|
||
| 该OP返回一个按照 ``padding`` 属性对 ``x`` 进行零填充的Tensor,数据类型与 ``x`` 相同。 | ||
|
|
||
| 参数 | ||
| :::::::::: | ||
| - **x** (Tensor) - Tensor,format可以为 ``'NCHW'``, ``'NHWC'`` ,默认值为 ``'NCHW'``,数据类型支持float16, float32, float64, int32, int64。 | ||
| - **padding** (Tensor | List[int] | Tuple[int]) - 填充大小。pad的格式为[pad_left, pad_right, pad_top, pad_bottom]; | ||
| - **data_format** (str) - 指定 ``x`` 的format,可为 ``'NCHW'``, ``'NHWC'``, 默认值为 ``'NCHW'``。 | ||
| - **name** (str, 可选) - 该参数供开发人员打印调试信息时使用,具体用法请参见 :ref:`api_guide_Name` ,缺省值为None。 | ||
|
|
||
| 返回 | ||
| :::::::::: | ||
| Tensor:对 ``x`` 进行 ``'pad'`` 的结果,数据类型和 ``x`` 相同。 | ||
|
|
||
| 代码示例 | ||
| :::::::::: | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| import paddle | ||
| import numpy as np | ||
|
|
||
| x_shape = (1, 1, 2, 3) | ||
| x = paddle.arange(np.prod(x_shape), dtype="float32").reshape(x_shape) + 1 | ||
| y = paddle.nn.functional.zeropad2d(x, [1, 2, 1, 1]) | ||
|
|
||
| # [[[[0. 0. 0. 0. 0. 0.] | ||
| # [0. 1. 2. 3. 0. 0.] | ||
| # [0. 4. 5. 6. 0. 0.] | ||
| # [0. 0. 0. 0. 0. 0.]]]] | ||
|
|
||
|
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.