提交 51c02671 authored 作者: Frederic's avatar Frederic

pep8

上级 47021839
...@@ -86,7 +86,6 @@ class TestConv2dFFT(unittest.TestCase): ...@@ -86,7 +86,6 @@ class TestConv2dFFT(unittest.TestCase):
assert sum(isinstance(n.op, theano.sandbox.cuda.fftconv.CuFFTOp) assert sum(isinstance(n.op, theano.sandbox.cuda.fftconv.CuFFTOp)
for n in topo) == 2, topo for n in topo) == 2, topo
res_ref = f_ref() res_ref = f_ref()
res_fft = f_fft() res_fft = f_fft()
...@@ -130,7 +129,8 @@ class TestConv2dFFT(unittest.TestCase): ...@@ -130,7 +129,8 @@ class TestConv2dFFT(unittest.TestCase):
inputs = shared(inputs_val) inputs = shared(inputs_val)
filters = shared(filters_val) filters = shared(filters_val)
conv = theano.tensor.nnet.conv.conv2d(inputs, filters, version='no_fft') conv = theano.tensor.nnet.conv.conv2d(inputs, filters,
version='no_fft')
mode = mode_with_gpu.including('conv_fft_valid') mode = mode_with_gpu.including('conv_fft_valid')
...@@ -178,15 +178,16 @@ class TestConv3dFFT(unittest.TestCase): ...@@ -178,15 +178,16 @@ class TestConv3dFFT(unittest.TestCase):
bias = shared(numpy.zeros(filters_shape[0]).astype('float32')) bias = shared(numpy.zeros(filters_shape[0]).astype('float32'))
# Flip filter as conv3D compute correlation # Flip filter as conv3D compute correlation
filters_flip = filters[:,::-1,::-1,::-1,:] filters_flip = filters[:, ::-1, ::-1, ::-1, :]
#filters_flip = filters # filters_flip = filters
conv_ref = theano.tensor.nnet.conv3D(V=inputs, W=filters_flip, conv_ref = theano.tensor.nnet.conv3D(V=inputs, W=filters_flip,
b=bias, d=(1,1,1)) b=bias, d=(1, 1, 1))
conv_fft = theano.sandbox.cuda.fftconv.conv3d_fft(inputs.dimshuffle(0, 4, 1, 2, 3), conv_fft = theano.sandbox.cuda.fftconv.conv3d_fft(
inputs.dimshuffle(0, 4, 1, 2, 3),
filters.dimshuffle(0, 4, 1, 2, 3), filters.dimshuffle(0, 4, 1, 2, 3),
border_mode = "valid", border_mode="valid",
pad_last_dim = pad) pad_last_dim=pad)
conv_fft = conv_fft.dimshuffle(0, 2, 3, 4, 1) conv_fft = conv_fft.dimshuffle(0, 2, 3, 4, 1)
f_ref = theano.function([], conv_ref, mode="FAST_RUN") f_ref = theano.function([], conv_ref, mode="FAST_RUN")
...@@ -198,8 +199,6 @@ class TestConv3dFFT(unittest.TestCase): ...@@ -198,8 +199,6 @@ class TestConv3dFFT(unittest.TestCase):
res_fft = f_fft() res_fft = f_fft()
utt.assert_allclose(res_ref, res_fft, rtol=1e-05, atol=1e-05) utt.assert_allclose(res_ref, res_fft, rtol=1e-05, atol=1e-05)
def run_conv_full(self, inputs_shape, filters_shape, pad=False): def run_conv_full(self, inputs_shape, filters_shape, pad=False):
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')
...@@ -208,14 +207,15 @@ class TestConv3dFFT(unittest.TestCase): ...@@ -208,14 +207,15 @@ class TestConv3dFFT(unittest.TestCase):
filters = shared(filters_val) filters = shared(filters_val)
bias = shared(numpy.zeros(filters_shape[4]).astype('float32')) bias = shared(numpy.zeros(filters_shape[4]).astype('float32'))
conv_ref = theano.tensor.nnet.convTransp3D(W=filters, b=bias, d=(1,1,1), conv_ref = theano.tensor.nnet.convTransp3D(
W=filters, b=bias, d=(1, 1, 1),
H=inputs) H=inputs)
filters = filters.dimshuffle(4, 0, 1, 2, 3) filters = filters.dimshuffle(4, 0, 1, 2, 3)
inputs = inputs.dimshuffle(0, 4, 1, 2, 3) inputs = inputs.dimshuffle(0, 4, 1, 2, 3)
conv_fft = theano.sandbox.cuda.fftconv.conv3d_fft(inputs, filters, conv_fft = theano.sandbox.cuda.fftconv.conv3d_fft(inputs, filters,
border_mode = "full", border_mode="full",
pad_last_dim = pad) pad_last_dim=pad)
conv_fft = conv_fft.dimshuffle(0, 2, 3, 4, 1) conv_fft = conv_fft.dimshuffle(0, 2, 3, 4, 1)
f_ref = theano.function([], conv_ref) f_ref = theano.function([], conv_ref)
...@@ -233,6 +233,7 @@ class TestConv3dFFT(unittest.TestCase): ...@@ -233,6 +233,7 @@ class TestConv3dFFT(unittest.TestCase):
self.run_conv_valid(inputs_shape=(16, 20, 32, 15, 1), self.run_conv_valid(inputs_shape=(16, 20, 32, 15, 1),
filters_shape=(10, 6, 12, 4, 1), filters_shape=(10, 6, 12, 4, 1),
pad=True) pad=True)
def test_full(self): def test_full(self):
self.run_conv_full(inputs_shape=(16, 15, 21, 16, 10), self.run_conv_full(inputs_shape=(16, 15, 21, 16, 10),
filters_shape=(10, 6, 12, 4, 1), filters_shape=(10, 6, 12, 4, 1),
...@@ -253,7 +254,7 @@ class TestConv3dFFT(unittest.TestCase): ...@@ -253,7 +254,7 @@ class TestConv3dFFT(unittest.TestCase):
bias = shared(numpy.zeros(filters_shape[0]).astype('float32')) bias = shared(numpy.zeros(filters_shape[0]).astype('float32'))
conv = theano.tensor.nnet.conv3D(V=inputs, W=filters, conv = theano.tensor.nnet.conv3D(V=inputs, W=filters,
b=bias, d=(1,1,1)) b=bias, d=(1, 1, 1))
mode = mode_with_gpu.including('conv3d_fft') mode = mode_with_gpu.including('conv3d_fft')
mode.check_py_code = False mode.check_py_code = False
...@@ -265,7 +266,6 @@ class TestConv3dFFT(unittest.TestCase): ...@@ -265,7 +266,6 @@ class TestConv3dFFT(unittest.TestCase):
assert sum(isinstance(n.op, theano.sandbox.cuda.fftconv.CuFFTOp) assert sum(isinstance(n.op, theano.sandbox.cuda.fftconv.CuFFTOp)
for n in topo) == 2 for n in topo) == 2
res_ref = f_ref() res_ref = f_ref()
res_fft = f_fft() res_fft = f_fft()
...@@ -284,7 +284,7 @@ class TestConv3dFFT(unittest.TestCase): ...@@ -284,7 +284,7 @@ class TestConv3dFFT(unittest.TestCase):
conv = theano.tensor.nnet.convGrad3D(V=inputs, dCdH=dCdH, conv = theano.tensor.nnet.convGrad3D(V=inputs, dCdH=dCdH,
WShape=filters_shape, WShape=filters_shape,
d=(1,1,1)) d=(1, 1, 1))
mode = mode_with_gpu.including('convgrad3d_fft') mode = mode_with_gpu.including('convgrad3d_fft')
mode.check_py_code = False mode.check_py_code = False
...@@ -296,13 +296,11 @@ class TestConv3dFFT(unittest.TestCase): ...@@ -296,13 +296,11 @@ class TestConv3dFFT(unittest.TestCase):
assert sum(isinstance(n.op, theano.sandbox.cuda.fftconv.CuFFTOp) assert sum(isinstance(n.op, theano.sandbox.cuda.fftconv.CuFFTOp)
for n in topo) == 2 for n in topo) == 2
res_ref = f_ref() res_ref = f_ref()
res_fft = f_fft() res_fft = f_fft()
utt.assert_allclose(res_ref, res_fft, rtol=1e-04, atol=1e-04) utt.assert_allclose(res_ref, res_fft, rtol=1e-04, atol=1e-04)
def test_opt_convtransp3d_fft(self): def test_opt_convtransp3d_fft(self):
inputs_shape = (16, 15, 21, 12, 10) inputs_shape = (16, 15, 21, 12, 10)
filters_shape = (10, 6, 12, 4, 1) filters_shape = (10, 6, 12, 4, 1)
...@@ -314,7 +312,7 @@ class TestConv3dFFT(unittest.TestCase): ...@@ -314,7 +312,7 @@ class TestConv3dFFT(unittest.TestCase):
inputs = shared(inputs_val) inputs = shared(inputs_val)
filters = shared(filters_val) filters = shared(filters_val)
conv = theano.tensor.nnet.convTransp3D(W=filters, b=bias, d=(1,1,1), conv = theano.tensor.nnet.convTransp3D(W=filters, b=bias, d=(1, 1, 1),
H=inputs) H=inputs)
mode = mode_with_gpu.including('convtransp3d_fft') mode = mode_with_gpu.including('convtransp3d_fft')
...@@ -326,9 +324,7 @@ class TestConv3dFFT(unittest.TestCase): ...@@ -326,9 +324,7 @@ class TestConv3dFFT(unittest.TestCase):
assert sum(isinstance(n.op, theano.sandbox.cuda.fftconv.CuFFTOp) assert sum(isinstance(n.op, theano.sandbox.cuda.fftconv.CuFFTOp)
for n in topo) == 2 for n in topo) == 2
res_ref = f_ref() res_ref = f_ref()
res_fft = f_fft() res_fft = f_fft()
utt.assert_allclose(res_ref, res_fft, rtol=1e-04, atol=1e-04) utt.assert_allclose(res_ref, res_fft, rtol=1e-04, atol=1e-04)
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论