提交 7a78f453 authored 作者: abergeron's avatar abergeron

Merge pull request #2480 from nouiz/conv

Conv and meta_conv
...@@ -857,7 +857,9 @@ class LocalMetaOptimizer(LocalOptimizer): ...@@ -857,7 +857,9 @@ class LocalMetaOptimizer(LocalOptimizer):
elif hasattr(input.tag, 'test_value'): elif hasattr(input.tag, 'test_value'):
givens[input] = theano.shared( givens[input] = theano.shared(
input.type.filter(input.tag.test_value), input.type.filter(input.tag.test_value),
input.name, borrow=True) input.name,
broadcastable=input.broadcastable,
borrow=True)
else: else:
missing.add(input) missing.add(input)
if missing: if missing:
......
...@@ -1541,6 +1541,18 @@ class GpuConv(GpuOp): ...@@ -1541,6 +1541,18 @@ class GpuConv(GpuOp):
to enable them. to enable them.
""" """
self.border_mode = border_mode self.border_mode = border_mode
if version != -1:
raise Exception(
"""GpuConv with version!=-1 is disabled as we do not
test it anymore. It probably work, so you probably can
just comment this error and use it. But we want to
make sure you know about that. Also, this Op is pretty
slow and isn't used by default anymore. We strongly
suggest to use GpuCorrMM that is much faster and
implement all the functionality (at a cost of some
extra memory usage). If you can use cuDNN, that is
even better.
""")
self.subsample = subsample self.subsample = subsample
if logical_img_hw is not None: if logical_img_hw is not None:
h, w = logical_img_hw h, w = logical_img_hw
......
...@@ -1285,16 +1285,11 @@ def local_conv_gemm(node): ...@@ -1285,16 +1285,11 @@ def local_conv_gemm(node):
img, kern = node.inputs img, kern = node.inputs
border_mode = node.op.border_mode border_mode = node.op.border_mode
subsample = node.op.subsample subsample = node.op.subsample
pad = (0,0) if (border_mode == 'valid') or (subsample != (1,1)):
if (border_mode == 'full') and (subsample != (1,1)):
# need to simulate this via a padded valid convolution
pad = 'full'
border_mode = 'valid'
if (border_mode == 'valid'):
# need to flip the kernel for valid convolution # need to flip the kernel for valid convolution
kern = kern[:, :, ::-1, ::-1] kern = kern[:, :, ::-1, ::-1]
# By default use GpuCorrMM # By default use GpuCorrMM
rval = GpuCorrMM('valid', subsample, pad)( rval = GpuCorrMM(border_mode, subsample)(
gpu_contiguous(img), gpu_contiguous(kern)) gpu_contiguous(img), gpu_contiguous(kern))
# call GpuCorrMM_gradWeights if good # call GpuCorrMM_gradWeights if good
...@@ -1323,7 +1318,7 @@ def local_conv_gemm(node): ...@@ -1323,7 +1318,7 @@ def local_conv_gemm(node):
# because we are not allowed to replace a CudaNdarray with # because we are not allowed to replace a CudaNdarray with
# a DimShuffle instance in a graph optimization) # a DimShuffle instance in a graph optimization)
rval = theano.sandbox.cuda.as_cuda_ndarray_variable( rval = theano.sandbox.cuda.as_cuda_ndarray_variable(
GpuCorrMM_gradWeights('valid', subsample, pad)( GpuCorrMM_gradWeights(border_mode, subsample)(
gpu_contiguous(img.dimshuffle(1, 0, 2, 3)), gpu_contiguous(img.dimshuffle(1, 0, 2, 3)),
gpu_contiguous(kern.dimshuffle(1, 0, 2, 3)) gpu_contiguous(kern.dimshuffle(1, 0, 2, 3))
).dimshuffle(1, 0, 2, 3)) ).dimshuffle(1, 0, 2, 3))
...@@ -1331,7 +1326,7 @@ def local_conv_gemm(node): ...@@ -1331,7 +1326,7 @@ def local_conv_gemm(node):
# need to dimshuffle the kernel for full convolution # need to dimshuffle the kernel for full convolution
kern = kern.dimshuffle(1, 0, 2, 3) kern = kern.dimshuffle(1, 0, 2, 3)
# call GpuCorrMM_gradInputs # call GpuCorrMM_gradInputs
rval = GpuCorrMM_gradInputs('valid', subsample, pad)( rval = GpuCorrMM_gradInputs('valid', subsample)(
gpu_contiguous(kern), gpu_contiguous(img)) gpu_contiguous(kern), gpu_contiguous(img))
if node.outputs[0].broadcastable != rval.broadcastable: if node.outputs[0].broadcastable != rval.broadcastable:
# With given shape information, conv2d_fft may return a different # With given shape information, conv2d_fft may return a different
...@@ -1413,7 +1408,9 @@ class ConvMetaOptimizer(LocalCudaMetaOptimizer): ...@@ -1413,7 +1408,9 @@ class ConvMetaOptimizer(LocalCudaMetaOptimizer):
# allow_downcast=True), # allow_downcast=True),
numpy.require(numpy.random.randn(*shape), numpy.require(numpy.random.randn(*shape),
dtype=var.dtype), dtype=var.dtype),
var.name, borrow=True) var.name,
broadcastable=var.broadcastable,
borrow=True)
# return mapping # return mapping
return result return result
......
...@@ -556,8 +556,8 @@ def _test_subsample(cls, mode, version_valid=[-1], version_full=[-1]): ...@@ -556,8 +556,8 @@ def _test_subsample(cls, mode, version_valid=[-1], version_full=[-1]):
def test_subsample(): def test_subsample():
for t in _test_subsample(None, theano_mode, for t in _test_subsample(None, theano_mode,
version_valid=[-2, -1, 1, 3, 11, 12], version_valid=[-1],
version_full=[-2, -1]): version_full=[-1]):
yield t yield t
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论