|
|
|
@ -3,8 +3,7 @@ import numpy as np
|
|
|
|
|
from op_test import OpTest
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def max_pool2D_forward_naive(x, ksize, strides, paddings=[0, 0], global_pool=0):
|
|
|
|
|
|
|
|
|
|
def max_pool2D_forward_naive(x, ksize, strides, paddings, global_pool=0):
|
|
|
|
|
N, C, H, W = x.shape
|
|
|
|
|
if global_pool == 1:
|
|
|
|
|
ksize = [H, W]
|
|
|
|
@ -23,8 +22,7 @@ def max_pool2D_forward_naive(x, ksize, strides, paddings=[0, 0], global_pool=0):
|
|
|
|
|
return out
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def avg_pool2D_forward_naive(x, ksize, strides, paddings=[0, 0], global_pool=0):
|
|
|
|
|
|
|
|
|
|
def avg_pool2D_forward_naive(x, ksize, strides, paddings, global_pool=0):
|
|
|
|
|
N, C, H, W = x.shape
|
|
|
|
|
if global_pool == 1:
|
|
|
|
|
ksize = [H, W]
|
|
|
|
@ -47,6 +45,7 @@ def avg_pool2D_forward_naive(x, ksize, strides, paddings=[0, 0], global_pool=0):
|
|
|
|
|
class TestPool2d_Op(OpTest):
|
|
|
|
|
def setUp(self):
|
|
|
|
|
self.init_test_case()
|
|
|
|
|
self.init_global_pool()
|
|
|
|
|
self.init_op_type()
|
|
|
|
|
self.init_pool_type()
|
|
|
|
|
if self.global_pool:
|
|
|
|
@ -75,8 +74,6 @@ class TestPool2d_Op(OpTest):
|
|
|
|
|
self.check_grad(set(['X']), 'Out', max_relative_error=0.07)
|
|
|
|
|
|
|
|
|
|
def init_test_case(self):
|
|
|
|
|
self.global_pool = True
|
|
|
|
|
self.pool2D_forward_naive = avg_pool2D_forward_naive
|
|
|
|
|
self.shape = [2, 3, 5, 5]
|
|
|
|
|
self.ksize = [3, 3]
|
|
|
|
|
self.strides = [1, 1]
|
|
|
|
@ -87,12 +84,14 @@ class TestPool2d_Op(OpTest):
|
|
|
|
|
|
|
|
|
|
def init_pool_type(self):
|
|
|
|
|
self.pool_type = "avg"
|
|
|
|
|
self.pool2D_forward_naive = avg_pool2D_forward_naive
|
|
|
|
|
|
|
|
|
|
def init_global_pool(self):
|
|
|
|
|
self.global_pool = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestCase1(TestPool2d_Op):
|
|
|
|
|
def init_test_case(self):
|
|
|
|
|
self.global_pool = False
|
|
|
|
|
self.pool2D_forward_naive = avg_pool2D_forward_naive
|
|
|
|
|
self.shape = [2, 3, 7, 7]
|
|
|
|
|
self.ksize = [3, 3]
|
|
|
|
|
self.strides = [1, 1]
|
|
|
|
@ -103,12 +102,14 @@ class TestCase1(TestPool2d_Op):
|
|
|
|
|
|
|
|
|
|
def init_pool_type(self):
|
|
|
|
|
self.pool_type = "avg"
|
|
|
|
|
self.pool2D_forward_naive = avg_pool2D_forward_naive
|
|
|
|
|
|
|
|
|
|
def init_global_pool(self):
|
|
|
|
|
self.global_pool = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestCase2(TestPool2d_Op):
|
|
|
|
|
def init_test_case(self):
|
|
|
|
|
self.global_pool = False
|
|
|
|
|
self.pool2D_forward_naive = avg_pool2D_forward_naive
|
|
|
|
|
self.shape = [2, 3, 7, 7]
|
|
|
|
|
self.ksize = [3, 3]
|
|
|
|
|
self.strides = [1, 1]
|
|
|
|
@ -119,152 +120,69 @@ class TestCase2(TestPool2d_Op):
|
|
|
|
|
|
|
|
|
|
def init_pool_type(self):
|
|
|
|
|
self.pool_type = "avg"
|
|
|
|
|
self.pool2D_forward_naive = avg_pool2D_forward_naive
|
|
|
|
|
|
|
|
|
|
def init_global_pool(self):
|
|
|
|
|
self.global_pool = False
|
|
|
|
|
|
|
|
|
|
class TestCase3(TestPool2d_Op):
|
|
|
|
|
def init_test_case(self):
|
|
|
|
|
self.global_pool = True
|
|
|
|
|
self.pool2D_forward_naive = max_pool2D_forward_naive
|
|
|
|
|
self.shape = [2, 3, 5, 5]
|
|
|
|
|
self.ksize = [3, 3]
|
|
|
|
|
self.strides = [1, 1]
|
|
|
|
|
self.paddings = [0, 0]
|
|
|
|
|
|
|
|
|
|
class TestCase3(TestPool2d_Op):
|
|
|
|
|
def init_op_type(self):
|
|
|
|
|
self.op_type = "pool2d"
|
|
|
|
|
|
|
|
|
|
def init_pool_type(self):
|
|
|
|
|
self.pool_type = "max"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestCase4(TestPool2d_Op):
|
|
|
|
|
def init_test_case(self):
|
|
|
|
|
self.global_pool = False
|
|
|
|
|
self.pool2D_forward_naive = max_pool2D_forward_naive
|
|
|
|
|
self.shape = [2, 3, 7, 7]
|
|
|
|
|
self.ksize = [3, 3]
|
|
|
|
|
self.strides = [1, 1]
|
|
|
|
|
self.paddings = [0, 0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestCase4(TestCase1):
|
|
|
|
|
def init_op_type(self):
|
|
|
|
|
self.op_type = "pool2d"
|
|
|
|
|
|
|
|
|
|
def init_pool_type(self):
|
|
|
|
|
self.pool_type = "max"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestCase5(TestPool2d_Op):
|
|
|
|
|
def init_test_case(self):
|
|
|
|
|
self.global_pool = False
|
|
|
|
|
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]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestCase5(TestCase2):
|
|
|
|
|
def init_op_type(self):
|
|
|
|
|
self.op_type = "pool2d"
|
|
|
|
|
|
|
|
|
|
def init_pool_type(self):
|
|
|
|
|
self.pool_type = "max"
|
|
|
|
|
self.pool2D_forward_naive = max_pool2D_forward_naive
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#--------------------test pool2d_cudnn--------------------
|
|
|
|
|
class TestCaseCudnn1(TestPool2d_Op):
|
|
|
|
|
def init_test_case(self):
|
|
|
|
|
self.global_pool = True
|
|
|
|
|
self.pool2D_forward_naive = avg_pool2D_forward_naive
|
|
|
|
|
self.shape = [2, 3, 5, 5]
|
|
|
|
|
self.ksize = [3, 3]
|
|
|
|
|
self.strides = [1, 1]
|
|
|
|
|
self.paddings = [0, 0]
|
|
|
|
|
|
|
|
|
|
class TestCudnnCase1(TestPool2d_Op):
|
|
|
|
|
def init_op_type(self):
|
|
|
|
|
self.op_type = "pool2d_cudnn"
|
|
|
|
|
|
|
|
|
|
def init_pool_type(self):
|
|
|
|
|
self.pool_type = "avg"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestCaseCudnn2(TestPool2d_Op):
|
|
|
|
|
def init_test_case(self):
|
|
|
|
|
self.global_pool = False
|
|
|
|
|
self.pool2D_forward_naive = avg_pool2D_forward_naive
|
|
|
|
|
self.shape = [2, 3, 7, 7]
|
|
|
|
|
self.ksize = [3, 3]
|
|
|
|
|
self.strides = [1, 1]
|
|
|
|
|
self.paddings = [0, 0]
|
|
|
|
|
|
|
|
|
|
class TestCudnnCase2(TestCase1):
|
|
|
|
|
def init_op_type(self):
|
|
|
|
|
self.op_type = "pool2d_cudnn"
|
|
|
|
|
|
|
|
|
|
def init_pool_type(self):
|
|
|
|
|
self.pool_type = "avg"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestCaseCudnn3(TestPool2d_Op):
|
|
|
|
|
def init_test_case(self):
|
|
|
|
|
self.global_pool = False
|
|
|
|
|
self.pool2D_forward_naive = avg_pool2D_forward_naive
|
|
|
|
|
self.shape = [2, 3, 7, 7]
|
|
|
|
|
self.ksize = [3, 3]
|
|
|
|
|
self.strides = [1, 1]
|
|
|
|
|
self.paddings = [1, 1]
|
|
|
|
|
|
|
|
|
|
class TestCudnnCase3(TestCase2):
|
|
|
|
|
def init_op_type(self):
|
|
|
|
|
self.op_type = "pool2d_cudnn"
|
|
|
|
|
|
|
|
|
|
def init_pool_type(self):
|
|
|
|
|
self.pool_type = "avg"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestCaseCudnn4(TestPool2d_Op):
|
|
|
|
|
def init_test_case(self):
|
|
|
|
|
self.global_pool = True
|
|
|
|
|
self.pool2D_forward_naive = max_pool2D_forward_naive
|
|
|
|
|
self.shape = [2, 3, 5, 5]
|
|
|
|
|
self.ksize = [3, 3]
|
|
|
|
|
self.strides = [1, 1]
|
|
|
|
|
self.paddings = [0, 0]
|
|
|
|
|
|
|
|
|
|
class TestCudnnCase4(TestCase3):
|
|
|
|
|
def init_op_type(self):
|
|
|
|
|
self.op_type = "pool2d_cudnn"
|
|
|
|
|
|
|
|
|
|
def init_pool_type(self):
|
|
|
|
|
self.pool_type = "max"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestCaseCudnn5(TestPool2d_Op):
|
|
|
|
|
def init_test_case(self):
|
|
|
|
|
self.global_pool = False
|
|
|
|
|
self.pool2D_forward_naive = max_pool2D_forward_naive
|
|
|
|
|
self.shape = [2, 3, 7, 7]
|
|
|
|
|
self.ksize = [3, 3]
|
|
|
|
|
self.strides = [1, 1]
|
|
|
|
|
self.paddings = [0, 0]
|
|
|
|
|
|
|
|
|
|
class TestCudnnCase5(TestCase4):
|
|
|
|
|
def init_op_type(self):
|
|
|
|
|
self.op_type = "pool2d_cudnn"
|
|
|
|
|
|
|
|
|
|
def init_pool_type(self):
|
|
|
|
|
self.pool_type = "max"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestCaseCudnn6(TestPool2d_Op):
|
|
|
|
|
def init_test_case(self):
|
|
|
|
|
self.global_pool = False
|
|
|
|
|
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]
|
|
|
|
|
|
|
|
|
|
class TestCudnnCase6(TestCase5):
|
|
|
|
|
def init_op_type(self):
|
|
|
|
|
self.op_type = "pool2d_cudnn"
|
|
|
|
|
|
|
|
|
|
def init_pool_type(self):
|
|
|
|
|
self.pool_type = "max"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
unittest.main()
|
|
|
|
|