[API 2.0] add functional pool1d API#26108
[API 2.0] add functional pool1d API#26108LDOUBLEV wants to merge 14 commits intoPaddlePaddle:developfrom LDOUBLEV:develop
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)) |
| return int(np.ceil((index + 1) * input_size / output_size)) | ||
|
|
||
|
|
||
| def max_pool1D_forward_naive(x, |
There was a problem hiding this comment.
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) |
| data, ksize=[6], adaptive=True, paddings=[0], strides=[0]) | ||
|
|
||
| np.testing.assert_allclose(res_np, res_pd.numpy()) | ||
| print("=> unittest adaptive_avg_pool1d success!") |
|
|
||
| import paddle.fluid as fluid | ||
|
|
||
| data = fluid.data(name='data', shape=[None, 3, 32], dtype='float32') |
There was a problem hiding this comment.
paddle.data?2.0好像主要用paddle.了
There was a problem hiding this comment.
应该还是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.
paddle.nn.functional
| stride=None, | ||
| padding=0, | ||
| count_include_pad=True, | ||
| ceil_mode=False, |
| None by default. | ||
| count_include_pad (bool): Whether to exclude padding points in average pooling | ||
| mode, default is `true`. | ||
|
|
| stride=None, | ||
| padding=0, | ||
| ceil_mode=False, | ||
| return_indices=False, |
There was a problem hiding this comment.
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): |
| 'Linear', | ||
| 'UpSample', | ||
| 'Pad2D', | ||
| 'AvgPool1d', |
There was a problem hiding this comment.
move pool layer to layer/pooling.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, |
|
|
||
| """ | ||
| """NCL to NCHW""" | ||
| data_format = "NCHW" |
| 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]) |
| 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, |
|
|
||
| def check_input(x, dimension): | ||
| if len(x.shape) != dimension: | ||
| raise ValueError("Excepted Input X is 3-D tensor, but received {}-D {}". |
| """ | ||
| """NCL to NCHW""" | ||
| data_format = "NCHW" | ||
| check_variable_and_dtype(x, 'input', ['float32', 'float64'], 'avg_pool1d') |
| None by default. | ||
| Returns: | ||
| None. | ||
|
|
| # 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.
use lower name name function
|
|
||
| Output(i) &= max(Input[lstart:lend])} | ||
|
|
||
| Args: |
| None by default. | ||
|
|
||
| Returns: | ||
| Tensor: The output tensor of adaptive pooling result. The data type is same |
|
为了防止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: