Skip to content
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

Merged
merged 12 commits into from
Aug 24, 2020
Merged

[API 2.0] add pool2d3d API,test=develop #26331

merged 12 commits into from
Aug 24, 2020

Conversation

LDOUBLEV
Copy link
Contributor

@LDOUBLEV LDOUBLEV commented Aug 16, 2020

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

@paddle-bot-old
Copy link

Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

return padding


def max_pool2d(input,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

input -> x

Copy link
Contributor Author

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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这块作为参数传进来吧?x可能试nhwc的

Copy link
Contributor Author

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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

input -> x

Copy link
Contributor Author

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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上

Copy link
Contributor Author

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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

动态图模式用core.ops.xxx?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

self.name = name

def forward(self, input):
return F.max_pool3d(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

input -> x

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

None by default.

Returns:
Variable: The output tensor of pooling result. The data type is same as input tensor.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return: None

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

class里面没有input

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

self.count_include_pad = count_include_pad
self.name = name

def forward(self, inputs):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

input -> x

Copy link
Contributor Author

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

加上 #DEFINE_ALIAS 标示,做api映射

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#DEFINE_ALIAS

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


# max pool2d
input = paddle.to_variable(np.random.uniform(-1, 1, [1, 3, 32, 32]).astype(np.float32))
output = F.avg_pool2d(input,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个是functional的example吧

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


def __init__(self,
kernel_size=-1,
stride=1,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stride 的默认值应该是None ,不是1;
以及注意None时候的行为

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


def __init__(self,
kernel_size,
stride=1,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stride 的默认值应该是None ,不是1;
以及注意None时候的行为

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

stride=1,
padding=0,
ceil_mode=False,
count_include_pad=True,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

divisor_override,这个没对齐

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


# max pool2d
input = paddle.to_variable(np.random.uniform(-1, 1, [1, 3, 32, 32]).astype(np.float32))
output = F.max_pool2d(input,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

构造Module的样例

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

stride=1,
padding=0,
ceil_mode=False,
return_indices=False,
Copy link
Contributor

@WuHaobo WuHaobo Aug 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ceil_mode return_indices的传参的顺序

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@LDOUBLEV LDOUBLEV changed the title add pool2d3d API,test=develop [API 2.0] add pool2d3d API,test=develop Aug 17, 2020
stride=2, padding=0)
output = Poo2d(input)
Copy link
Contributor

@WuHaobo WuHaobo Aug 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix the typo "Poo2d"

name=None):
ceil_mode=False,
name=None,
data_format="NCHW"):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

参数顺序,name 一般是最后一个

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

name=None):
ceil_mode=False,
name=None,
data_format="NCDHW"):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data_format 和 name的顺序

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

WuHaobo
WuHaobo previously approved these changes Aug 20, 2020
Copy link
Contributor

@WuHaobo WuHaobo left a 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',
Copy link
Contributor

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

Copy link
Contributor Author

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',
Copy link
Contributor

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 ?

Copy link
Contributor Author

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:

Copy link
Contributor

@jzhang533 jzhang533 Aug 21, 2020

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 确认具体的写法。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

收到,我线下找 chenlong 确认下。

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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

输入输出的形状规范成torch文档里的Shape的写法。

Copy link
Contributor Author

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

jzhang533
jzhang533 previously approved these changes Aug 21, 2020
Copy link
Contributor

@jzhang533 jzhang533 left a 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.

dyning
dyning previously approved these changes Aug 21, 2020
@LDOUBLEV LDOUBLEV dismissed stale reviews from dyning and jzhang533 via c581fc8 August 24, 2020 05:12
Copy link
Contributor

@jzhang533 jzhang533 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm(resolved conflicts)

Copy link
Collaborator

@raindrops2sea raindrops2sea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jzhang533 jzhang533 merged commit c8e1836 into PaddlePaddle:develop Aug 24, 2020
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.
Copy link
Contributor

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
Copy link
Contributor

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.
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同理 应该加一个空行

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants