本文整理汇总了Python中theano.Apply方法的典型用法代码示例。如果您正苦于以下问题:Python theano.Apply方法的具体用法?Python theano.Apply怎么用?Python theano.Apply使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类theano
的用法示例。
在下文中一共展示了theano.Apply方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_node
# 需要导入模块: import theano [as 别名]
# 或者: from theano import Apply [as 别名]
def make_node(self, acts, labels, input_lengths):
# Unless specified, assume all sequences have full sequence length, i.e. acts_.shape[0]
if input_lengths == None:
input_lengths = T.cast(acts.shape[0], dtype="int32") * T.ones_like(acts[0,:,0], dtype=np.int32)
# acts.shape = [seqLen, batchN, outputUnit]
if acts.dtype != "float32":
raise Exception("acts must be float32 instead of %s" % acts.dtype)
# labels.shape = [batchN, labelLen]
if labels.dtype != "int32":
raise Exception("labels must be int32 instead of %s" % labels.dtype)
# input_lengths.shape = [batchN]
if input_lengths.dtype != "int32":
raise Exception("input_lengths must be int32 instead of %s" % input_lengths.dtype)
applyNode = theano.Apply(self, inputs=[acts, input_lengths, labels], outputs=[self.costs, self.gradients])
# Return only the cost. Gradient will be returned by grad()
self.default_output = 0
return applyNode
示例2: make_node
# 需要导入模块: import theano [as 别名]
# 或者: from theano import Apply [as 别名]
def make_node(self, img, topgrad, shape=None):
img = as_tensor_variable(img)
topgrad = as_tensor_variable(topgrad)
if img.type.ndim != 4:
raise TypeError('img must be 4D tensor')
if topgrad.type.ndim != 4:
raise TypeError('topgrad must be 4D tensor')
if self.subsample != (1, 1) or self.border_mode == "half":
if shape is None:
raise ValueError('shape must be given if subsample != (1, 1)'
' or border_mode == "half"')
height_width = [as_tensor_variable(shape[0]).astype('int64'), as_tensor_variable(shape[1]).astype('int64')]
else:
height_width = []
broadcastable = [topgrad.type.broadcastable[1], img.type.broadcastable[1],
False, False]
dtype = img.type.dtype
return Apply(self, [img, topgrad] + height_width,
[TensorType(dtype, broadcastable)()])
示例3: make_node
# 需要导入模块: import theano [as 别名]
# 或者: from theano import Apply [as 别名]
def make_node(self, a, val, offset):
a = tensor.as_tensor_variable(a)
val = tensor.as_tensor_variable(val)
offset = tensor.as_tensor_variable(offset)
if a.ndim != 2:
raise TypeError('%s: first parameter must have exactly'
' two dimensions' % self.__class__.__name__)
elif val.ndim != 0:
raise TypeError('%s: second parameter must be a scalar'
% self.__class__.__name__)
elif offset.ndim != 0:
raise TypeError('%s: third parameter must be a scalar'
% self.__class__.__name__)
val = tensor.cast(val, dtype=scalar.upcast(a.dtype, val.dtype))
if val.dtype != a.dtype:
raise TypeError('%s: type of second parameter must be the same'
' as the first\'s' % self.__class__.__name__)
elif offset.dtype[:3] != 'int':
raise TypeError('%s: type of third parameter must be as integer'
' use theano.tensor.cast( input, \'int32/int64\')'
% self.__class__.__name__)
return gof.Apply(self, [a, val, offset], [a.type()])
示例4: c_init_code_struct
# 需要导入模块: import theano [as 别名]
# 或者: from theano import Apply [as 别名]
def c_init_code_struct(self, node, name, sub):
"""
Optional: return a code string specific to the apply
to be inserted in the struct initialization code.
Parameters
----------
node : an Apply instance in the graph being compiled
name : str
A unique name to distinguish variables from those of other nodes.
sub
A dictionary of values to substitute in the code.
Most notably it contains a 'fail' entry that you should place in
your code after setting a python exception to indicate an error.
Raises
------
MethodNotDefined
The subclass does not override this method.
"""
raise utils.MethodNotDefined("c_init_code_apply", type(self),
self.__class__.__name__)
示例5: c_support_code_struct
# 需要导入模块: import theano [as 别名]
# 或者: from theano import Apply [as 别名]
def c_support_code_struct(self, node, name):
"""
Optional: return utility code for use by an `Op` that will be
inserted at struct scope, that can be specialized for the
support of a particular `Apply` node.
Parameters
----------
node : an Apply instance in the graph being compiled
name : str
A unique name to distinguish you variables from those of other
nodes.
Raises
------
MethodNotDefined
Subclass does not implement this method.
"""
raise utils.MethodNotDefined("c_support_code_struct",
type(self), self.__class__.__name__)
示例6: c_cleanup_code_struct
# 需要导入模块: import theano [as 别名]
# 或者: from theano import Apply [as 别名]
def c_cleanup_code_struct(self, node, name):
"""
Optional: return a code string specific to the apply to be
inserted in the struct cleanup code.
Parameters
----------
node : an Apply instance in the graph being compiled
name : str
A unique name to distinguish variables from those of other nodes.
Raises
------
MethodNotDefined
The subclass does not override this method.
"""
raise utils.MethodNotDefined("c_cleanup_code_struct", type(self),
self.__class__.__name__)
示例7: make_node
# 需要导入模块: import theano [as 别名]
# 或者: from theano import Apply [as 别名]
def make_node(self, *inputs):
if not hasattr(self, 'itypes'):
raise NotImplementedError("You can either define itypes and otypes,\
or implement make_node")
if not hasattr(self, 'otypes'):
raise NotImplementedError("You can either define itypes and otypes,\
or implement make_node")
if len(inputs) != len(self.itypes):
raise ValueError("We expected %d inputs but got %d." %
(len(self.itypes), len(inputs)))
if not all(inp.type == it for inp, it in zip(inputs, self.itypes)):
raise TypeError(
"We expected inputs of types '%s' but got types '%s' " %
(str([inp.type for inp in inputs]), str(self.itypes)))
return theano.Apply(self, inputs, [o() for o in self.otypes])
示例8: make_node
# 需要导入模块: import theano [as 别名]
# 或者: from theano import Apply [as 别名]
def make_node(self, pvals, unis):
assert pvals.dtype == 'float32'
assert unis.dtype == 'float32'
if not isinstance(pvals.type, CudaNdarrayType):
raise TypeError('pvals must be cudandarray', pvals)
if not isinstance(unis.type, CudaNdarrayType):
raise TypeError('unis must be cudandarray', unis)
if self.odtype == 'auto':
odtype = pvals.dtype
else:
odtype = self.odtype
if odtype != pvals.dtype:
raise NotImplementedError(
'GpuMultinomialFromUniform works only if '
'self.odtype == pvals.dtype', odtype, pvals.dtype)
br = (pvals.broadcastable[1], pvals.broadcastable[0])
out = CudaNdarrayType(broadcastable=br)()
return Apply(self, [pvals, unis], [out])
示例9: make_node
# 需要导入模块: import theano [as 别名]
# 或者: from theano import Apply [as 别名]
def make_node(self, img, topgrad, shape=None):
img = as_cuda_ndarray_variable(img)
topgrad = as_cuda_ndarray_variable(topgrad)
if img.type.ndim != 4:
raise TypeError('img must be 4D tensor')
if topgrad.type.ndim != 4:
raise TypeError('topgrad must be 4D tensor')
if self.subsample != (1, 1) or self.border_mode == "half":
if shape is None:
raise ValueError('shape must be given if subsample != (1, 1)'
' or border_mode == "half"')
height_width = [shape[0], shape[1]]
assert shape[0].ndim == 0
assert shape[1].ndim == 0
else:
height_width = []
broadcastable = [topgrad.type.broadcastable[1], img.type.broadcastable[1],
False, False]
return Apply(self, [img, topgrad] + height_width, [CudaNdarrayType(broadcastable)()])
示例10: make_node
# 需要导入模块: import theano [as 别名]
# 或者: from theano import Apply [as 别名]
def make_node(self, img_shape, kern_shape):
if img_shape.type.ndim != 1 or img_shape.type.dtype != 'int64':
raise TypeError('img must be 1D shape tensor')
if kern_shape.type.ndim != 1 or kern_shape.type.dtype != 'int64':
raise TypeError('kern must be 1D shape tensor')
node = Apply(self, [img_shape, kern_shape],
[CDataType("cudnnConvolutionDescriptor_t",
freefunc="cudnnDestroyConvolutionDescriptor")()])
# DebugMode cannot compare the values of CDataType variables, so by
# default it returns False all the time. To prevent DebugMode from
# complaining because of the MergeOptimizer, we make this variable
# always compare to True.
out = node.outputs[0]
out.tag.values_eq_approx = tensor.type.values_eq_approx_always_true
return node
示例11: make_node
# 需要导入模块: import theano [as 别名]
# 或者: from theano import Apply [as 别名]
def make_node(self, *inputs):
inputs = tuple(map(T.as_tensor_variable, inputs))
output = T.tensor4(dtype=(self.output_dtype or inputs[0].dtype))
return Apply(self, inputs, (output,))
示例12: make_node
# 需要导入模块: import theano [as 别名]
# 或者: from theano import Apply [as 别名]
def make_node(self, input):
output = T.as_tensor_variable(input).type()
return theano.Apply(self, (input,), (output,))
示例13: make_node
# 需要导入模块: import theano [as 别名]
# 或者: from theano import Apply [as 别名]
def make_node(self, V, d, WShape, dCdH):
V_ = T.as_tensor_variable(V)
d_ = T.as_tensor_variable(d)
WShape_ = T.as_tensor_variable(WShape)
dCdH_ = T.as_tensor_variable(dCdH)
return theano.Apply(self,
inputs=[V_, d_, WShape_, dCdH_],
outputs=[T.TensorType(
V_.dtype,
(False, False, False, False, False))()])
示例14: make_node
# 需要导入模块: import theano [as 别名]
# 或者: from theano import Apply [as 别名]
def make_node(self, W, b, d, H, RShape=None):
"""
Parameters
----------
W
Weights, filter
b
Bias, shape == (W.shape[0],).
d
Strides when moving the filter over the input.
H
The output of Conv3D.
"""
W_ = T.as_tensor_variable(W)
b_ = T.as_tensor_variable(b)
d_ = T.as_tensor_variable(d)
H_ = T.as_tensor_variable(H)
if RShape:
RShape_ = T.as_tensor_variable(RShape)
else:
RShape_ = T.as_tensor_variable([-1, -1, -1])
return theano.Apply(self,
inputs=[W_, b_, d_, H_, RShape_],
outputs=[T.TensorType(H_.dtype,
(False, False, False, False, False))()])
示例15: make_node
# 需要导入模块: import theano [as 别名]
# 或者: from theano import Apply [as 别名]
def make_node(self, x):
if x.type.ndim != 4:
raise TypeError()
# TODO: consider restricting the dtype?
x = tensor.as_tensor_variable(x)
# If the input shape are broadcastable we can have 0 in the output shape
broad = x.broadcastable[:2] + (False, False)
out = tensor.TensorType(x.dtype, broad)
return gof.Apply(self, [x], [out()])