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 functional pool1d API #26108

Closed
wants to merge 14 commits into from
Closed

[API 2.0] add functional pool1d API #26108

wants to merge 14 commits into from

Conversation

LDOUBLEV
Copy link
Contributor

@LDOUBLEV LDOUBLEV commented Aug 10, 2020

PR types

New features

PR changes

APIs

Describe

add functional APIs:

  • 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

@paddle-bot-old
Copy link

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

@paddle-bot-old
Copy link

paddle-bot-old bot commented Aug 10, 2020

✅ This PR's description meets the template requirements!
Please wait for other CI results.



def adaptive_start_index(index, input_size, output_size):
return int(np.floor(index * input_size / output_size))
Copy link
Contributor

Choose a reason for hiding this comment

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

直接int就可以?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

为了和ceil mode区分

return int(np.ceil((index + 1) * input_size / output_size))


def max_pool1D_forward_naive(x,
Copy link
Contributor

Choose a reason for hiding this comment

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

pool1D -> pool1d ?

def test_np_pd_pool1d():
data = np.random.random((2, 4, 32)).astype('float32')
with fluid.dygraph.guard():
# datapd = fluid.layers.assign(data)
Copy link
Contributor

Choose a reason for hiding this comment

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

comment删掉?

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

data, ksize=[6], adaptive=True, paddings=[0], strides=[0])

np.testing.assert_allclose(res_np, res_pd.numpy())
print("=> unittest adaptive_avg_pool1d success!")
Copy link
Contributor

Choose a reason for hiding this comment

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

同上


import paddle.fluid as fluid

data = fluid.data(name='data', shape=[None, 3, 32], dtype='float32')
Copy link
Contributor

Choose a reason for hiding this comment

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

paddle.data?2.0好像主要用paddle.了

Copy link
Contributor Author

Choose a reason for hiding this comment

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

应该还是fluid.data,可以再确认下

data = fluid.data(name='data', shape=[None, 3, 32], dtype='float32')

# max pool2d
pool2d = fluid.layers.functional.avg_pool1d(input=data, kernel_size=2, stride=2, padding=0)
Copy link
Contributor

Choose a reason for hiding this comment

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

paddle.nn.functional

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!THX

@LDOUBLEV LDOUBLEV changed the title add functional pool1d API [API 2.0] add functional pool1d API Aug 17, 2020
stride=None,
padding=0,
count_include_pad=True,
ceil_mode=False,
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.

data_format='NCL'

None by default.
count_include_pad (bool): Whether to exclude padding points in average pooling
mode, default is `true`.

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.

Args 顺序,name最后一个

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

Choose a reason for hiding this comment

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

return_indices=False, ceil_mode=False, data_format='NCL'

stride=None,
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.

dataformat name

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

@@ -28,6 +28,10 @@
'Linear',
'UpSample',
'Pad2D',
'AvgPool1d',
Copy link
Member

Choose a reason for hiding this comment

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

move pool layer to layer/pooling.py ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

目前是都在common.py里的

Args:
x (Tensor): The input tensor of pooling operator which is a 3-D tensor with
shape [N, C, L]. The format of input tensor is `"NCL"` or
`"NHL"`, where `N` is batch size, `C` is the number of channels,
Copy link
Member

Choose a reason for hiding this comment

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

NHL -> NLC

Copy link
Contributor Author

Choose a reason for hiding this comment

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

dataformat 低优


"""
"""NCL to NCHW"""
data_format = "NCHW"
Copy link
Member

Choose a reason for hiding this comment

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

add NHWC?

padding_algorithm, 'use_cudnn', not count_include_pad, 'ceil_mode',
ceil_mode, 'use_mkldnn', False, 'exclusive', True, 'data_format',
data_format)
return squeeze(output, [2])
Copy link
Member

Choose a reason for hiding this comment

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

call core.ops.squeeze?

Args:
x (Tensor): The input tensor of pooling operator which is a 3-D tensor with
shape [N, C, L]. The format of input tensor is `"NCL"` or
`"NHL"`, where `N` is batch size, `C` is the number of channels,
Copy link
Member

Choose a reason for hiding this comment

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

NLC


def check_input(x, dimension):
if len(x.shape) != dimension:
raise ValueError("Excepted Input X is 3-D tensor, but received {}-D {}".
Copy link
Member

Choose a reason for hiding this comment

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

dimension - D

"""
"""NCL to NCHW"""
data_format = "NCHW"
check_variable_and_dtype(x, 'input', ['float32', 'float64'], 'avg_pool1d')
Copy link
Member

Choose a reason for hiding this comment

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

if not in_dygraph_mode

Copy link
Contributor Author

Choose a reason for hiding this comment

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

适用静态图模式

None by default.
Returns:
None.

Copy link
Member

Choose a reason for hiding this comment

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

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.

返回的是一个对象

# pool_out shape: [1, 3, 16]

# for return_indices = true
AdaptiveMaxPool1d = nn.AdaptiveMaxPool1d(output_size=16, return_indices=True)
Copy link
Member

Choose a reason for hiding this comment

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

use lower name name function


Output(i) &= max(Input[lstart:lend])}

Args:
Copy link
Member

Choose a reason for hiding this comment

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

Parameters

None by default.

Returns:
Tensor: The output tensor of adaptive pooling result. The data type is same
Copy link
Member

Choose a reason for hiding this comment

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

There are two conditions

@LDOUBLEV
Copy link
Contributor Author

为了防止PR合入冲突,将该PR 的修改 合并到 #26331 中,此PR可关闭

@paddle-bot-old paddle-bot-old bot closed this Sep 14, 2021
@paddle-bot-old
Copy link

Since you haven't replied for more than a year, we have closed this issue/pr.
If the problem is not solved or there is a follow-up one, please reopen it at any time and we will continue to follow up.
由于您超过一年未回复,我们将关闭这个issue/pr。
若问题未解决或有后续问题,请随时重新打开,我们会继续跟进。

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.

4 participants