-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
[API 2.0] add pool2d3d API,test=develop #26331
Conversation
Thanks for your contribution! |
return padding | ||
|
||
|
||
def max_pool2d(input, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
input -> x
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这块作为参数传进来吧?x可能试nhwc的
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
return (pool_out, mask) if return_indices else pool_out | ||
|
||
|
||
def avg_pool2d(input, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
input -> x
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
padding_algorithm = "SAME" | ||
padding = [0, 0, 0] | ||
|
||
data_format = "NCDHW" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
mask = helper.create_variable_for_type_inference(dtype) | ||
outputs = {"Out": pool_out, "Mask": mask} | ||
|
||
helper.append_op( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
动态图模式用core.ops.xxx?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
python/paddle/nn/layer/common.py
Outdated
self.name = name | ||
|
||
def forward(self, input): | ||
return F.max_pool3d( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
input -> x
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return: None
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class里面没有input
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
python/paddle/nn/layer/common.py
Outdated
self.count_include_pad = count_include_pad | ||
self.name = name | ||
|
||
def forward(self, inputs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
input -> x
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -155,6 +157,10 @@ | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
加上 #DEFINE_ALIAS 标示,做api映射
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
python/paddle/nn/layer/__init__.py
Outdated
@@ -42,6 +42,10 @@ | |||
from .common import Linear #DEFINE_ALIAS | |||
from .common import Flatten #DEFINE_ALIAS | |||
from .common import UpSample #DEFINE_ALIAS | |||
from .common import AvgPool2d | |||
from .common import MaxPool2d | |||
from .common import AvgPool3d |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#DEFINE_ALIAS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个是functional的example吧
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
python/paddle/nn/layer/common.py
Outdated
|
||
def __init__(self, | ||
kernel_size=-1, | ||
stride=1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stride 的默认值应该是None ,不是1;
以及注意None时候的行为
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
python/paddle/nn/layer/common.py
Outdated
|
||
def __init__(self, | ||
kernel_size, | ||
stride=1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stride 的默认值应该是None ,不是1;
以及注意None时候的行为
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
python/paddle/nn/layer/common.py
Outdated
stride=1, | ||
padding=0, | ||
ceil_mode=False, | ||
count_include_pad=True, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
divisor_override,这个没对齐
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
构造Module的样例
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
python/paddle/nn/layer/common.py
Outdated
stride=1, | ||
padding=0, | ||
ceil_mode=False, | ||
return_indices=False, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ceil_mode return_indices的传参的顺序
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
python/paddle/nn/layer/common.py
Outdated
stride=2, padding=0) | ||
output = Poo2d(input) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix the typo "Poo2d"
python/paddle/nn/layer/common.py
Outdated
name=None): | ||
ceil_mode=False, | ||
name=None, | ||
data_format="NCHW"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
参数顺序,name 一般是最后一个
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
python/paddle/nn/layer/common.py
Outdated
name=None): | ||
ceil_mode=False, | ||
name=None, | ||
data_format="NCDHW"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
data_format 和 name的顺序
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
python/paddle/nn/layer/common.py
Outdated
super(AvgPool3d, self).__init__() | ||
self.ksize = kernel_size | ||
self.stride = stride | ||
self.padding = padding | ||
self.ceil_mode = ceil_mode | ||
self.count_include_pad = count_include_pad | ||
self.name = name | ||
self.data_format = data_format | ||
self.divisor = divisor_override |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
'pool2d', 'pool3d', 'adaptive_pool2d', 'adaptive_pool3d', | ||
'adaptive_avg_pool2d', 'adaptive_avg_pool3d' | ||
'pool2d', | ||
'pool3d', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pool2d, pool3d 在2.0的API体系里不再需要了。对应的fluid下的api定义上加上deprecated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
收到,这个改动和另外两条意见能否新提一个PR修改,functional/common.py 修改较多,很容易和其他PR冲突。解决冲突后还得重新过CI
'adaptive_avg_pool2d', | ||
'adaptive_avg_pool3d', | ||
'adaptive_pool2d', | ||
'adaptive_pool3d', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adaptive_pool2d, adaptive_pool3d应该是也不需要了,直接对fluid下的api定义上加上deprecated吧。
好像还缺少adaptive_max_pool2d, adaptive_max_pool3d ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这两个API分给了一帆,他提了PR
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这部分可以直接加个reference link 到class 版本的API里。
正在请 @TCChenlong 确认具体的写法。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
收到,我线下找 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
输入输出的形状规范成torch文档里的Shape
的写法。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
收到,这个改动和另外两条意见能否新提一个PR修改,functional/common.py 修改较多,很容易和其他PR冲突。解决冲突后还得重新过CI
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will merge
some followup:
- split pooling implementation to separate file
- fix api deprecation and document issues discussed in this pr.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm(resolved conflicts)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if -> is
ShapeError: If the output's shape calculated is not greater than 0. | ||
Examples: | ||
.. code-block:: python | ||
import paddle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里应该有一行间隔 不然会预览bug
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if -> is
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
少了'Default is False。'
ShapeError: If the output's shape calculated is not greater than 0. | ||
Examples: | ||
.. code-block:: python | ||
import paddle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同理 应该加一个空行
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