Skip to content

Commit 2d8a5b9

Browse files
committed
fix unit test
1 parent df59889 commit 2d8a5b9

File tree

3 files changed

+48
-25
lines changed

3 files changed

+48
-25
lines changed

paddle/operators/math/CMakeLists.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
if(WITH_GPU)
2-
nv_library(math_function SRCS math_function.cc math_function.cu im2col.cc im2col.cu pooling.cc pooling.cu DEPS cblas device_context)
2+
nv_library(math_function SRCS math_function.cc math_function.cu im2col.cc im2col.cu pooling.cc pooling.cu DEPS cblas device_context operator)
33
nv_test(math_function_test SRCS math_function_test.cc DEPS math_function tensor)
44
nv_library(softmax SRCS softmax.cc softmax.cu DEPS operator)
55
nv_library(cross_entropy SRCS cross_entropy.cc cross_entropy.cu DEPS operator)
66
else()
7-
cc_library(math_function SRCS math_function.cc im2col.cc pooling.cc
8-
DEPS cblas device_context operator)
7+
cc_library(math_function SRCS math_function.cc im2col.cc pooling.cc DEPS cblas device_context operator)
98
cc_test(math_function_test SRCS math_function_test.cc DEPS math_function tensor)
109
cc_library(softmax SRCS softmax.cc DEPS operator)
1110
cc_library(cross_entropy SRCS cross_entropy.cc DEPS operator)

python/paddle/v2/framework/tests/test_pool2d_op.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ def avg_pool2D_forward_naive(x, ksize, strides, paddings=[0, 0], global_pool=0):
4747
class TestPool2d_Op(OpTest):
4848
def setUp(self):
4949
self.initTestCase()
50-
self.op_type = "pool2d"
5150
input = np.random.random(self.shape).astype("float32")
5251
output = self.pool2D_forward_naive(input, self.ksize, self.strides,
5352
self.paddings, self.global_pool)
@@ -71,7 +70,8 @@ def test_check_grad(self):
7170
self.check_grad(set(['X']), 'Out', max_relative_error=0.07)
7271

7372
def initTestCase(self):
74-
self.global_pool = 0
73+
self.global_pool = True
74+
self.op_type = "pool2d"
7575
self.pool_type = "avg"
7676
self.pool2D_forward_naive = avg_pool2D_forward_naive
7777
self.shape = [2, 3, 5, 5]
@@ -82,47 +82,59 @@ def initTestCase(self):
8282

8383
class TestCase1(TestPool2d_Op):
8484
def initTestCase(self):
85-
self.global_pool = 0
85+
self.global_pool = False
8686
self.op_type = "pool2d"
8787
self.pool_type = "avg"
8888
self.pool2D_forward_naive = avg_pool2D_forward_naive
89-
self.shape = [2, 3, 5, 5]
89+
self.shape = [2, 3, 7, 7]
9090
self.ksize = [3, 3]
9191
self.strides = [1, 1]
92-
self.paddings = [1, 1]
92+
self.paddings = [0, 0]
9393

9494

9595
class TestCase2(TestPool2d_Op):
9696
def initTestCase(self):
97-
self.global_pool = 1
97+
self.global_pool = False
9898
self.op_type = "pool2d"
9999
self.pool_type = "avg"
100100
self.pool2D_forward_naive = avg_pool2D_forward_naive
101-
self.shape = [2, 3, 5, 5]
101+
self.shape = [2, 3, 7, 7]
102102
self.ksize = [3, 3]
103103
self.strides = [1, 1]
104104
self.paddings = [1, 1]
105105

106106

107107
class TestCase3(TestPool2d_Op):
108108
def initTestCase(self):
109-
self.global_pool = 0
109+
self.global_pool = True
110110
self.op_type = "pool2d"
111111
self.pool_type = "max"
112112
self.pool2D_forward_naive = max_pool2D_forward_naive
113113
self.shape = [2, 3, 5, 5]
114114
self.ksize = [3, 3]
115115
self.strides = [1, 1]
116-
self.paddings = [1, 1]
116+
self.paddings = [0, 0]
117117

118118

