提交 cd2272fe authored 作者: Frédéric Bastien's avatar Frédéric Bastien

Merge pull request #3145 from harlouci/props_tensor_nnet

Props tensor nnet
...@@ -45,14 +45,7 @@ class Conv3D(theano.Op): ...@@ -45,14 +45,7 @@ class Conv3D(theano.Op):
""" 3D `convolution` of multiple filters on a minibatch """ 3D `convolution` of multiple filters on a minibatch
:note: does not flip the kernel, moves kernel with a user specified stride :note: does not flip the kernel, moves kernel with a user specified stride
""" """
def __eq__(self, other): __props__ = ()
return type(self) == type(other)
def __hash__(self):
return hash(type(self))
def __str__(self):
return "Conv3D"
def c_code_cache_version(self): def c_code_cache_version(self):
return (3, blas_header_version()) return (3, blas_header_version())
......
...@@ -12,11 +12,7 @@ from theano.gradient import DisconnectedType ...@@ -12,11 +12,7 @@ from theano.gradient import DisconnectedType
class ConvGrad3D(theano.Op): class ConvGrad3D(theano.Op):
""" Gradient of Conv3D with respect to W """ """ Gradient of Conv3D with respect to W """
def __eq__(self, other): __props__ = ()
return type(self) == type(other)
def __hash__(self):
return hash(type(self))
def c_code_cache_version(self): def c_code_cache_version(self):
return (1,) return (1,)
......
...@@ -10,11 +10,7 @@ from theano.gradient import DisconnectedType ...@@ -10,11 +10,7 @@ from theano.gradient import DisconnectedType
class ConvTransp3D(theano.Op): class ConvTransp3D(theano.Op):
""" "Transpose" of Conv3D (Conv3D implements multiplication by an implicitly defined matrix W. This implements multiplication by its transpose) """ """ "Transpose" of Conv3D (Conv3D implements multiplication by an implicitly defined matrix W. This implements multiplication by its transpose) """
def __eq__(self, other): __props__ = ()
return type(self) == type(other)
def __hash__(self):
return hash(type(self))
def c_code_cache_version(self): def c_code_cache_version(self):
return (3,) return (3,)
......
...@@ -73,6 +73,8 @@ class DiagonalSubtensor(Op): ...@@ -73,6 +73,8 @@ class DiagonalSubtensor(Op):
see what's necessary at that point. see what's necessary at that point.
""" """
__props__ = ("inplace",)
def __str__(self): def __str__(self):
if self.inplace: if self.inplace:
return "%s{inplace}" % self.__class__.__name__ return "%s{inplace}" % self.__class__.__name__
...@@ -83,12 +85,6 @@ class DiagonalSubtensor(Op): ...@@ -83,12 +85,6 @@ class DiagonalSubtensor(Op):
if inplace: if inplace:
self.view_map = {0: [0]} self.view_map = {0: [0]}
def __eq__(self, other):
return type(self) == type(other) and self.inplace == other.inplace
def __hash__(self):
return hash((type(self), self.inplace))
def make_node(self, x, i0, i1): def make_node(self, x, i0, i1):
_i0 = tensor.as_tensor_variable(i0) _i0 = tensor.as_tensor_variable(i0)
_i1 = tensor.as_tensor_variable(i1) _i1 = tensor.as_tensor_variable(i1)
...@@ -117,6 +113,8 @@ class IncDiagonalSubtensor(Op): ...@@ -117,6 +113,8 @@ class IncDiagonalSubtensor(Op):
""" """
The gradient of DiagonalSubtensor The gradient of DiagonalSubtensor
""" """
__props__ = ("inplace",)
def __str__(self): def __str__(self):
if self.inplace: if self.inplace:
return "%s{inplace}" % self.__class__.__name__ return "%s{inplace}" % self.__class__.__name__
...@@ -127,12 +125,6 @@ class IncDiagonalSubtensor(Op): ...@@ -127,12 +125,6 @@ class IncDiagonalSubtensor(Op):
if inplace: if inplace:
self.destroy_map = {0: [0]} self.destroy_map = {0: [0]}
def __eq__(self, other):
return type(self) == type(other) and self.inplace == other.inplace
def __hash__(self):
return hash((type(self), self.inplace))
def make_node(self, x, i0, i1, amt): def make_node(self, x, i0, i1, amt):
_i0 = tensor.as_tensor_variable(i0) _i0 = tensor.as_tensor_variable(i0)
_i1 = tensor.as_tensor_variable(i1) _i1 = tensor.as_tensor_variable(i1)
......
...@@ -13,6 +13,9 @@ import numpy ...@@ -13,6 +13,9 @@ import numpy
class Images2Neibs(Op): class Images2Neibs(Op):
__props__ = ("mode",)
def __init__(self, mode='valid'): def __init__(self, mode='valid'):
""" """
:type mode: str :type mode: str
...@@ -33,12 +36,6 @@ class Images2Neibs(Op): ...@@ -33,12 +36,6 @@ class Images2Neibs(Op):
" implemented for the op Images2Neibs") " implemented for the op Images2Neibs")
self.mode = mode self.mode = mode
def __eq__(self, other):
return type(self) == type(other) and self.mode == other.mode
def __hash__(self):
return hash(type(self)) ^ hash(self.mode)
def __str__(self): def __str__(self):
return self.__class__.__name__ + "{%s}" % self.mode return self.__class__.__name__ + "{%s}" % self.mode
......
...@@ -44,21 +44,9 @@ class SoftmaxWithBias(gof.Op): ...@@ -44,21 +44,9 @@ class SoftmaxWithBias(gof.Op):
This L{Op}'s output is softmax(x+b). This L{Op}'s output is softmax(x+b).
softmax(x[i]) is the i'th distribution over len(x[i]) options. softmax(x[i]) is the i'th distribution over len(x[i]) options.
""" """
nin = 2 nin = 2
nout = 1 nout = 1
__props__ = ()
def __init__(self, **kwargs):
gof.Op.__init__(self, **kwargs)
def __eq__(self, other):
return type(self) == type(other)
def __hash__(self):
return tensor.hashtype(self)
def __str__(self):
return self.__class__.__name__
def make_node(self, x, b): def make_node(self, x, b):
x = tensor.as_tensor_variable(x) x = tensor.as_tensor_variable(x)
...@@ -284,7 +272,6 @@ class SoftmaxGrad(gof.Op): ...@@ -284,7 +272,6 @@ class SoftmaxGrad(gof.Op):
"""Gradient wrt x of the Softmax Op""" """Gradient wrt x of the Softmax Op"""
nin = 2 nin = 2
nout = 1 nout = 1
__props__ = () __props__ = ()
def make_node(self, dy, sm): def make_node(self, dy, sm):
...@@ -828,19 +815,11 @@ class CrossentropySoftmaxArgmax1HotWithBias(gof.Op): ...@@ -828,19 +815,11 @@ class CrossentropySoftmaxArgmax1HotWithBias(gof.Op):
""" """
nin = 3 nin = 3
nout = 3 nout = 3
__props__ = ()
def __init__(self, **kwargs): def __init__(self, **kwargs):
gof.Op.__init__(self, **kwargs) gof.Op.__init__(self, **kwargs)
def __eq__(self, other):
return type(self) == type(other)
def __hash__(self):
return tensor.hashtype(self)
def __str__(self):
return self.__class__.__name__
def make_node(self, x, b, y_idx): def make_node(self, x, b, y_idx):
x = tensor.as_tensor_variable(x) x = tensor.as_tensor_variable(x)
b = tensor.as_tensor_variable(b) b = tensor.as_tensor_variable(b)
...@@ -1058,18 +1037,9 @@ class CrossentropySoftmaxArgmax1HotWithBias(gof.Op): ...@@ -1058,18 +1037,9 @@ class CrossentropySoftmaxArgmax1HotWithBias(gof.Op):
class CrossentropySoftmax1HotWithBiasDx(gof.Op): class CrossentropySoftmax1HotWithBiasDx(gof.Op):
nin = 3 nin = 3
nout = 1 nout = 1
__props__ = ()
"""Gradient wrt x of the CrossentropySoftmaxArgmax1HotWithBias Op""" """Gradient wrt x of the CrossentropySoftmaxArgmax1HotWithBias Op"""
def __init__(self, **kwargs):
gof.Op.__init__(self, **kwargs)
def __eq__(self, other):
return type(self) == type(other)
def __hash__(self):
return tensor.hashtype(self)
def __str__(self):
return self.__class__.__name__
def make_node(self, dy, sm, y_idx, **kwargs): def make_node(self, dy, sm, y_idx, **kwargs):
dy = tensor.as_tensor_variable(dy) dy = tensor.as_tensor_variable(dy)
...@@ -1269,15 +1239,8 @@ def crossentropy_softmax_max_and_argmax_1hot(x, y_idx, **kwargs): ...@@ -1269,15 +1239,8 @@ def crossentropy_softmax_max_and_argmax_1hot(x, y_idx, **kwargs):
class CrossentropyCategorical1HotGrad(gof.Op): class CrossentropyCategorical1HotGrad(gof.Op):
def __eq__(self, other): __props__ = ()
return type(self) == type(other)
def __hash__(self):
return tensor.hashtype(self)
def __str__(self):
return self.__class__.__name__
def make_node(self, g_y, coding_dist, true_one_of_n): def make_node(self, g_y, coding_dist, true_one_of_n):
return Apply(self, [g_y, coding_dist, true_one_of_n], return Apply(self, [g_y, coding_dist, true_one_of_n],
...@@ -1313,15 +1276,7 @@ class CrossentropyCategorical1Hot(gof.Op): ...@@ -1313,15 +1276,7 @@ class CrossentropyCategorical1Hot(gof.Op):
away in favour of one with a C implementation. away in favour of one with a C implementation.
""" """
__props__ = ()
def __eq__(self, other):
return type(self) == type(other)
def __hash__(self):
return tensor.hashtype(self)
def __str__(self):
return self.__class__.__name__
def make_node(self, coding_dist, true_one_of_n): def make_node(self, coding_dist, true_one_of_n):
""" """
...@@ -1950,17 +1905,14 @@ from theano import scalar ...@@ -1950,17 +1905,14 @@ from theano import scalar
class Prepend_scalar_constant_to_each_row(gof.Op): class Prepend_scalar_constant_to_each_row(gof.Op):
__props__ = ()
def __init__(self, val=0): def __init__(self, val=0):
if isinstance(val, float): if isinstance(val, float):
val = scalar.constant(val) val = scalar.constant(val)
self.val = val self.val = val
def __eq__(self, other):
return (type(self) == type(other)) and (self.val == other.val)
def __hash__(self):
return tensor.hashtype(self) ^ hash(self.val.data)
def __str__(self): def __str__(self):
return '%s{%s}' % (self.__class__.__name__, self.val) return '%s{%s}' % (self.__class__.__name__, self.val)
...@@ -2007,14 +1959,8 @@ class Prepend_scalar_constant_to_each_row(gof.Op): ...@@ -2007,14 +1959,8 @@ class Prepend_scalar_constant_to_each_row(gof.Op):
class Prepend_scalar_to_each_row(gof.Op): class Prepend_scalar_to_each_row(gof.Op):
def __eq__(self, other):
return (type(self) == type(other))
def __hash__(self):
return tensor.hashtype(self)
def __str__(self): __props__ = ()
return self.__class__.__name__
def make_node(self, val, mat): def make_node(self, val, mat):
# check type of input # check type of input
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论