Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
b9d739a7
P
Paddle
项目概览
PaddlePaddle
/
Paddle
接近 2 年 前同步成功
通知
2323
Star
20933
Fork
5424
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
b9d739a7
编写于
9月 27, 2020
作者:
D
Double_V
提交者:
GitHub
9月 27, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix pool bug, test=develop (#27537)
* fix pool bug, test=develop * fix coverage,test=develop * fix bug, test=develop
上级
86fa0432
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
43 addition
and
14 deletion
+43
-14
python/paddle/fluid/tests/unittests/test_pool1d_api.py
python/paddle/fluid/tests/unittests/test_pool1d_api.py
+18
-0
python/paddle/nn/functional/pooling.py
python/paddle/nn/functional/pooling.py
+25
-14
未找到文件。
python/paddle/fluid/tests/unittests/test_pool1d_api.py
浏览文件 @
b9d739a7
...
@@ -195,6 +195,23 @@ class TestPool1d_API(unittest.TestCase):
...
@@ -195,6 +195,23 @@ class TestPool1d_API(unittest.TestCase):
result
=
max_pool1d_dg
(
input
)
result
=
max_pool1d_dg
(
input
)
self
.
assertTrue
(
np
.
allclose
(
result
.
numpy
(),
result_np
))
self
.
assertTrue
(
np
.
allclose
(
result
.
numpy
(),
result_np
))
def
check_max_dygraph_return_index_results
(
self
,
place
):
with
fluid
.
dygraph
.
guard
(
place
):
input_np
=
np
.
random
.
random
([
2
,
3
,
32
]).
astype
(
"float32"
)
input
=
fluid
.
dygraph
.
to_variable
(
input_np
)
result
,
index
=
F
.
max_pool1d
(
input
,
kernel_size
=
2
,
stride
=
2
,
padding
=
0
,
return_indices
=
True
)
result_np
=
max_pool1D_forward_naive
(
input_np
,
ksize
=
[
2
],
strides
=
[
2
],
paddings
=
[
0
])
self
.
assertTrue
(
np
.
allclose
(
result
.
numpy
(),
result_np
))
max_pool1d_dg
=
paddle
.
nn
.
layer
.
MaxPool1d
(
kernel_size
=
2
,
stride
=
None
,
padding
=
0
)
result
=
max_pool1d_dg
(
input
)
self
.
assertTrue
(
np
.
allclose
(
result
.
numpy
(),
result_np
))
def
check_max_dygraph_padding_same
(
self
,
place
):
def
check_max_dygraph_padding_same
(
self
,
place
):
with
fluid
.
dygraph
.
guard
(
place
):
with
fluid
.
dygraph
.
guard
(
place
):
input_np
=
np
.
random
.
random
([
2
,
3
,
32
]).
astype
(
"float32"
)
input_np
=
np
.
random
.
random
([
2
,
3
,
32
]).
astype
(
"float32"
)
...
@@ -228,6 +245,7 @@ class TestPool1d_API(unittest.TestCase):
...
@@ -228,6 +245,7 @@ class TestPool1d_API(unittest.TestCase):
self
.
check_avg_static_results
(
place
)
self
.
check_avg_static_results
(
place
)
self
.
check_max_dygraph_padding_same
(
place
)
self
.
check_max_dygraph_padding_same
(
place
)
self
.
check_avg_dygraph_padding_same
(
place
)
self
.
check_avg_dygraph_padding_same
(
place
)
self
.
check_max_dygraph_return_index_results
(
place
)
class
TestPool2dError_API
(
unittest
.
TestCase
):
class
TestPool2dError_API
(
unittest
.
TestCase
):
...
...
python/paddle/nn/functional/pooling.py
浏览文件 @
b9d739a7
...
@@ -571,15 +571,26 @@ def max_pool1d(x,
...
@@ -571,15 +571,26 @@ def max_pool1d(x,
padding
=
_expand_low_nd_padding
(
padding
)
padding
=
_expand_low_nd_padding
(
padding
)
if
in_dygraph_mode
():
if
in_dygraph_mode
():
pool_out
=
core
.
ops
.
max_pool2d_with_index
(
if
return_indices
:
x
,
'ksize'
,
kernel_size
,
'global_pooling'
,
False
,
'strides'
,
stride
,
pool_out
=
core
.
ops
.
max_pool2d_with_index
(
'paddings'
,
padding
,
'padding_algorithm'
,
padding_algorithm
,
x
,
'ksize'
,
kernel_size
,
'global_pooling'
,
False
,
'strides'
,
'use_cudnn'
,
True
,
'ceil_mode'
,
ceil_mode
,
'use_mkldnn'
,
False
,
stride
,
'paddings'
,
padding
,
'padding_algorithm'
,
'exclusive'
,
True
,
'data_format'
,
data_format
)
padding_algorithm
,
'use_cudnn'
,
True
,
'ceil_mode'
,
ceil_mode
,
return
(
squeeze
(
pool_out
[
0
],
[
2
]),
squeeze
(
'use_mkldnn'
,
False
,
'exclusive'
,
True
,
'data_format'
,
pool_out
[
1
],
[
2
]))
if
return_indices
else
squeeze
(
pool_out
[
0
],
[
2
])
data_format
)
return
(
squeeze
(
pool_out
[
0
],
[
2
]),
squeeze
(
pool_out
[
1
],
[
2
]))
if
return_indices
else
squeeze
(
pool_out
[
0
],
[
2
])
else
:
pool_out
=
core
.
ops
.
pool2d
(
x
,
'pooling_type'
,
'max'
,
'ksize'
,
kernel_size
,
'global_pooling'
,
False
,
'padding_algorithm'
,
padding_algorithm
,
'strides'
,
stride
,
'paddings'
,
padding
,
'use_cudnn'
,
True
,
'ceil_mode'
,
ceil_mode
,
'use_mkldnn'
,
False
,
'exclusive'
,
True
,
'data_format'
,
data_format
)
return
squeeze
(
pool_out
,
[
2
])
op_type
=
'max_pool2d_with_index'
op_type
=
'max_pool2d_with_index'
if
return_indices
else
"pool2d"
helper
=
LayerHelper
(
op_type
,
**
locals
())
helper
=
LayerHelper
(
op_type
,
**
locals
())
dtype
=
helper
.
input_dtype
()
dtype
=
helper
.
input_dtype
()
pool_out
=
helper
.
create_variable_for_type_inference
(
dtype
)
pool_out
=
helper
.
create_variable_for_type_inference
(
dtype
)
...
@@ -696,7 +707,7 @@ def max_pool2d(x,
...
@@ -696,7 +707,7 @@ def max_pool2d(x,
)
)
if
in_dygraph_mode
():
if
in_dygraph_mode
():
if
data_format
==
"NCHW"
:
if
return_indices
:
output
=
core
.
ops
.
max_pool2d_with_index
(
output
=
core
.
ops
.
max_pool2d_with_index
(
x
,
'ksize'
,
kernel_size
,
'global_pooling'
,
False
,
'strides'
,
x
,
'ksize'
,
kernel_size
,
'global_pooling'
,
False
,
'strides'
,
stride
,
'paddings'
,
padding
,
'padding_algorithm'
,
stride
,
'paddings'
,
padding
,
'padding_algorithm'
,
...
@@ -704,7 +715,7 @@ def max_pool2d(x,
...
@@ -704,7 +715,7 @@ def max_pool2d(x,
'use_mkldnn'
,
False
,
'exclusive'
,
True
,
'data_format'
,
'use_mkldnn'
,
False
,
'exclusive'
,
True
,
'data_format'
,
data_format
)
data_format
)
return
output
if
return_indices
else
output
[
0
]
return
output
if
return_indices
else
output
[
0
]
el
if
data_format
==
"NHWC"
and
not
return_indices
:
el
se
:
output
=
core
.
ops
.
pool2d
(
output
=
core
.
ops
.
pool2d
(
x
,
'pooling_type'
,
'max'
,
'ksize'
,
kernel_size
,
x
,
'pooling_type'
,
'max'
,
'ksize'
,
kernel_size
,
'global_pooling'
,
False
,
'padding_algorithm'
,
padding_algorithm
,
'global_pooling'
,
False
,
'padding_algorithm'
,
padding_algorithm
,
...
@@ -713,7 +724,7 @@ def max_pool2d(x,
...
@@ -713,7 +724,7 @@ def max_pool2d(x,
'data_format'
,
data_format
)
'data_format'
,
data_format
)
return
output
return
output
op_type
=
'max_pool2d_with_index'
if
data_format
==
"NCHW"
else
"pool2d"
op_type
=
'max_pool2d_with_index'
if
return_indices
else
"pool2d"
helper
=
LayerHelper
(
op_type
,
**
locals
())
helper
=
LayerHelper
(
op_type
,
**
locals
())
dtype
=
helper
.
input_dtype
()
dtype
=
helper
.
input_dtype
()
pool_out
=
helper
.
create_variable_for_type_inference
(
dtype
)
pool_out
=
helper
.
create_variable_for_type_inference
(
dtype
)
...
@@ -822,7 +833,7 @@ def max_pool3d(x,
...
@@ -822,7 +833,7 @@ def max_pool3d(x,
)
)
if
in_dygraph_mode
():
if
in_dygraph_mode
():
if
data_format
==
"NCDHW"
:
if
return_indices
:
output
=
core
.
ops
.
max_pool3d_with_index
(
output
=
core
.
ops
.
max_pool3d_with_index
(
x
,
'pooling_type'
,
'max'
,
'ksize'
,
kernel_size
,
'strides'
,
x
,
'pooling_type'
,
'max'
,
'ksize'
,
kernel_size
,
'strides'
,
stride
,
'paddings'
,
padding
,
'global_pooling'
,
False
,
stride
,
'paddings'
,
padding
,
'global_pooling'
,
False
,
...
@@ -830,7 +841,7 @@ def max_pool3d(x,
...
@@ -830,7 +841,7 @@ def max_pool3d(x,
'ceil_mode'
,
ceil_mode
,
'use_mkldnn'
,
False
,
'exclusive'
,
True
,
'ceil_mode'
,
ceil_mode
,
'use_mkldnn'
,
False
,
'exclusive'
,
True
,
'data_format'
,
data_format
)
'data_format'
,
data_format
)
return
output
if
return_indices
else
output
[
0
]
return
output
if
return_indices
else
output
[
0
]
el
if
data_format
==
"NDHWC"
and
not
return_indices
:
el
se
:
output
=
core
.
ops
.
pool3d
(
output
=
core
.
ops
.
pool3d
(
x
,
'pooling_type'
,
'max'
,
'ksize'
,
kernel_size
,
x
,
'pooling_type'
,
'max'
,
'ksize'
,
kernel_size
,
'global_pooling'
,
False
,
'padding_algorithm'
,
padding_algorithm
,
'global_pooling'
,
False
,
'padding_algorithm'
,
padding_algorithm
,
...
@@ -839,7 +850,7 @@ def max_pool3d(x,
...
@@ -839,7 +850,7 @@ def max_pool3d(x,
'data_format'
,
data_format
)
'data_format'
,
data_format
)
return
output
return
output
op_type
=
"max_pool3d_with_index"
if
data_format
==
"NCDHW"
else
"pool3d"
op_type
=
"max_pool3d_with_index"
if
return_indices
else
"pool3d"
helper
=
LayerHelper
(
op_type
,
**
locals
())
helper
=
LayerHelper
(
op_type
,
**
locals
())
dtype
=
helper
.
input_dtype
()
dtype
=
helper
.
input_dtype
()
pool_out
=
helper
.
create_variable_for_type_inference
(
dtype
)
pool_out
=
helper
.
create_variable_for_type_inference
(
dtype
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录