From 2d8a5b97cc9096a84483b92be458d1388533c84f Mon Sep 17 00:00:00 2001 From: chengduoZH Date: Fri, 29 Sep 2017 20:33:38 +0800 Subject: [PATCH] fix unit test --- paddle/operators/math/CMakeLists.txt | 5 ++- .../v2/framework/tests/test_pool2d_op.py | 36 ++++++++++++------- .../v2/framework/tests/test_pool3d_op.py | 32 +++++++++++------ 3 files changed, 48 insertions(+), 25 deletions(-) diff --git a/paddle/operators/math/CMakeLists.txt b/paddle/operators/math/CMakeLists.txt index f3ed0c78be..a0ceb029e3 100644 --- a/paddle/operators/math/CMakeLists.txt +++ b/paddle/operators/math/CMakeLists.txt @@ -1,11 +1,10 @@ if(WITH_GPU) - nv_library(math_function SRCS math_function.cc math_function.cu im2col.cc im2col.cu pooling.cc pooling.cu DEPS cblas device_context) + nv_library(math_function SRCS math_function.cc math_function.cu im2col.cc im2col.cu pooling.cc pooling.cu DEPS cblas device_context operator) nv_test(math_function_test SRCS math_function_test.cc DEPS math_function tensor) nv_library(softmax SRCS softmax.cc softmax.cu DEPS operator) nv_library(cross_entropy SRCS cross_entropy.cc cross_entropy.cu DEPS operator) else() - cc_library(math_function SRCS math_function.cc im2col.cc pooling.cc - DEPS cblas device_context operator) + cc_library(math_function SRCS math_function.cc im2col.cc pooling.cc DEPS cblas device_context operator) cc_test(math_function_test SRCS math_function_test.cc DEPS math_function tensor) cc_library(softmax SRCS softmax.cc DEPS operator) cc_library(cross_entropy SRCS cross_entropy.cc DEPS operator) diff --git a/python/paddle/v2/framework/tests/test_pool2d_op.py b/python/paddle/v2/framework/tests/test_pool2d_op.py index e8e5218073..0f9a548f29 100644 --- a/python/paddle/v2/framework/tests/test_pool2d_op.py +++ b/python/paddle/v2/framework/tests/test_pool2d_op.py @@ -47,7 +47,6 @@ def avg_pool2D_forward_naive(x, ksize, strides, paddings=[0, 0], global_pool=0): class TestPool2d_Op(OpTest): def setUp(self): self.initTestCase() - 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.global_pool) @@ -71,7 +70,8 @@ class TestPool2d_Op(OpTest): self.check_grad(set(['X']), 'Out', max_relative_error=0.07) def initTestCase(self): - self.global_pool = 0 + self.global_pool = True + self.op_type = "pool2d" self.pool_type = "avg" self.pool2D_forward_naive = avg_pool2D_forward_naive self.shape = [2, 3, 5, 5] @@ -82,23 +82,23 @@ class TestPool2d_Op(OpTest): class TestCase1(TestPool2d_Op): def initTestCase(self): - self.global_pool = 0 + self.global_pool = False self.op_type = "pool2d" self.pool_type = "avg" self.pool2D_forward_naive = avg_pool2D_forward_naive - self.shape = [2, 3, 5, 5] + self.shape = [2, 3, 7, 7] self.ksize = [3, 3] self.strides = [1, 1] - self.paddings = [1, 1] + self.paddings = [0, 0] class TestCase2(TestPool2d_Op): def initTestCase(self): - self.global_pool = 1 + self.global_pool = False self.op_type = "pool2d" self.pool_type = "avg" self.pool2D_forward_naive = avg_pool2D_forward_naive - self.shape = [2, 3, 5, 5] + self.shape = [2, 3, 7, 7] self.ksize = [3, 3] self.strides = [1, 1] self.paddings = [1, 1] @@ -106,23 +106,35 @@ class TestCase2(TestPool2d_Op): class TestCase3(TestPool2d_Op): def initTestCase(self): - self.global_pool = 0 + self.global_pool = True 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] + self.paddings = [0, 0] -class TestCase4(TestPool2d_Op): +class TestCase3(TestPool2d_Op): def initTestCase(self): - self.global_pool = 1 + self.global_pool = False self.op_type = "pool2d" self.pool_type = "max" self.pool2D_forward_naive = max_pool2D_forward_naive - self.shape = [2, 3, 5, 5] + self.shape = [2, 3, 7, 7] + self.ksize = [3, 3] + self.strides = [1, 1] + self.paddings = [0, 0] + + +class TestCase3(TestPool2d_Op): + def initTestCase(self): + self.global_pool = False + self.op_type = "pool2d" + self.pool_type = "max" + self.pool2D_forward_naive = max_pool2D_forward_naive + self.shape = [2, 3, 7, 7] self.ksize = [3, 3] self.strides = [1, 1] self.paddings = [1, 1] diff --git a/python/paddle/v2/framework/tests/test_pool3d_op.py b/python/paddle/v2/framework/tests/test_pool3d_op.py index 2a3de89a70..f041ff9178 100644 --- a/python/paddle/v2/framework/tests/test_pool3d_op.py +++ b/python/paddle/v2/framework/tests/test_pool3d_op.py @@ -55,7 +55,6 @@ def avg_pool3D_forward_naive(x, ksize, strides, paddings=[0, 0], global_pool=0): class TestPool3d_Op(OpTest): def setUp(self): self.initTestCase() - 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.global_pool) @@ -79,7 +78,8 @@ class TestPool3d_Op(OpTest): self.check_grad(set(['X']), 'Out', max_relative_error=0.07) def initTestCase(self): - self.global_pool = 0 + self.global_pool = True + self.op_type = "pool3d" self.pool_type = "avg" self.pool3D_forward_naive = avg_pool3D_forward_naive self.shape = [2, 3, 5, 5, 5] @@ -90,19 +90,19 @@ class TestPool3d_Op(OpTest): class TestCase1(TestPool3d_Op): def initTestCase(self): - self.global_pool = 0 + self.global_pool = False self.op_type = "pool3d" self.pool_type = "avg" self.pool3D_forward_naive = avg_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] + self.paddings = [0, 0, 0] class TestCase2(TestPool3d_Op): def initTestCase(self): - self.global_pool = 1 + self.global_pool = False self.op_type = "pool3d" self.pool_type = "avg" self.pool3D_forward_naive = avg_pool3D_forward_naive @@ -114,23 +114,35 @@ class TestCase2(TestPool3d_Op): class TestCase3(TestPool3d_Op): def initTestCase(self): - self.global_pool = 0 + self.global_pool = True 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] + self.paddings = [0, 0, 0] -class TestCase4(TestPool3d_Op): +class TestCase3(TestPool3d_Op): def initTestCase(self): - self.global_pool = 1 + self.global_pool = False self.op_type = "pool3d" self.pool_type = "max" self.pool3D_forward_naive = max_pool3D_forward_naive - self.shape = [2, 3, 5, 5, 5] + self.shape = [2, 3, 7, 7, 7] + self.ksize = [3, 3, 3] + self.strides = [1, 1, 1] + self.paddings = [0, 0, 0] + + +class TestCase3(TestPool3d_Op): + def initTestCase(self): + self.global_pool = False + self.op_type = "pool3d" + self.pool_type = "max" + self.pool3D_forward_naive = max_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] -- GitLab