Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
6f61b5df
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
6f61b5df
编写于
9月 22, 2017
作者:
C
chengduoZH
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix unit test
上级
84a2512b
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
77 addition
and
16 deletion
+77
-16
paddle/operators/pool_op.cc
paddle/operators/pool_op.cc
+6
-7
python/paddle/v2/framework/tests/test_pool2d_op.py
python/paddle/v2/framework/tests/test_pool2d_op.py
+36
-4
python/paddle/v2/framework/tests/test_pool3d_op.py
python/paddle/v2/framework/tests/test_pool3d_op.py
+35
-5
未找到文件。
paddle/operators/pool_op.cc
浏览文件 @
6f61b5df
...
...
@@ -46,20 +46,19 @@ class PoolOp : public framework::OperatorWithKernel {
PADDLE_ENFORCE
(
pooling_type
==
"max"
||
pooling_type
==
"ave"
,
"pooling_type should be 'max' or 'ave'"
);
PADDLE_ENFORCE
(
ksize
.
size
()
==
2
||
ksize
.
size
()
==
3
,
"Pooling
ksize should be 2-D or 3
-D"
);
PADDLE_ENFORCE
(
in_X
->
dims
().
size
()
==
4
||
in_X
->
dims
().
size
()
==
5
,
"Pooling
intput should be 4-D or 5
-D"
);
if
(
global_pooling
==
1
)
{
for
(
size_t
i
=
0
;
i
<
ksize
.
size
();
++
i
)
ksize
[
i
]
=
in_X
->
dims
()[
i
+
2
];
ksize
.
resize
(
static_cast
<
size_t
>
(
in_X
->
dims
().
size
())
-
2
);
for
(
size_t
i
=
0
;
i
<
ksize
.
size
();
++
i
)
ksize
[
i
]
=
static_cast
<
int
>
(
in_X
->
dims
()[
i
+
2
]);
}
if
(
ksize
.
size
()
==
2
)
{
PADDLE_ENFORCE_EQ
(
in_X
->
dims
().
size
(),
4
,
"Pool2DOp intput should be 4-D."
);
PADDLE_ENFORCE_EQ
(
strides
.
size
(),
2
,
"Pool2DOp strides should be 2-D."
);
PADDLE_ENFORCE_EQ
(
paddings
.
size
(),
2
,
"Pool2DOp paddings should be 2-D."
);
}
else
{
PADDLE_ENFORCE_EQ
(
in_X
->
dims
().
size
(),
5
,
"Pool3DOp intput should be 5-D."
);
PADDLE_ENFORCE_EQ
(
strides
.
size
(),
3
,
"Pool3DOp strides should be 3-D."
);
PADDLE_ENFORCE_EQ
(
paddings
.
size
(),
3
,
"Pool3DOp paddings should be 3-D."
);
}
...
...
python/paddle/v2/framework/tests/test_pool2d_op.py
浏览文件 @
6f61b5df
...
...
@@ -3,9 +3,11 @@ import numpy as np
from
op_test
import
OpTest
def
max_pool2D_forward_naive
(
x
,
ksize
,
strides
,
paddings
=
[
0
,
0
]):
def
max_pool2D_forward_naive
(
x
,
ksize
,
strides
,
paddings
=
[
0
,
0
]
,
global_pool
=
0
):
N
,
C
,
H
,
W
=
x
.
shape
if
global_pool
==
1
:
ksize
=
[
H
,
W
]
H_out
=
(
H
-
ksize
[
0
]
+
2
*
paddings
[
0
])
/
strides
[
0
]
+
1
W_out
=
(
W
-
ksize
[
1
]
+
2
*
paddings
[
1
])
/
strides
[
1
]
+
1
out
=
np
.
zeros
((
N
,
C
,
H_out
,
W_out
))
...
...
@@ -21,9 +23,11 @@ def max_pool2D_forward_naive(x, ksize, strides, paddings=[0, 0]):
return
out
def
ave_pool2D_forward_naive
(
x
,
ksize
,
strides
,
paddings
=
[
0
,
0
]):
def
ave_pool2D_forward_naive
(
x
,
ksize
,
strides
,
paddings
=
[
0
,
0
]
,
global_pool
=
0
):
N
,
C
,
H
,
W
=
x
.
shape
if
global_pool
==
1
:
ksize
=
[
H
,
W
]
H_out
=
(
H
-
ksize
[
0
]
+
2
*
paddings
[
0
])
/
strides
[
0
]
+
1
W_out
=
(
W
-
ksize
[
1
]
+
2
*
paddings
[
1
])
/
strides
[
1
]
+
1
out
=
np
.
zeros
((
N
,
C
,
H_out
,
W_out
))
...
...
@@ -46,7 +50,7 @@ class TestPool2d_Op(OpTest):
self
.
op_type
=
"pool2d"
input
=
np
.
random
.
random
(
self
.
shape
).
astype
(
"float32"
)
output
=
self
.
pool2D_forward_naive
(
input
,
self
.
ksize
,
self
.
strides
,
self
.
paddings
)
self
.
paddings
,
self
.
global_pool
)
self
.
inputs
=
{
'X'
:
input
}
self
.
attrs
=
{
...
...
@@ -54,6 +58,7 @@ class TestPool2d_Op(OpTest):
'paddings'
:
self
.
paddings
,
'ksize'
:
self
.
ksize
,
'poolingType'
:
self
.
pool_type
,
'globalPooling'
:
self
.
global_pool
,
}
self
.
outputs
=
{
'Out'
:
output
}
...
...
@@ -66,6 +71,7 @@ class TestPool2d_Op(OpTest):
self
.
check_grad
(
set
([
'X'
]),
'Out'
,
max_relative_error
=
0.07
)
def
initTestCase
(
self
):
self
.
global_pool
=
0
self
.
pool_type
=
"ave"
self
.
pool2D_forward_naive
=
ave_pool2D_forward_naive
self
.
shape
=
[
2
,
3
,
5
,
5
]
...
...
@@ -74,8 +80,21 @@ class TestPool2d_Op(OpTest):
self
.
paddings
=
[
0
,
0
]
class
TestCase1
(
TestPool2d_Op
):
def
initTestCase
(
self
):
self
.
global_pool
=
0
self
.
op_type
=
"pool2d"
self
.
pool_type
=
"ave"
self
.
pool2D_forward_naive
=
ave_pool2D_forward_naive
self
.
shape
=
[
2
,
3
,
5
,
5
]
self
.
ksize
=
[
3
,
3
]
self
.
strides
=
[
1
,
1
]
self
.
paddings
=
[
1
,
1
]
class
TestCase2
(
TestPool2d_Op
):
def
initTestCase
(
self
):
self
.
global_pool
=
1
self
.
op_type
=
"pool2d"
self
.
pool_type
=
"ave"
self
.
pool2D_forward_naive
=
ave_pool2D_forward_naive
...
...
@@ -85,8 +104,21 @@ class TestCase2(TestPool2d_Op):
self
.
paddings
=
[
1
,
1
]
class
TestCase1
(
TestPool2d_Op
):
class
TestCase3
(
TestPool2d_Op
):
def
initTestCase
(
self
):
self
.
global_pool
=
0
self
.
op_type
=
"pool2d"
self
.
pool_type
=
"max"
self
.
pool2D_forward_naive
=
max_pool2D_forward_naive
self
.
shape
=
[
2
,
3
,
5
,
5
]
self
.
ksize
=
[
3
,
3
]
self
.
strides
=
[
1
,
1
]
self
.
paddings
=
[
1
,
1
]
class
TestCase4
(
TestPool2d_Op
):
def
initTestCase
(
self
):
self
.
global_pool
=
1
self
.
op_type
=
"pool2d"
self
.
pool_type
=
"max"
self
.
pool2D_forward_naive
=
max_pool2D_forward_naive
...
...
python/paddle/v2/framework/tests/test_pool3d_op.py
浏览文件 @
6f61b5df
...
...
@@ -3,9 +3,11 @@ import numpy as np
from
op_test
import
OpTest
def
max_pool3D_forward_naive
(
x
,
ksize
,
strides
,
paddings
=
[
0
,
0
]):
def
max_pool3D_forward_naive
(
x
,
ksize
,
strides
,
paddings
=
[
0
,
0
]
,
global_pool
=
0
):
N
,
C
,
D
,
H
,
W
=
x
.
shape
if
global_pool
==
1
:
ksize
=
[
D
,
H
,
W
]
D_out
=
(
D
-
ksize
[
0
]
+
2
*
paddings
[
0
])
/
strides
[
0
]
+
1
H_out
=
(
H
-
ksize
[
1
]
+
2
*
paddings
[
1
])
/
strides
[
1
]
+
1
W_out
=
(
W
-
ksize
[
2
]
+
2
*
paddings
[
2
])
/
strides
[
2
]
+
1
...
...
@@ -19,16 +21,17 @@ def max_pool3D_forward_naive(x, ksize, strides, paddings=[0, 0]):
for
j
in
xrange
(
W_out
):
w_start
=
np
.
max
((
j
*
strides
[
1
]
-
paddings
[
1
],
0
))
w_end
=
np
.
min
((
j
*
strides
[
1
]
+
ksize
[
1
]
-
paddings
[
1
],
W
))
x_masked
=
x
[:,
:,
d_start
:
d_end
,
h_start
:
h_end
,
w_start
:
w_end
]
out
[:,
:,
k
,
i
,
j
]
=
np
.
max
(
x_masked
,
axis
=
(
2
,
3
,
4
))
return
out
def
ave_pool3D_forward_naive
(
x
,
ksize
,
strides
,
paddings
=
[
0
,
0
]):
def
ave_pool3D_forward_naive
(
x
,
ksize
,
strides
,
paddings
=
[
0
,
0
]
,
global_pool
=
0
):
N
,
C
,
D
,
H
,
W
=
x
.
shape
if
global_pool
==
1
:
ksize
=
[
D
,
H
,
W
]
D_out
=
(
D
-
ksize
[
0
]
+
2
*
paddings
[
0
])
/
strides
[
0
]
+
1
H_out
=
(
H
-
ksize
[
1
]
+
2
*
paddings
[
1
])
/
strides
[
1
]
+
1
W_out
=
(
W
-
ksize
[
2
]
+
2
*
paddings
[
2
])
/
strides
[
2
]
+
1
...
...
@@ -42,7 +45,6 @@ def ave_pool3D_forward_naive(x, ksize, strides, paddings=[0, 0]):
for
j
in
xrange
(
W_out
):
w_start
=
np
.
max
((
j
*
strides
[
1
]
-
paddings
[
1
],
0
))
w_end
=
np
.
min
((
j
*
strides
[
1
]
+
ksize
[
1
]
-
paddings
[
1
],
W
))
x_masked
=
x
[:,
:,
d_start
:
d_end
,
h_start
:
h_end
,
w_start
:
w_end
]
out
[:,
:,
k
,
i
,
j
]
=
np
.
sum
(
x_masked
,
axis
=
(
2
,
3
,
4
))
/
(
...
...
@@ -56,7 +58,7 @@ class TestPool3d_Op(OpTest):
self
.
op_type
=
"pool3d"
input
=
np
.
random
.
random
(
self
.
shape
).
astype
(
"float32"
)
output
=
self
.
pool3D_forward_naive
(
input
,
self
.
ksize
,
self
.
strides
,
self
.
paddings
)
self
.
paddings
,
self
.
global_pool
)
self
.
inputs
=
{
'X'
:
input
}
self
.
attrs
=
{
...
...
@@ -64,6 +66,7 @@ class TestPool3d_Op(OpTest):
'paddings'
:
self
.
paddings
,
'ksize'
:
self
.
ksize
,
'poolingType'
:
self
.
pool_type
,
'globalPooling'
:
self
.
global_pool
,
}
self
.
outputs
=
{
'Out'
:
output
}
...
...
@@ -76,6 +79,7 @@ class TestPool3d_Op(OpTest):
self
.
check_grad
(
set
([
'X'
]),
'Out'
,
max_relative_error
=
0.07
)
def
initTestCase
(
self
):
self
.
global_pool
=
0
self
.
pool_type
=
"ave"
self
.
pool3D_forward_naive
=
ave_pool3D_forward_naive
self
.
shape
=
[
2
,
3
,
5
,
5
,
5
]
...
...
@@ -86,6 +90,7 @@ class TestPool3d_Op(OpTest):
class
TestCase1
(
TestPool3d_Op
):
def
initTestCase
(
self
):
self
.
global_pool
=
0
self
.
op_type
=
"pool3d"
self
.
pool_type
=
"ave"
self
.
pool3D_forward_naive
=
ave_pool3D_forward_naive
...
...
@@ -97,6 +102,31 @@ class TestCase1(TestPool3d_Op):
class
TestCase2
(
TestPool3d_Op
):
def
initTestCase
(
self
):
self
.
global_pool
=
1
self
.
op_type
=
"pool3d"
self
.
pool_type
=
"ave"
self
.
pool3D_forward_naive
=
ave_pool3D_forward_naive
self
.
shape
=
[
2
,
3
,
7
,
7
,
7
]
self
.
ksize
=
[
3
,
3
,
3
]
self
.
strides
=
[
1
,
1
,
1
]
self
.
paddings
=
[
1
,
1
,
1
]
class
TestCase3
(
TestPool3d_Op
):
def
initTestCase
(
self
):
self
.
global_pool
=
0
self
.
op_type
=
"pool3d"
self
.
pool_type
=
"max"
self
.
pool3D_forward_naive
=
max_pool3D_forward_naive
self
.
shape
=
[
2
,
3
,
5
,
5
,
5
]
self
.
ksize
=
[
3
,
3
,
3
]
self
.
strides
=
[
1
,
1
,
1
]
self
.
paddings
=
[
1
,
1
,
1
]
class
TestCase4
(
TestPool3d_Op
):
def
initTestCase
(
self
):
self
.
global_pool
=
1
self
.
op_type
=
"pool3d"
self
.
pool_type
=
"max"
self
.
pool3D_forward_naive
=
max_pool3D_forward_naive
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录