-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
Conversation
Thanks for your contribution! |
✅ This PR's description meets the template requirements! |
|
||
|
||
def adaptive_start_index(index, input_size, output_size): | ||
return int(np.floor(index * input_size / output_size)) |
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.
直接int就可以?
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 int(np.ceil((index + 1) * input_size / output_size)) | ||
|
||
|
||
def max_pool1D_forward_naive(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.
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) |
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.
comment删掉?
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
data, ksize=[6], adaptive=True, paddings=[0], strides=[0]) | ||
|
||
np.testing.assert_allclose(res_np, res_pd.numpy()) | ||
print("=> unittest adaptive_avg_pool1d success!") |
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.
同上
|
||
import paddle.fluid as fluid | ||
|
||
data = fluid.data(name='data', shape=[None, 3, 32], dtype='float32') |
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.
paddle.data?2.0好像主要用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.
应该还是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) |
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.
paddle.nn.functional
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!THX
stride=None, | ||
padding=0, | ||
count_include_pad=True, | ||
ceil_mode=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.
data_format='NCL'
None by default. | ||
count_include_pad (bool): Whether to exclude padding points in average pooling | ||
mode, default is `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.
Args 顺序,name最后一个
stride=None, | ||
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.
return_indices=False, ceil_mode=False, data_format='NCL'
python/paddle/nn/layer/common.py
Outdated
stride=None, | ||
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.
dataformat 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.
LGTM
@@ -28,6 +28,10 @@ | |||
'Linear', | |||
'UpSample', | |||
'Pad2D', | |||
'AvgPool1d', |
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.
move pool layer to layer/pooling.py ?
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.
目前是都在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, |
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.
NHL -> NLC
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.
dataformat 低优
|
||
""" | ||
"""NCL to NCHW""" | ||
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.
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]) |
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.
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, |
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.
NLC
|
||
def check_input(x, dimension): | ||
if len(x.shape) != dimension: | ||
raise ValueError("Excepted Input X is 3-D tensor, but received {}-D {}". |
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.
dimension - D
""" | ||
"""NCL to NCHW""" | ||
data_format = "NCHW" | ||
check_variable_and_dtype(x, 'input', ['float32', 'float64'], 'avg_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.
if not in_dygraph_mode
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.
适用静态图模式
None by default. | ||
Returns: | ||
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.
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.
返回的是一个对象
# pool_out shape: [1, 3, 16] | ||
|
||
# for return_indices = true | ||
AdaptiveMaxPool1d = nn.AdaptiveMaxPool1d(output_size=16, return_indices=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.
use lower name name function
|
||
Output(i) &= max(Input[lstart:lend])} | ||
|
||
Args: |
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.
Parameters
None by default. | ||
|
||
Returns: | ||
Tensor: The output tensor of adaptive pooling result. The data type is same |
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 are two conditions
为了防止PR合入冲突,将该PR 的修改 合并到 #26331 中,此PR可关闭 |
Since you haven't replied for more than a year, we have closed this issue/pr. |
PR types
New features
PR changes
APIs
Describe
add functional APIs: