提交 6e85e214 authored 作者: AdeB's avatar AdeB 提交者: Pascal Lamblin

Add check_trace argument in test_abstract_conv.py functions

上级 c720cafa
......@@ -99,7 +99,7 @@ class BaseTestConv2d(unittest.TestCase):
def run_fwd(self, inputs_shape, filters_shape, ref=conv_corr,
subsample=(1, 1), verify_grad=True, mode=None,
border_mode='valid', filter_flip=True, provide_shape=False,
target_op=None):
target_op=None, check_trace=False):
inputs_val = numpy.random.random(inputs_shape).astype('float32')
filters_val = numpy.random.random(filters_shape).astype('float32')
......@@ -135,7 +135,8 @@ class BaseTestConv2d(unittest.TestCase):
assert any([isinstance(n.op, target_op) for n
in f.maker.fgraph.toposort()])
self.assertTrue(check_stack_trace(f, ops_to_check='all'))
if check_trace:
self.assertTrue(check_stack_trace(f, ops_to_check='all'))
res_ref = numpy.array(f_ref())
res = numpy.array(f())
utt.assert_allclose(res_ref, res)
......@@ -149,7 +150,7 @@ class BaseTestConv2d(unittest.TestCase):
def run_gradweight(self, inputs_shape, filters_shape, output_shape,
ref=conv_corr_gw, subsample=(1, 1), filter_flip=True,
verify_grad=True, mode=None, border_mode='valid',
provide_shape=False, target_op=None):
provide_shape=False, target_op=None, check_trace=False):
inputs_val = numpy.random.random(inputs_shape).astype('float32')
output_val = numpy.random.random(output_shape).astype('float32')
......@@ -178,7 +179,8 @@ class BaseTestConv2d(unittest.TestCase):
subsample=subsample,
conv_mode=conv_mode)
f = theano.function([], c, mode=mode)
self.assertTrue(check_stack_trace(f, ops_to_check='all'))
if check_trace:
self.assertTrue(check_stack_trace(f, ops_to_check='all'))
f_ref = theano.function([], c_ref, mode='FAST_RUN')
if target_op is not None:
......@@ -202,7 +204,7 @@ class BaseTestConv2d(unittest.TestCase):
def run_gradinput(self, inputs_shape, filters_shape, output_shape,
ref=conv_corr_gi, subsample=(1, 1), filter_flip=True,
verify_grad=True, mode=None, border_mode='valid',
provide_shape=False, target_op=None):
provide_shape=False, target_op=None, check_trace=False):
output_val = numpy.random.random(output_shape).astype('float32')
filters_val = numpy.random.random(filters_shape).astype('float32')
......@@ -228,7 +230,8 @@ class BaseTestConv2d(unittest.TestCase):
border_mode=border_mode, subsample=subsample,
conv_mode=conv_mode)
f = theano.function([], c, mode=mode)
self.assertTrue(check_stack_trace(f, ops_to_check='all'))
if check_trace:
self.assertTrue(check_stack_trace(f, ops_to_check='all'))
f_ref = theano.function([], c_ref, mode='FAST_RUN')
if target_op is not None:
......@@ -292,15 +295,18 @@ class TestCorrConv2d(BaseTestConv2d):
raise SkipTest("Need blas to test conv2d")
self.run_fwd(inputs_shape=i, filters_shape=f, subsample=s,
verify_grad=True, provide_shape=provide_shape,
border_mode=b, filter_flip=flip, target_op=CorrMM)
border_mode=b, filter_flip=flip, target_op=CorrMM,
check_trace=True)
self.run_gradweight(inputs_shape=i, filters_shape=f,
output_shape=o, subsample=s, verify_grad=True,
provide_shape=provide_shape, border_mode=b,
filter_flip=flip, target_op=CorrMM_gradWeights)
filter_flip=flip, target_op=CorrMM_gradWeights,
check_trace=True)
self.run_gradinput(inputs_shape=i, filters_shape=f,
output_shape=o, subsample=s, verify_grad=True,
provide_shape=provide_shape, border_mode=b,
filter_flip=flip, target_op=CorrMM_gradInputs)
filter_flip=flip, target_op=CorrMM_gradInputs,
check_trace=True)
class TestCpuConv2d(BaseTestConv2d):
......@@ -344,7 +350,8 @@ class TestCpuConv2d(BaseTestConv2d):
self.run_fwd(inputs_shape=i, filters_shape=f, subsample=s,
verify_grad=(gradweight_OK and gradinput_OK),
mode=mode, provide_shape=provide_shape,
border_mode=b, filter_flip=flip, target_op=ConvOp)
border_mode=b, filter_flip=flip, target_op=ConvOp,
check_trace=True)
else:
self.assertRaises(AssertionError,
self.run_fwd,
......@@ -355,7 +362,8 @@ class TestCpuConv2d(BaseTestConv2d):
mode=mode,
provide_shape=provide_shape,
border_mode=b,
filter_flip=flip)
filter_flip=flip,
check_trace=True)
if gradweight_OK:
if not theano.config.blas.ldflags:
......@@ -365,7 +373,8 @@ class TestCpuConv2d(BaseTestConv2d):
verify_grad=False, mode=mode,
provide_shape=provide_shape, border_mode=b,
filter_flip=flip,
target_op=(ConvOp, ConvGrad3D))
target_op=(ConvOp, ConvGrad3D),
check_trace=True)
else:
self.assertRaises(AssertionError,
self.run_gradweight,
......@@ -377,7 +386,8 @@ class TestCpuConv2d(BaseTestConv2d):
mode=mode,
provide_shape=provide_shape,
border_mode=b,
filter_flip=flip)
filter_flip=flip,
check_trace=True)
if gradinput_OK:
if not theano.config.blas.ldflags:
......@@ -387,7 +397,8 @@ class TestCpuConv2d(BaseTestConv2d):
verify_grad=False, mode=mode,
provide_shape=provide_shape, border_mode=b,
filter_flip=flip,
target_op=(ConvOp, ConvTransp3D))
target_op=(ConvOp, ConvTransp3D),
check_trace=True)
else:
self.assertRaises(AssertionError,
self.run_gradinput,
......@@ -399,7 +410,8 @@ class TestCpuConv2d(BaseTestConv2d):
mode=mode,
provide_shape=provide_shape,
border_mode=b,
filter_flip=flip)
filter_flip=flip,
check_trace=True)
def test_constant_shapes():
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论