提交 8d8f527f authored 作者: vdumoulin's avatar vdumoulin

Merge pull request #3621 from shabanian/tensor_signal_pep8

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