[API 2.0] add pool2d3d API,test=develop#26331
[API 2.0] add pool2d3d API,test=develop#26331jzhang533 merged 12 commits intoPaddlePaddle:developfrom LDOUBLEV:API
Conversation
|
Thanks for your contribution! |
| return padding | ||
|
|
||
|
|
||
| def max_pool2d(input, |
| kernel_size = utils.convert_to_list(kernel_size, 2, 'pool_size') | ||
| stride = utils.convert_to_list(stride, 2, 'pool_stride') | ||
|
|
||
| data_format = "NCHW" |
There was a problem hiding this comment.
这块作为参数传进来吧?x可能试nhwc的
| return (pool_out, mask) if return_indices else pool_out | ||
|
|
||
|
|
||
| def avg_pool2d(input, |
| padding_algorithm = "SAME" | ||
| padding = [0, 0, 0] | ||
|
|
||
| data_format = "NCDHW" |
| mask = helper.create_variable_for_type_inference(dtype) | ||
| outputs = {"Out": pool_out, "Mask": mask} | ||
|
|
||
| helper.append_op( |
There was a problem hiding this comment.
动态图模式用core.ops.xxx?
python/paddle/nn/layer/common.py
Outdated
| self.name = name | ||
|
|
||
| def forward(self, input): | ||
| return F.max_pool3d( |
python/paddle/nn/layer/common.py
Outdated
| None by default. | ||
|
|
||
| Returns: | ||
| Variable: The output tensor of pooling result. The data type is same as input tensor. |
python/paddle/nn/layer/common.py
Outdated
| H is the height of the feature, D is the depth of the feature, and W is the width of the feature. | ||
|
|
||
| Args: | ||
| input (Variable): The input tensor of pooling operator, which is a 5-D tensor with |
python/paddle/nn/layer/common.py
Outdated
| self.count_include_pad = count_include_pad | ||
| self.name = name | ||
|
|
||
| def forward(self, inputs): |
| from .pooling import pool3d #DEFINE_ALIAS | ||
| from .pooling import adaptive_pool2d #DEFINE_ALIAS | ||
| from .pooling import adaptive_pool3d #DEFINE_ALIAS | ||
| from .pooling import avg_pool2d |
There was a problem hiding this comment.
加上 #DEFINE_ALIAS 标示,做api映射
python/paddle/nn/layer/__init__.py
Outdated
| from .common import UpSample #DEFINE_ALIAS | ||
| from .common import AvgPool2d | ||
| from .common import MaxPool2d | ||
| from .common import AvgPool3d |
python/paddle/nn/layer/common.py
Outdated
|
|
||
| # max pool2d | ||
| input = paddle.to_variable(np.random.uniform(-1, 1, [1, 3, 32, 32]).astype(np.float32)) | ||
| output = F.avg_pool2d(input, |
python/paddle/nn/layer/common.py
Outdated
|
|
||
| def __init__(self, | ||
| kernel_size=-1, | ||
| stride=1, |
There was a problem hiding this comment.
stride 的默认值应该是None ,不是1;
以及注意None时候的行为
python/paddle/nn/layer/common.py
Outdated
|
|
||
| def __init__(self, | ||
| kernel_size, | ||
| stride=1, |
There was a problem hiding this comment.
stride 的默认值应该是None ,不是1;
以及注意None时候的行为
python/paddle/nn/layer/common.py
Outdated
| stride=1, | ||
| padding=0, | ||
| ceil_mode=False, | ||
| count_include_pad=True, |
python/paddle/nn/layer/common.py
Outdated
|
|
||
| # max pool2d | ||
| input = paddle.to_variable(np.random.uniform(-1, 1, [1, 3, 32, 32]).astype(np.float32)) | ||
| output = F.max_pool2d(input, |
python/paddle/nn/layer/common.py
Outdated
| stride=1, | ||
| padding=0, | ||
| ceil_mode=False, | ||
| return_indices=False, |
There was a problem hiding this comment.
ceil_mode return_indices的传参的顺序
python/paddle/nn/layer/common.py
Outdated
| input = paddle.to_tensor(np.random.uniform(-1, 1, [1, 3, 32, 32]).astype(np.float32)) | ||
| Pool2d = nn.AvgPool2d(kernel_size=2, | ||
| stride=2, padding=0) | ||
| output = Poo2d(input) |
python/paddle/nn/layer/common.py
Outdated
| name=None): | ||
| ceil_mode=False, | ||
| name=None, | ||
| data_format="NCHW"): |
python/paddle/nn/layer/common.py
Outdated
| name=None): | ||
| ceil_mode=False, | ||
| name=None, | ||
| data_format="NCDHW"): |
python/paddle/nn/layer/common.py
Outdated
| self.count_include_pad = count_include_pad | ||
| self.name = name | ||
| self.data_format = data_format | ||
| self.divisor = divisor_override |
| 'pool2d', 'pool3d', 'adaptive_pool2d', 'adaptive_pool3d', | ||
| 'adaptive_avg_pool2d', 'adaptive_avg_pool3d' | ||
| 'pool2d', | ||
| 'pool3d', |
There was a problem hiding this comment.
pool2d, pool3d 在2.0的API体系里不再需要了。对应的fluid下的api定义上加上deprecated
There was a problem hiding this comment.
收到,这个改动和另外两条意见能否新提一个PR修改,functional/common.py 修改较多,很容易和其他PR冲突。解决冲突后还得重新过CI
| 'adaptive_avg_pool2d', | ||
| 'adaptive_avg_pool3d', | ||
| 'adaptive_pool2d', | ||
| 'adaptive_pool3d', |
There was a problem hiding this comment.
adaptive_pool2d, adaptive_pool3d应该是也不需要了,直接对fluid下的api定义上加上deprecated吧。
好像还缺少adaptive_max_pool2d, adaptive_max_pool3d ?
| The output value of the layer with input size (N, C, L), | ||
| output (N, C, L_{out}) and kernel_size k can be precisely described as | ||
| For average pool1d: | ||
|
|
There was a problem hiding this comment.
这部分可以直接加个reference link 到class 版本的API里。
正在请 @TCChenlong 确认具体的写法。
There was a problem hiding this comment.
收到,我线下找 chenlong 确认下。
python/paddle/nn/layer/common.py
Outdated
| in NCHW format, where N is batch size, C is the number of channels, | ||
| H is the height of the feature, and W is the width of the feature. | ||
|
|
||
| Example: |
There was a problem hiding this comment.
输入输出的形状规范成torch文档里的Shape的写法。
There was a problem hiding this comment.
收到,这个改动和另外两条意见能否新提一个PR修改,functional/common.py 修改较多,很容易和其他PR冲突。解决冲突后还得重新过CI
jzhang533
left a comment
There was a problem hiding this comment.
will merge
some followup:
- split pooling implementation to separate file
- fix api deprecation and document issues discussed in this pr.
jzhang533
left a comment
There was a problem hiding this comment.
lgtm(resolved conflicts)
| Args: | ||
| x (Tensor): The input tensor of pooling operator which is a 3-D tensor with | ||
| shape [N, C, L]. where `N` is batch size, `C` is the number of channels, | ||
| `L` is the length of the feature. The data type if float32 or float64. |
| ShapeError: If the output's shape calculated is not greater than 0. | ||
| Examples: | ||
| .. code-block:: python | ||
| import paddle |
| Args: | ||
| x (Tensor): The input tensor of pooling operator which is a 3-D tensor with | ||
| shape [N, C, L], where `N` is batch size, `C` is the number of channels, | ||
| `L` is the length of the feature. The data type if float32 or float64. |
| when `data_format` is `"NHWC"`, `pool_padding` can be in the form | ||
| `[[0,0], [pad_height_top, pad_height_bottom], [pad_width_left, pad_width_right], [0,0]]`. | ||
| Otherwise, the pool padding size will be a square of an int. | ||
| ceil_mode (bool): when True, will use `ceil` instead of `floor` to compute the output shape |
| ShapeError: If the output's shape calculated is not greater than 0. | ||
| Examples: | ||
| .. code-block:: python | ||
| import paddle |
PR types
New features
PR changes
APIs
Describe
add API include:
paddle.nn.functional.avg_pool2d
paddle.nn.functional.max_pool2d
paddle.nn.functional.avg_pool3d
paddle.nn.functional.max_pool3d
paddle.nn.layers.AvgPool2d
paddle.nn.layers.MaxPool2d
paddle.nn.layers.AvgPool3d
paddle.nn.layers.MaxPool3d
paddle.nn.functional.avg_pool1d
paddle.nn.functional.max_pool1d
paddle.nn.functional.adaptive_avg_pool1d
paddle.nn.functional.adaptive_max_pool1d
paddle.nn.AvgPool1d
paddle.nn.MaxPool1d
paddle.nn.AdaptiveAvgPool1d
paddle.nn.AdaptiveMaxPool1d
中文文档PR:
https://github.com/PaddlePaddle/FluidDoc/pull/2434/files