提交 c3b54b9b authored 作者: Arnaud Bergeron's avatar Arnaud Bergeron

Fix tests and code so that they can be happy forever after.

上级 05a63694
......@@ -31,6 +31,7 @@ from .bn import batch_normalization
import warnings
from .abstract_conv import conv2d as abstract_conv2d
def conv2d(input, filters, input_shape=None, filter_shape=None,
border_mode='valid', subsample=(1, 1), filter_flip=True,
image_shape=None, **kwargs):
......@@ -139,5 +140,3 @@ def conv2d(input, filters, input_shape=None, filter_shape=None,
return abstract_conv2d(input, filters, input_shape, filter_shape,
border_mode, subsample, filter_flip)
......@@ -424,7 +424,7 @@ class CorrMM_gradWeights(BaseCorrMM):
if shape is None:
raise ValueError('shape must be given if subsample != (1, 1)'
' or border_mode == "half"')
height_width = [shape[0], shape[1]]
height_width = [as_tensor_variable(shape[0]), as_tensor_variable(shape[1])]
else:
height_width = []
......@@ -519,7 +519,7 @@ class CorrMM_gradInputs(BaseCorrMM):
raise TypeError('topgrad must be 4D tensor')
if self.subsample != (1, 1) and shape is None:
raise ValueError('shape must be given if subsample != (1, 1)')
height_width = [shape[0], shape[1]] if self.subsample != (1, 1) else []
height_width = [as_tensor_variable(shape[0]), as_tensor_variable(shape[1])] if self.subsample != (1, 1) else []
broadcastable = [topgrad.type.broadcastable[0], kern.type.broadcastable[1],
False, False]
......
......@@ -162,7 +162,7 @@ PyArrayObject* corrMM(PyArrayObject* bottom,
"CorrMM shape inconsistency:\n"
" bottom shape: %%d %%d %%d %%d\n"
" weight shape: %%d %%d %%d %%d\n"
" top shape: %%d %%d %%d %%d (expected %%d %%d %%d %%d)\n",
" top shape: %%ld %%ld %%ld %%ld (expected %%d %%d %%d %%d)\n",
batchSize, nChannels, bottomHeight, bottomWidth,
nFilters, nChannels, kH, kW,
PyArray_DIMS(top)[0], PyArray_DIMS(top)[1],
......@@ -182,7 +182,7 @@ PyArrayObject* corrMM(PyArrayObject* bottom,
if (NULL == col)
{
PyErr_Format(PyExc_RuntimeError,
"CorrMM failed to allocate working memory of %%d x %%d\n",
"CorrMM failed to allocate working memory of %%ld x %%ld\n",
col_dim[0], col_dim[1]);
return NULL;
}
......
......@@ -4,12 +4,12 @@ import itertools
import theano
from theano import tensor
from theano.tests import unittests_tools as utt
from theano.tensor.nnet.abstract_conv import conv, get_conv_output_shape
from theano.tensor.nnet import corr
from theano.tests import unittest_tools as utt
from theano.tensor.nnet import corr, abstract_conv as conv
from theano.tensor.nnet.abstract_conv import get_conv_output_shape
from theano.tensor.nnet.conv import ConvOp
from theano.tensor.nnet.corr import (CorrMM, CorrMM_gradWeights,
CorrMM_gradInputs)
from theano.tensor.nnet.conv import ConvOp
from theano.tensor.nnet.ConvGrad3D import ConvGrad3D
from theano.tensor.nnet.ConvTransp3D import ConvTransp3D
......@@ -21,18 +21,21 @@ def conv_corr(inputs, filters, border_mode="valid", subsample=(1, 1),
return corr.CorrMM(border_mode, subsample)(inputs, filters)
def conv_corr_gw(inputs, filters, border_mode="valid", subsample=(1, 1),
conv_mode='conv'):
def conv_corr_gw(inputs, topgrad, filters_shape, border_mode="valid",
subsample=(1, 1), conv_mode='conv'):
rval = corr.CorrMM_gradWeights(border_mode, subsample)(inputs, topgrad,
filters_shape[2:])
if conv_mode == 'conv':
filters = filters[:, :, ::-1, ::-1]
return corr.CorrMM(border_mode, subsample)(inputs, filters)
rval = rval[:, :, ::-1, ::-1]
return rval
def conv_corr_gi(inputs, filters, border_mode="valid", subsample=(1, 1),
conv_mode='conv'):
def conv_corr_gi(filters, topgrad, inputs_shape, border_mode="valid",
subsample=(1, 1), conv_mode='conv'):
if conv_mode == 'conv':
filters = filters[:, :, ::-1, ::-1]
return corr.CorrMM(border_mode, subsample)(inputs, filters)
return corr.CorrMM_gradInputs(border_mode, subsample)(filters, topgrad,
inputs_shape[2:])
class TestGetConvOutShape(unittest.TestCase):
......@@ -279,7 +282,7 @@ class TestCpuConv2d(TestConv2d):
gradweight_OK = False
gradinput_OK = False
if b not in ('valid', 'full'):
if b not in ((0, 0), 'valid', 'full'):
fwd_OK = False
gradweight_OK = False
gradinput_OK = False
......@@ -294,7 +297,7 @@ class TestCpuConv2d(TestConv2d):
if fwd_OK:
self.run_fwd(inputs_shape=i, filters_shape=f, subsample=s,
verify_grad=True, mode=mode, device='cpu',
verify_grad=True, mode=mode,
provide_shape=provide_shape, border_mode=b,
filter_flip=flip, target_op=ConvOp)
else:
......@@ -312,7 +315,7 @@ class TestCpuConv2d(TestConv2d):
if gradweight_OK:
self.run_gradweight(inputs_shape=i, filters_shape=f,
output_shape=o, subsample=s,
verify_grad=False, mode=mode, device='cpu',
verify_grad=False, mode=mode,
provide_shape=provide_shape, border_mode=b,
filter_flip=flip,
target_op=(ConvOp, ConvGrad3D))
......@@ -332,7 +335,7 @@ class TestCpuConv2d(TestConv2d):
if gradinput_OK:
self.run_gradinput(inputs_shape=i, filters_shape=f,
output_shape=o, subsample=s,
verify_grad=False, mode=mode, device='cpu',
verify_grad=False, mode=mode,
provide_shape=provide_shape, border_mode=b,
filter_flip=flip,
target_op=(ConvOp, ConvTransp3D))
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论