提交 f000e752 authored 作者: abergeron's avatar abergeron

Merge pull request #3682 from nouiz/abs_conv

Better error message and docstring
......@@ -510,7 +510,7 @@ TensorVariable
.. method:: diagonal(offset=0, axis1=0, axis2=1)
.. method:: astype(dtype)
.. method:: take(indices, axis=None, mode='raise')
.. method:: copy()
.. method:: copy() Return a new symbolic variable that is a copy of the variable. Does not copy the tag.
.. method:: norm(L, axis=None)
.. method:: nonzero(self, return_matrix=False)
.. method:: nonzero_values(self)
......
......@@ -262,6 +262,7 @@ if __name__ == "__main__":
GTX Titan Black 0.64s 0.64s
GTX Titan(D15U-50)
GTX 780
GTX 980 Ti 0.41s
GTX 980
GTX 970
GTX 680 1.57s
......
......@@ -422,6 +422,7 @@ class GpuFromHost(Op):
}
} else {
Py_XDECREF(%(out)s);
// This method will release the GIL when needed.
%(out)s = pygpu_fromhostdata(PyArray_DATA(%(name)s_tmp),
get_typecode((PyObject *)PyArray_DESCR(%(name)s_tmp)),
PyArray_NDIM(%(name)s_tmp),
......
......@@ -103,10 +103,10 @@ def conv2d(input,
border_mode='valid',
subsample=(1, 1),
filter_flip=True):
"""
This function will build the symbolic graph for convolving a mini-batch of a
stack of 2D inputs with a set of 2D filters. The implementation is modelled
after Convolutional Neural Networks (CNN).
"""This function will build the symbolic graph for convolving a
mini-batch of a stack of 2D inputs with a set of 2D filters. The
implementation is modelled after Convolutional Neural Networks
(CNN).
:type input: symbolic 4D tensor
:param input: mini-batch of feature map stacks, of shape
......@@ -153,11 +153,20 @@ def conv2d(input,
:param filter_flip: If ``True``, will flip the filter rows and columns
before sliding them over the input. This operation is normally referred
to as a convolution, and this is the default. If ``False``, the filters
are not flipped and the operation is referred to as a cross-correlation.
are not flipped and the operation is referred to as a
cross-correlation.
:rtype: symbolic 4D tensor
:return: set of feature maps generated by convolutional layer. Tensor is
of shape (batch size, output channels, output rows, output columns)
:note: If CuDNN is available, it will be used on the
GPU. Otherwise, it is the *CorrMM* convolution that will be used
"caffe style convolution".
:note: This is only supported in Theano 0.8 or the development
version until it is released.
"""
conv_op = AbstractConv2d(imshp=input_shape,
......@@ -169,9 +178,10 @@ def conv2d(input,
class BaseAbstractConv2d(Op):
"""
Base class for AbstractConv
Define an abstract convolution op that will be replaced with the appropriate implementation
"""Base class for AbstractConv
Define an abstract convolution op that will be replaced with the
appropriate implementation
:type imshp: None, tuple/list of len 4 of int or Constant variable
:param imshp: The shape of the input parameter.
......@@ -211,7 +221,9 @@ class BaseAbstractConv2d(Op):
:param filter_flip: If ``True``, will flip the filter rows and columns
before sliding them over the input. This operation is normally referred
to as a convolution, and this is the default. If ``False``, the filters
are not flipped and the operation is referred to as a cross-correlation.
are not flipped and the operation is referred to as a
cross-correlation.
"""
check_broadcast = False
__props__ = ('border_mode', 'subsample', 'filter_flip', 'imshp', 'kshp')
......@@ -270,7 +282,8 @@ class AbstractConv2d(BaseAbstractConv2d):
subsample=(1, 1),
filter_flip=True):
super(AbstractConv2d, self).__init__(imshp, kshp,
border_mode, subsample, filter_flip)
border_mode, subsample,
filter_flip)
def make_node(self, img, kern):
if img.type.ndim != 4:
......@@ -319,7 +332,9 @@ class AbstractConv2d_gradWeights(BaseAbstractConv2d):
subsample=(1, 1),
filter_flip=True):
super(AbstractConv2d_gradWeights, self).__init__(imshp, kshp,
border_mode, subsample, filter_flip)
border_mode,
subsample,
filter_flip)
# Update shape/height_width
def make_node(self, img, topgrad, shape):
......@@ -336,7 +351,8 @@ class AbstractConv2d_gradWeights(BaseAbstractConv2d):
return Apply(self, [img, topgrad, shape], [output])
def perform(self, node, inp, out_):
raise NotImplementedError('AbstractConv2d_gradWeight theano optimization failed')
raise NotImplementedError(
'AbstractConv2d_gradWeight theano optimization failed')
def grad(self, inp, grads):
bottom, top = inp[:2]
......@@ -344,7 +360,10 @@ class AbstractConv2d_gradWeights(BaseAbstractConv2d):
d_bottom = AbstractConv2d_gradInputs(self.imshp, self.kshp,
self.border_mode,
self.subsample,
self.filter_flip)(weights, top, bottom.shape[-2:])
self.filter_flip)(
weights,
top,
bottom.shape[-2:])
d_top = AbstractConv2d(self.imshp,
self.kshp,
self.border_mode,
......@@ -373,7 +392,9 @@ class AbstractConv2d_gradInputs(BaseAbstractConv2d):
subsample=(1, 1),
filter_flip=True):
super(AbstractConv2d_gradInputs, self).__init__(imshp, kshp,
border_mode, subsample, filter_flip)
border_mode,
subsample,
filter_flip)
# Update shape/height_width
def make_node(self, kern, topgrad, shape):
......@@ -390,16 +411,20 @@ class AbstractConv2d_gradInputs(BaseAbstractConv2d):
return Apply(self, [kern, topgrad, shape], [output])
def perform(self, node, inp, out_):
raise NotImplementedError('AbstractConv2d_gradWeight theano optimization failed')
raise NotImplementedError(
'AbstractConv2d_gradWeight theano optimization failed')
def grad(self, inp, grads):
weights, top = inp[:2]
bottom, = grads
d_weights = AbstractConv2d_gradWeights(self.imshp, self.kshp,
self.border_mode,
self.subsample)(bottom, top, weights.shape[-2:])
self.subsample)(
bottom, top,
weights.shape[-2:])
d_top = AbstractConv2d(self.imshp, self.kshp,
self.border_mode, self.subsample)(bottom, weights)
self.border_mode, self.subsample)(
bottom, weights)
d_height_width = (theano.gradient.DisconnectedType()(),)
return (d_weights, d_top) + d_height_width
......
......@@ -881,8 +881,9 @@ class ConvOp(OpenMPOp):
if self.dx not in (1, 2) or self.dy not in (1, 2):
raise NotImplementedError(
"ERROR: We disable ConvOp.grad now when dx or "
"dy are different from 1 and 2, as there is a bug in it.")
"ERROR: We disable ConvOp.grad now when output_mode is not"
" 'valid' and dx or dy are greater than 2, as there is a bug"
" in it. See `abstract_conv2d <>`_ for a version that support this.")
all_shape = self.has_all_shape(self.imshp, self.kshp,
self.nkern, self.bsize)
......
......@@ -535,7 +535,10 @@ class _tensor_py_operators(object):
# COPYING
def copy(self, name=None):
"""Copy a variable and optionally assign a name."""
"""Return a symbolic copy and optionally assign a name.
Does not copy the tags.
"""
copied_variable = theano.tensor.basic.tensor_copy(self)
copied_variable.name = name
return copied_variable
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论