119-
class TestCase4(TestPool2d_Op):
119+
class TestCase3(TestPool2d_Op):
120120
def initTestCase(self):
121-
self.global_pool = 1
121+
self.global_pool = False
122122
self.op_type = "pool2d"
123123
self.pool_type = "max"
124124
self.pool2D_forward_naive = max_pool2D_forward_naive
125-
self.shape = [2, 3, 5, 5]
125+
self.shape = [2, 3, 7, 7]
126+
self.ksize = [3, 3]
127+
self.strides = [1, 1]
128+
self.paddings = [0, 0]
129+
130+
131+
class TestCase3(TestPool2d_Op):
132+
def initTestCase(self):
133+
self.global_pool = False
134+
self.op_type = "pool2d"
135+
self.pool_type = "max"
136+
self.pool2D_forward_naive = max_pool2D_forward_naive
137+
self.shape = [2, 3, 7, 7]
126138
self.ksize = [3, 3]
127139
self.strides = [1, 1]
128140
self.paddings = [1, 1]

python/paddle/v2/framework/tests/test_pool3d_op.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ def avg_pool3D_forward_naive(x, ksize, strides, paddings=[0, 0], global_pool=0):
5555
class TestPool3d_Op(OpTest):
5656
def setUp(self):
5757
self.initTestCase()
58-
self.op_type = "pool3d"
5958
input = np.random.random(self.shape).astype("float32")
6059
output = self.pool3D_forward_naive(input, self.ksize, self.strides,
6160
self.paddings, self.global_pool)
@@ -79,7 +78,8 @@ def test_check_grad(self):
7978
self.check_grad(set(['X']), 'Out', max_relative_error=0.07)
8079

8180
def initTestCase(self):
82-
self.global_pool = 0
81+
self.global_pool = True
82+
self.op_type = "pool3d"
8383
self.pool_type = "avg"
8484
self.pool3D_forward_naive = avg_pool3D_forward_naive
8585
self.shape = [2, 3, 5, 5, 5]
@@ -90,19 +90,19 @@ def initTestCase(self):
9090

9191
class TestCase1(TestPool3d_Op):
9292
def initTestCase(self):
93-
self.global_pool = 0
93+
self.global_pool = False
9494
self.op_type = "pool3d"
9595
self.pool_type = "avg"
9696
self.pool3D_forward_naive = avg_pool3D_forward_naive
9797
self.shape = [2, 3, 7, 7, 7]
9898
self.ksize = [3, 3, 3]
9999
self.strides = [1, 1, 1]
100-
self.paddings = [1, 1, 1]
100+
self.paddings = [0, 0, 0]
101101

102102

103103
class TestCase2(TestPool3d_Op):
104104
def initTestCase(self):
105-
self.global_pool = 1
105+
self.global_pool = False
106106
self.op_type = "pool3d"
107107
self.pool_type = "avg"
108108
self.pool3D_forward_naive = avg_pool3D_forward_naive
@@ -114,23 +114,35 @@ def initTestCase(self):
114114

115115
class TestCase3(TestPool3d_Op):
116116
def initTestCase(self):
117-
self.global_pool = 0
117+
self.global_pool = True
118118
self.op_type = "pool3d"
119119
self.pool_type = "max"
120120
self.pool3D_forward_naive = max_pool3D_forward_naive
121121
self.shape = [2, 3, 5, 5, 5]
122122
self.ksize = [3, 3, 3]
123123
self.strides = [1, 1, 1]
124-
self.paddings = [1, 1, 1]
124+
self.paddings = [0, 0, 0]
125125

126126

127-
class TestCase4(TestPool3d_Op):
127+
class TestCase3(TestPool3d_Op):
128128
def initTestCase(self):
129-
self.global_pool = 1
129+
self.global_pool = False
130130
self.op_type = "pool3d"
131131
self.pool_type = "max"
132132
self.pool3D_forward_naive = max_pool3D_forward_naive
133-
self.shape = [2, 3, 5, 5, 5]
133+
self.shape = [2, 3, 7, 7, 7]
134+
self.ksize = [3, 3, 3]
135+
self.strides = [1, 1, 1]
136+
self.paddings = [0, 0, 0]
137+
138+
139+
class TestCase3(TestPool3d_Op):
140+
def initTestCase(self):
141+
self.global_pool = False
142+
self.op_type = "pool3d"
143+
self.pool_type = "max"
144+
self.pool3D_forward_naive = max_pool3D_forward_naive
145+
self.shape = [2, 3, 7, 7, 7]
134146
self.ksize = [3, 3, 3]
135147
self.strides = [1, 1, 1]
136148
self.paddings = [1, 1, 1]

0 commit comments

Comments
 (0)