提交 53e556fc authored 作者: abergeron's avatar abergeron

Merge pull request #1891 from nouiz/signal_conv2d

Interface change: Make theano.tensor.signal.conv2d(2d,2d) output 2d answer.
......@@ -13,6 +13,9 @@ Done up to PR 1608
* https://github.com/Theano/Theano/pull/1591 # need info
Interface change:
- theano.tensor.signal.conv2d(2d,2d) output 2d answer. (Frederic B., reported by Alexander Izvorski)
Theano Development version
==========================
......
......@@ -400,6 +400,12 @@ AddConfigVar('warn.vm_gc_bug',
BoolParam(False),
in_c_key=False)
AddConfigVar('warn.signal_conv2d_interface',
("Warn we use the new signal.conv2d() when its interface"
" changed mid June 2014"),
BoolParam(warn_default('0.7')),
in_c_key=False)
AddConfigVar('compute_test_value',
("If 'True', Theano will run each op at graph build time, using "
"Constants, SharedVariables and the tag 'test_value' as inputs "
......
......@@ -2,11 +2,15 @@ import numpy
import theano
# Skip test if cuda_ndarray is not available.
from nose.plugins.skip import SkipTest
import theano.sandbox.cuda as cuda_ndarray
if cuda_ndarray.cuda_available == False:
raise SkipTest('Optional package cuda disabled')
try:
from nose.plugins.skip import SkipTest
import theano.sandbox.cuda as cuda_ndarray
if cuda_ndarray.cuda_available == False:
raise SkipTest('Optional package cuda disabled')
except ImportError:
# To have the GPU back-end work without nose, we need this file to
# be importable without nose.
pass
from theano.gof.python25 import any
import theano.sandbox.cuda as cuda
import theano.sandbox.cuda.basic_ops as B
......
......@@ -5,6 +5,9 @@ generic 2D convolution.
__docformat__ = "restructuredtext en"
import warnings
import theano
import theano.tensor as tensor
from theano.tensor.nnet import conv
......@@ -82,7 +85,16 @@ def conv2d(input, filters, image_shape=None, filter_shape=None,
output = op(input4D, filters4D)
# flatten to 3D tensor if convolving with single filter or single image
if input.ndim==2 or filters.ndim==2:
if input.ndim == 2 and filters.ndim == 2:
if theano.config.warn.signal_conv2d_interface:
warnings.warn(
"theano.tensor.signal.conv2d() now output 2d tensor when both"
" inputs are 2d. To disable this warning, set the Theano flag"
" warn.signal_conv2d_interface to False",
stacklevel=3)
output = tensor.flatten(output.T, outdim=2).T
elif input.ndim == 2 or filters.ndim == 2:
output = tensor.flatten(output.T, outdim=3).T
return output
......@@ -17,7 +17,7 @@ class TestSignalConv2D(unittest.TestCase):
def setUp(self):
utt.seed_rng()
def validate(self, image_shape, filter_shape, verify_grad=True):
def validate(self, image_shape, filter_shape, out_dim, verify_grad=True):
image_dim = len(image_shape)
filter_dim = len(filter_shape)
......@@ -36,6 +36,7 @@ class TestSignalConv2D(unittest.TestCase):
def sym_conv2d(input, filters):
return conv.conv2d(input, filters)
output = sym_conv2d(input, filters)
assert output.ndim == out_dim
theano_conv = theano.function([input, filters], output)
# initialize input and compute result
......@@ -90,10 +91,10 @@ class TestSignalConv2D(unittest.TestCase):
theano.config.cxx == ""):
raise SkipTest("conv2d tests need SciPy or a c++ compiler")
self.validate((1, 4, 5), (2, 2, 3), verify_grad=True)
self.validate((7, 5), (5, 2, 3), verify_grad=False)
self.validate((3, 7, 5), (2, 3), verify_grad=False)
self.validate((7, 5), (2, 3), verify_grad=False)
self.validate((1, 4, 5), (2, 2, 3), out_dim=4, verify_grad=True)
self.validate((7, 5), (5, 2, 3), out_dim=3, verify_grad=False)
self.validate((3, 7, 5), (2, 3), out_dim=3, verify_grad=False)
self.validate((7, 5), (2, 3), out_dim=2, verify_grad=False)
def test_fail(self):
"""
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论