提交 3937acc7 authored 作者: Nicolas Ballas's avatar Nicolas Ballas 提交者: Pascal Lamblin

update

上级 538350dc
...@@ -11,15 +11,15 @@ import theano.tensor.nnet.abstract_conv2d as conv ...@@ -11,15 +11,15 @@ import theano.tensor.nnet.abstract_conv2d as conv
from theano.sandbox.cuda import float32_shared_constructor as shared from theano.sandbox.cuda import float32_shared_constructor as shared
from theano.sandbox.cuda.tests.test_conv_cuda_ndarray import py_conv from theano.sandbox.cuda.tests.test_conv_cuda_ndarray import py_conv
from theano.sandbox.cuda.dnn import dnn_available #from theano.sandbox.cuda.dnn import dnn_available
if theano.config.mode == 'FAST_COMPILE': if theano.config.mode == 'FAST_COMPILE':
mode_with_gpu = theano.compile.mode.get_mode('FAST_RUN').including('gpu') #mode_with_gpu = theano.compile.mode.get_mode('FAST_RUN').including('gpu')
mode_without_gpu = theano.compile.mode.get_default_mode().excluding('gpu') mode_without_gpu = theano.compile.mode.get_mode('FAST_RUN').excluding('gpu')
else: else:
mode_with_gpu = theano.compile.mode.get_default_mode().including('gpu') #mode_with_gpu = theano.compile.mode.get_default_mode().including('gpu')
mode_without_gpu = theano.compile.mode.get_default_mode().excluding('gpu') mode_without_gpu = theano.compile.mode.get_mode('FAST_RUN').excluding('gpu')
class TestConv2d(unittest.TestCase): class TestConv2d(unittest.TestCase):
...@@ -29,7 +29,7 @@ class TestConv2d(unittest.TestCase): ...@@ -29,7 +29,7 @@ class TestConv2d(unittest.TestCase):
filters_shape, filters_shape,
subsample=(1, 1), subsample=(1, 1),
verify_grad=True, verify_grad=True,
mode=mode_with_gpu): mode=mode_without_gpu):
inputs_val = numpy.random.random(inputs_shape).astype('float32') inputs_val = numpy.random.random(inputs_shape).astype('float32')
filters_val = numpy.random.random(filters_shape).astype('float32') filters_val = numpy.random.random(filters_shape).astype('float32')
...@@ -44,17 +44,20 @@ class TestConv2d(unittest.TestCase): ...@@ -44,17 +44,20 @@ class TestConv2d(unittest.TestCase):
border_mode="valid", subsample=subsample) border_mode="valid", subsample=subsample)
f_ref = theano.function([], c_ref, mode=mode_with_gpu) f_ref = theano.function([], c_ref, mode=mode)
f = theano.function([], c, mode) f = theano.function([], c, mode)
res_ref = f_ref() res_ref = f_ref()
res = f() res = f()
print res_ref.shape, res.shape print res_ref.shape, res.shape
utt.assert_allclose(res_ref, res) utt.assert_allclose(res_ref, res)
# if verify_grad: if verify_grad:
# utt.verify_grad(conv.AbstractConv2d(border_mode="valid", utt.verify_grad(conv.AbstractConv2d(border_mode="valid",
# subsample=subsample), imshp=inputs_shape,
# [inputs_val, filters_val]) kshp=filters_shape,
bsize=inputs_shape[0],
subsample=subsample),
[inputs_val, filters_val])
def run_gradweight(self, def run_gradweight(self,
...@@ -62,25 +65,26 @@ class TestConv2d(unittest.TestCase): ...@@ -62,25 +65,26 @@ class TestConv2d(unittest.TestCase):
filters_shape, filters_shape,
subsample=(1, 1), subsample=(1, 1),
verify_grad=True, verify_grad=True,
mode=mode_with_gpu): mode=mode_without_gpu):
inputs_val = numpy.random.random(inputs_shape).astype('float32') inputs_val = numpy.random.random(inputs_shape).astype('float32')
filters_val = numpy.random.random(filters_shape).astype('float32') filters_val = numpy.random.random(filters_shape).astype('float32')
inputs = shared(inputs_val.transpose((1, 0, 2, 3))) inputs = shared(inputs_val.transpose((1, 0, 2, 3)))
filters = shared(filters_val.transpose((1, 0, 2, 3))[:,:,::-1,::-1]) filters = shared(filters_val.transpose((1, 0, 2, 3))[:,:,:,:])
c = conv.AbstractConv2d_gradWeights(border_mode="valid", c = conv.AbstractConv2d_gradWeights(border_mode="valid",
subsample=subsample) subsample=subsample)
c = c(inputs, filters) c = c(inputs, filters, inputs_shape)
f = theano.function([], c, mode) f = theano.function([], c, mode)
res_ref = py_conv(inputs_val, filters_val, 'valid', subsample) res_ref = py_conv(inputs_val, filters_val, 'valid', subsample)
print res_ref.shape, numpy.array(f()).shape
res = numpy.array(f()).transpose((1, 0, 2, 3)) res = numpy.array(f()).transpose((1, 0, 2, 3))
utt.assert_allclose(res_ref, res) utt.assert_allclose(res_ref, res)
# if verify_grad: if verify_grad:
# utt.verify_grad(conv.AbstractConv2d(border_mode="valid", utt.verify_grad(conv.AbstractConv2d(border_mode="valid",
# subsample=subsample), subsample=subsample),
# [inputs_val, filters_val]) [inputs_val, filters_val])
def run_gradinput(self, def run_gradinput(self,
...@@ -88,76 +92,78 @@ class TestConv2d(unittest.TestCase): ...@@ -88,76 +92,78 @@ class TestConv2d(unittest.TestCase):
filters_shape, filters_shape,
subsample=(1, 1), subsample=(1, 1),
verify_grad=True, verify_grad=True,
mode=mode_with_gpu): mode=mode_without_gpu):
inputs_val = numpy.random.random(inputs_shape).astype('float32') inputs_val = numpy.random.random(inputs_shape).astype('float32')
filters_val = numpy.random.random(filters_shape).astype('float32') filters_val = numpy.random.random(filters_shape).astype('float32')
inputs = shared(inputs_val) inputs = shared(inputs_val)
filters = shared(filters_val.transpose(1, 0, 2, 3)) filters = shared(filters_val.transpose(1, 0, 2, 3)[:, :, ::-1, ::-1])
c = conv.AbstractConv2d_gradInputs(border_mode="valid", c = conv.AbstractConv2d_gradInputs(border_mode="valid",
subsample=subsample) subsample=subsample)
c = c(filters, inputs) c = c(filters, inputs, inputs_shape)
f = theano.function([], c, mode) f = theano.function([], c, mode)
res_ref = py_conv(inputs_val, filters_val, 'full', subsample) res_ref = py_conv(inputs_val, filters_val, 'full', subsample)
res = numpy.array(f()) #.transpose((1, 0, 2, 3)) res = numpy.array(f()) #.transpose((1, 0, 2, 3))
print "2, ", res_ref.shape, res.shape print "2, ", res_ref.shape, res.shape
utt.assert_allclose(res_ref, res) utt.assert_allclose(res_ref, res)
# if verify_grad: if verify_grad:
# utt.verify_grad(conv.AbstractConv2d(border_mode="valid", utt.verify_grad(conv.AbstractConv2d(border_mode="valid",
# subsample=subsample), subsample=subsample),
# [inputs_val, filters_val]) [inputs_val, filters_val])
# def test_corrmm(self):
# mode = mode_with_gpu
# mode = mode.excluding('cudnn')
# self.run_conv(inputs_shape=(16, 1, 2, 2),
# filters_shape=(10, 1, 2, 2),
# verify_grad=False, mode=mode)
# self.run_gradweight(inputs_shape=(16, 1, 2, 2),
# filters_shape=(10, 1, 2, 2),
# verify_grad=False, mode=mode)
# self.run_gradinput(inputs_shape=(1, 1, 2, 2),
# filters_shape=(10, 1, 2, 2),
# verify_grad=False, mode=mode)
def test_valid(self):
mode = mode_with_gpu
if dnn_available():
self.run_conv(inputs_shape=(16, 1, 2, 2),
filters_shape=(10, 1, 2, 2),
verify_grad=False, mode=mode)
self.run_gradweight(inputs_shape=(16, 1, 2, 2),
filters_shape=(10, 1, 2, 2),
verify_grad=False, mode=mode)
self.run_gradinput(inputs_shape=(1, 1, 2, 2),
filters_shape=(10, 1, 2, 2),
verify_grad=False, mode=mode)
mode = mode.excluding('cudnn') def test_cpu(self):
self.run_conv(inputs_shape=(16, 1, 2, 2),
filters_shape=(10, 1, 2, 2),
verify_grad=False, mode=mode)
self.run_gradweight(inputs_shape=(16, 1, 2, 2),
filters_shape=(10, 1, 2, 2),
verify_grad=False, mode=mode)
self.run_gradinput(inputs_shape=(1, 1, 2, 2),
filters_shape=(10, 1, 2, 2),
verify_grad=False, mode=mode)
mode = mode_without_gpu
self.run_conv(inputs_shape=(16, 1, 2, 2), self.run_conv(inputs_shape=(16, 1, 2, 2),
filters_shape=(10, 1, 2, 2), filters_shape=(10, 1, 2, 2),
verify_grad=False, mode=mode) verify_grad=True,
self.run_gradweight(inputs_shape=(16, 1, 2, 2), mode=mode_without_gpu)
filters_shape=(10, 1, 2, 2), # self.run_gradweight(inputs_shape=(16, 1, 2, 2),
verify_grad=False, mode=mode) # filters_shape=(10, 1, 2, 2),
self.run_gradinput(inputs_shape=(1, 1, 2, 2), # verify_grad=False, mode=mode_without_gpu)
filters_shape=(10, 1, 2, 2), #self.run_gradinput(inputs_shape=(1, 1, 2, 2),
verify_grad=False, mode=mode) # filters_shape=(10, 1, 2, 2),
# verify_grad=False, mode=mode_without_gpu)
# mode = mode_without_gpu
# self.run_conv(inputs_shape=(16, 1, 8, 8),
# filters_shape=(10, 1, 4, 4),
# subsample=(2, 2),
# verify_grad=False,mode=mode)
# self.run_conv(inputs_shape=(16, 1, 2, 2), # self.run_conv(inputs_shape=(16, 1, 2, 2),
# filters_shape=(10, 1, 2, 2), # filters_shape=(10, 1, 2, 2),
# verify_grad=True,mode=mode) # verify_grad=False, mode=mode)
# self.run_conv(inputs_shape=(16, 1, 8, 8), # self.run_gradweight(inputs_shape=(16, 1, 2, 2),
# filters_shape=(10, 1, 2, 2), # filters_shape=(10, 1, 2, 2),
# subsample=(2, 2), # verify_grad=False, mode=mode)
# verify_grad=True,mode=mode) # self.run_gradinput(inputs_shape=(1, 1, 2, 2),
# filters_shape=(10, 1, 2, 2),
# verify_grad=False, mode=mode)
# # self.run_conv(inputs_shape=(16, 1, 8, 8),
# # filters_shape=(10, 1, 4, 4),
# # subsample=(2, 2),
# # verify_grad=False,mode=mode)
# # self.run_conv(inputs_shape=(16, 1, 2, 2),
# # filters_shape=(10, 1, 2, 2),
# # verify_grad=True,mode=mode)
# # self.run_conv(inputs_shape=(16, 1, 8, 8),
# # filters_shape=(10, 1, 2, 2),
# # subsample=(2, 2),
# # verify_grad=True,mode=mode)
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论