提交 0c57414e authored 作者: Frédéric Bastien's avatar Frédéric Bastien 提交者: GitHub

Merge pull request #4654 from slefrancois/yield_test_absconv

yield test in test_abstract_conv for tensor.nnet, sandbox.cuda and gpuarray
...@@ -15,11 +15,12 @@ gpu_ftensor4 = GpuArrayType(dtype='float32', broadcastable=(False,) * 4) ...@@ -15,11 +15,12 @@ gpu_ftensor4 = GpuArrayType(dtype='float32', broadcastable=(False,) * 4)
class TestDnnConv2d(test_abstract_conv.BaseTestConv2d): class TestDnnConv2d(test_abstract_conv.BaseTestConv2d):
def setUp(self): @classmethod
super(TestDnnConv2d, self).setUp() def setup_class(cls):
self.shared = gpuarray_shared_constructor test_abstract_conv.BaseTestConv2d.setup_class()
cls.shared = staticmethod(gpuarray_shared_constructor)
# provide_shape is not used by the cuDNN impementation # provide_shape is not used by the cuDNN impementation
self.provide_shape = [False] cls.provide_shape = [False]
def tcase(self, i, f, s, b, flip, provide_shape, fd=(1, 1)): def tcase(self, i, f, s, b, flip, provide_shape, fd=(1, 1)):
if not dnn_available(test_ctx_name): if not dnn_available(test_ctx_name):
......
...@@ -23,11 +23,12 @@ else: ...@@ -23,11 +23,12 @@ else:
class TestDnnConv2d(test_abstract_conv.BaseTestConv2d): class TestDnnConv2d(test_abstract_conv.BaseTestConv2d):
def setUp(self): @classmethod
super(TestDnnConv2d, self).setUp() def setup_class(cls):
test_abstract_conv.BaseTestConv2d.setup_class()
# provide_shape is not used by the cuDNN impementation # provide_shape is not used by the cuDNN impementation
self.provide_shape = [False] cls.provide_shape = [False]
self.shared = gpu_shared cls.shared = staticmethod(gpu_shared)
def tcase(self, i, f, s, b, flip, provide_shape, fd=(1, 1)): def tcase(self, i, f, s, b, flip, provide_shape, fd=(1, 1)):
if fd != (1, 1): if fd != (1, 1):
...@@ -56,10 +57,11 @@ class TestDnnConv2d(test_abstract_conv.BaseTestConv2d): ...@@ -56,10 +57,11 @@ class TestDnnConv2d(test_abstract_conv.BaseTestConv2d):
class TestCorrMMConv2d(test_abstract_conv.BaseTestConv2d): class TestCorrMMConv2d(test_abstract_conv.BaseTestConv2d):
def setUp(self): @classmethod
super(TestCorrMMConv2d, self).setUp() def setup_class(cls):
self.shared = gpu_shared test_abstract_conv.BaseTestConv2d.setup_class()
self.mode = mode_with_gpu.excluding('cudnn') cls.shared = staticmethod(gpu_shared)
cls.mode = mode_with_gpu.excluding('cudnn')
def tcase(self, i, f, s, b, flip, provide_shape, fd=(1, 1)): def tcase(self, i, f, s, b, flip, provide_shape, fd=(1, 1)):
mode = self.mode mode = self.mode
......
...@@ -3,7 +3,8 @@ import unittest ...@@ -3,7 +3,8 @@ import unittest
import numpy import numpy
import numpy as np import numpy as np
from nose.plugins.skip import SkipTest from nose.plugins.skip import SkipTest
from nose.tools import assert_raises from nose.tools import assert_raises, assert_true
import theano import theano
from theano import tensor from theano import tensor
from theano.gof.opt import check_stack_trace from theano.gof.opt import check_stack_trace
...@@ -77,20 +78,21 @@ class TestGetConvOutShape(unittest.TestCase): ...@@ -77,20 +78,21 @@ class TestGetConvOutShape(unittest.TestCase):
self.assertTrue(test4_params == (3, 4, 6, 4)) self.assertTrue(test4_params == (3, 4, 6, 4))
class BaseTestConv2d(unittest.TestCase): class BaseTestConv2d:
def setUp(self): @classmethod
def setup_class(cls):
if theano.config.blas.ldflags == '': if theano.config.blas.ldflags == '':
raise SkipTest("BLAS required for reference") raise SkipTest("BLAS required for reference")
self.inputs_shapes = [(8, 1, 6, 6), (8, 1, 8, 8), (2, 1, 7, 7), cls.inputs_shapes = [(8, 1, 6, 6), (8, 1, 8, 8), (2, 1, 7, 7),
(6, 1, 10, 11), (2, 1, 6, 5), (1, 5, 9, 9)] (6, 1, 10, 11), (2, 1, 6, 5), (1, 5, 9, 9)]
self.filters_shapes = [(5, 1, 2, 2), (4, 1, 3, 3), (2, 1, 3, 3), cls.filters_shapes = [(5, 1, 2, 2), (4, 1, 3, 3), (2, 1, 3, 3),
(1, 1, 2, 3), (4, 1, 1, 3), (4, 5, 3, 2)] (1, 1, 2, 3), (4, 1, 1, 3), (4, 5, 3, 2)]
self.subsamples = [(1, 1), (2, 2), (2, 4)] cls.subsamples = [(1, 1), (2, 2), (2, 4)]
self.filters_dilations = [(1, 1), (1, 2), (2, 1)] cls.filters_dilations = [(1, 1), (1, 2), (2, 1)]
self.border_modes = ["valid", "full", (0, 0), (1, 1), (5, 5), (5, 2)] cls.border_modes = ["valid", "full", (0, 0), (1, 1), (5, 5), (5, 2)]
self.filter_flip = [True, False] cls.filter_flip = [True, False]
self.provide_shape = [True, False] cls.provide_shape = [True, False]
self.shared = theano.compile.shared cls.shared = staticmethod(theano.compile.shared)
def get_output_shape(self, inputs_shape, filters_shape, def get_output_shape(self, inputs_shape, filters_shape,
subsample, border_mode, filter_dilation): subsample, border_mode, filter_dilation):
...@@ -153,7 +155,7 @@ class BaseTestConv2d(unittest.TestCase): ...@@ -153,7 +155,7 @@ class BaseTestConv2d(unittest.TestCase):
assert any([isinstance(n.op, target_op) for n assert any([isinstance(n.op, target_op) for n
in f.maker.fgraph.toposort()]) in f.maker.fgraph.toposort()])
if check_trace: if check_trace:
self.assertTrue(check_stack_trace(f, ops_to_check=target_op)) assert_true(check_stack_trace(f, ops_to_check=target_op))
res_ref = numpy.array(f_ref()) res_ref = numpy.array(f_ref())
res = numpy.array(f()) res = numpy.array(f())
...@@ -207,7 +209,7 @@ class BaseTestConv2d(unittest.TestCase): ...@@ -207,7 +209,7 @@ class BaseTestConv2d(unittest.TestCase):
assert any([isinstance(n.op, target_op) for n assert any([isinstance(n.op, target_op) for n
in f.maker.fgraph.toposort()]) in f.maker.fgraph.toposort()])
if check_trace: if check_trace:
self.assertTrue(check_stack_trace(f, ops_to_check=target_op)) assert_true(check_stack_trace(f, ops_to_check=target_op))
res_ref = numpy.array(f_ref()) res_ref = numpy.array(f_ref())
res = numpy.array(f()) res = numpy.array(f())
...@@ -260,7 +262,7 @@ class BaseTestConv2d(unittest.TestCase): ...@@ -260,7 +262,7 @@ class BaseTestConv2d(unittest.TestCase):
assert any([isinstance(n.op, target_op) for n assert any([isinstance(n.op, target_op) for n
in f.maker.fgraph.toposort()]) in f.maker.fgraph.toposort()])
if check_trace: if check_trace:
self.assertTrue(check_stack_trace(f, ops_to_check=target_op)) assert_true(check_stack_trace(f, ops_to_check=target_op))
res_ref = numpy.array(f_ref()) res_ref = numpy.array(f_ref())
res = numpy.array(f()) res = numpy.array(f())
...@@ -284,36 +286,24 @@ class BaseTestConv2d(unittest.TestCase): ...@@ -284,36 +286,24 @@ class BaseTestConv2d(unittest.TestCase):
db = (0, 0) db = (0, 0)
dflip = True in self.filter_flip dflip = True in self.filter_flip
dprovide_shape = True in self.provide_shape dprovide_shape = True in self.provide_shape
skipped = False
for (i, f) in zip(self.inputs_shapes, self.filters_shapes): for (i, f) in zip(self.inputs_shapes, self.filters_shapes):
for provide_shape in self.provide_shape: for provide_shape in self.provide_shape:
try: yield (self.tcase, i, f, ds, db, dflip, provide_shape)
self.tcase(i, f, ds, db, dflip, provide_shape)
except SkipTest as e:
skipped = e
for fd in self.filters_dilations: for fd in self.filters_dilations:
for s in self.subsamples: for s in self.subsamples:
for b in self.border_modes: for b in self.border_modes:
try: yield (self.tcase, i, f, s, db, dflip,
self.tcase(i, f, s, db, dflip,
dprovide_shape, fd) dprovide_shape, fd)
except SkipTest as e:
skipped = e
for flip in self.filter_flip: for flip in self.filter_flip:
try: yield (self.tcase, i, f, ds, db, flip, dprovide_shape)
self.tcase(i, f, ds, db, flip,
dprovide_shape)
except SkipTest as e:
skipped = e
if skipped:
raise skipped
class TestCorrConv2d(BaseTestConv2d): class TestCorrConv2d(BaseTestConv2d):
def setUp(self): @classmethod
def setup_class(cls):
if theano.config.blas.ldflags == "": if theano.config.blas.ldflags == "":
raise SkipTest() raise SkipTest()
return super(TestCorrConv2d, self).setUp() BaseTestConv2d.setup_class()
def tcase(self, i, f, s, b, flip, provide_shape, fd=(1, 1)): def tcase(self, i, f, s, b, flip, provide_shape, fd=(1, 1)):
o = self.get_output_shape(i, f, s, b, fd) o = self.get_output_shape(i, f, s, b, fd)
...@@ -339,14 +329,16 @@ class TestCorrConv2d(BaseTestConv2d): ...@@ -339,14 +329,16 @@ class TestCorrConv2d(BaseTestConv2d):
class TestCpuConv2d(BaseTestConv2d): class TestCpuConv2d(BaseTestConv2d):
def setUp(self): @classmethod
super(TestCpuConv2d, self).setUp() def setup(cls):
self.mode = theano.compile.mode.get_default_mode().excluding('conv_gemm') BaseTestConv2d.setup_class()
self.opt_err = theano.config.on_opt_error cls.mode = theano.compile.mode.get_default_mode().excluding('conv_gemm')
cls.opt_err = theano.config.on_opt_error
theano.config.on_opt_error = 'ignore' theano.config.on_opt_error = 'ignore'
def tearDown(self): @classmethod
theano.config.on_opt_error = self.opt_err def tearDown(cls):
theano.config.on_opt_error = cls.opt_err
def tcase(self, i, f, s, b, flip, provide_shape, fd=(1, 1)): def tcase(self, i, f, s, b, flip, provide_shape, fd=(1, 1)):
if fd != (1, 1): if fd != (1, 1):
...@@ -385,7 +377,7 @@ class TestCpuConv2d(BaseTestConv2d): ...@@ -385,7 +377,7 @@ class TestCpuConv2d(BaseTestConv2d):
check_trace=True, filter_dilation=fd) check_trace=True, filter_dilation=fd)
else: else:
self.assertRaises(AssertionError, assert_raises(AssertionError,
self.run_fwd, self.run_fwd,
inputs_shape=i, inputs_shape=i,
filters_shape=f, filters_shape=f,
...@@ -410,7 +402,7 @@ class TestCpuConv2d(BaseTestConv2d): ...@@ -410,7 +402,7 @@ class TestCpuConv2d(BaseTestConv2d):
check_trace=True, check_trace=True,
filter_dilation=fd) filter_dilation=fd)
else: else:
self.assertRaises(AssertionError, assert_raises(AssertionError,
self.run_gradweight, self.run_gradweight,
inputs_shape=i, inputs_shape=i,
filters_shape=f, filters_shape=f,
...@@ -436,7 +428,7 @@ class TestCpuConv2d(BaseTestConv2d): ...@@ -436,7 +428,7 @@ class TestCpuConv2d(BaseTestConv2d):
check_trace=True, check_trace=True,
filter_dilation=fd) filter_dilation=fd)
else: else:
self.assertRaises(AssertionError, assert_raises(AssertionError,
self.run_gradinput, self.run_gradinput,
inputs_shape=i, inputs_shape=i,
filters_shape=f, filters_shape=f,
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论