提交 c81f8c36 authored 作者: Samira Shabanian's avatar Samira Shabanian

pep8 typed list directory

上级 33c97605
...@@ -3,8 +3,6 @@ Contains a wrapper function for tensor.nnet.ConvOp, which can be used to perform ...@@ -3,8 +3,6 @@ Contains a wrapper function for tensor.nnet.ConvOp, which can be used to perform
generic 2D convolution. generic 2D convolution.
""" """
__docformat__ = "restructuredtext en"
import warnings import warnings
import theano import theano
...@@ -12,6 +10,10 @@ import theano.tensor as tensor ...@@ -12,6 +10,10 @@ import theano.tensor as tensor
from theano.tensor.nnet import conv from theano.tensor.nnet import conv
import logging import logging
__docformat__ = "restructuredtext en"
_logger = logging.getLogger("theano.tensor.signal.conv") _logger = logging.getLogger("theano.tensor.signal.conv")
...@@ -52,7 +54,7 @@ def conv2d(input, filters, image_shape=None, filter_shape=None, ...@@ -52,7 +54,7 @@ def conv2d(input, filters, image_shape=None, filter_shape=None,
assert input.ndim in (2, 3) assert input.ndim in (2, 3)
assert filters.ndim in (2, 3) assert filters.ndim in (2, 3)
### use shape information if it is given to us ### # use shape information if it is given to us ###
if filter_shape and image_shape: if filter_shape and image_shape:
if input.ndim == 3: if input.ndim == 3:
bsize = image_shape[0] bsize = image_shape[0]
...@@ -69,7 +71,7 @@ def conv2d(input, filters, image_shape=None, filter_shape=None, ...@@ -69,7 +71,7 @@ def conv2d(input, filters, image_shape=None, filter_shape=None,
nkern, kshp = None, None nkern, kshp = None, None
bsize, imshp = None, None bsize, imshp = None, None
### reshape tensors to 4D, for compatibility with ConvOp ### # reshape tensors to 4D, for compatibility with ConvOp ###
if input.ndim == 3: if input.ndim == 3:
sym_bsize = input.shape[0] sym_bsize = input.shape[0]
else: else:
...@@ -86,10 +88,10 @@ def conv2d(input, filters, image_shape=None, filter_shape=None, ...@@ -86,10 +88,10 @@ def conv2d(input, filters, image_shape=None, filter_shape=None,
new_filter_shape = tensor.join(0, tensor.stack([sym_nkern, 1]), filters.shape[-2:]) new_filter_shape = tensor.join(0, tensor.stack([sym_nkern, 1]), filters.shape[-2:])
filters4D = tensor.reshape(filters, new_filter_shape, ndim=4) filters4D = tensor.reshape(filters, new_filter_shape, ndim=4)
### perform actual convolution ### # perform actual convolution ###
op = conv.ConvOp(output_mode=border_mode, op = conv.ConvOp(output_mode=border_mode,
dx=subsample[0], dy=subsample[1], dx=subsample[0], dy=subsample[1],
imshp=imshp, kshp=kshp, nkern=nkern, bsize=bsize, **kargs) imshp=imshp, kshp=kshp, nkern=nkern, bsize=bsize, **kargs)
output = op(input4D, filters4D) output = op(input4D, filters4D)
......
...@@ -31,7 +31,7 @@ class TestSignalConv2D(unittest.TestCase): ...@@ -31,7 +31,7 @@ class TestSignalConv2D(unittest.TestCase):
if filter_dim != 3: if filter_dim != 3:
nkern = 1 nkern = 1
############# THEANO IMPLEMENTATION ############ # THEANO IMPLEMENTATION ############
# we create a symbolic function so that verify_grad can work # we create a symbolic function so that verify_grad can work
def sym_conv2d(input, filters): def sym_conv2d(input, filters):
return conv.conv2d(input, filters) return conv.conv2d(input, filters)
...@@ -44,9 +44,8 @@ class TestSignalConv2D(unittest.TestCase): ...@@ -44,9 +44,8 @@ class TestSignalConv2D(unittest.TestCase):
filter_data = numpy.random.random(filter_shape) filter_data = numpy.random.random(filter_shape)
theano_output = theano_conv(image_data, filter_data) theano_output = theano_conv(image_data, filter_data)
############# REFERENCE IMPLEMENTATION ############ # REFERENCE IMPLEMENTATION ############
out_shape2d = numpy.array(image_shape[-2:]) -\ out_shape2d = numpy.array(image_shape[-2:]) - numpy.array(filter_shape[-2:]) + 1
numpy.array(filter_shape[-2:]) + 1
ref_output = numpy.zeros(tuple(out_shape2d)) ref_output = numpy.zeros(tuple(out_shape2d))
# reshape as 3D input tensors to make life easier # reshape as 3D input tensors to make life easier
...@@ -76,7 +75,7 @@ class TestSignalConv2D(unittest.TestCase): ...@@ -76,7 +75,7 @@ class TestSignalConv2D(unittest.TestCase):
self.assertTrue(_allclose(theano_output4d[b, k, :, :], self.assertTrue(_allclose(theano_output4d[b, k, :, :],
output2d)) output2d))
############# TEST GRADIENT ############ # TEST GRADIENT ############
if verify_grad: if verify_grad:
utt.verify_grad(sym_conv2d, [image_data, filter_data]) utt.verify_grad(sym_conv2d, [image_data, filter_data])
...@@ -87,8 +86,8 @@ class TestSignalConv2D(unittest.TestCase): ...@@ -87,8 +86,8 @@ class TestSignalConv2D(unittest.TestCase):
signal.conv.conv2d can support inputs and filters of type signal.conv.conv2d can support inputs and filters of type
matrix or tensor3. matrix or tensor3.
""" """
if (not theano.tensor.nnet.conv.imported_scipy_signal and if(not theano.tensor.nnet.conv.imported_scipy_signal and
theano.config.cxx == ""): theano.config.cxx == ""):
raise SkipTest("conv2d tests need SciPy or a c++ compiler") raise SkipTest("conv2d tests need SciPy or a c++ compiler")
self.validate((1, 4, 5), (2, 2, 3), out_dim=4, verify_grad=True) self.validate((1, 4, 5), (2, 2, 3), out_dim=4, verify_grad=True)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论