本文整理汇总了Python中theano.tensor.any方法的典型用法代码示例。如果您正苦于以下问题:Python tensor.any方法的具体用法?Python tensor.any怎么用?Python tensor.any使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类theano.tensor
的用法示例。
在下文中一共展示了tensor.any方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: in_top_k
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import any [as 别名]
def in_top_k(predictions, targets, k):
'''Returns whether the `targets` are in the top `k` `predictions`
# Arguments
predictions: A tensor of shape batch_size x classess and type float32.
targets: A tensor of shape batch_size and type int32 or int64.
k: An int, number of top elements to consider.
# Returns
A tensor of shape batch_size and type int. output_i is 1 if
targets_i is within top-k values of predictions_i
'''
predictions_top_k = T.argsort(predictions)[:, -k:]
result, _ = theano.map(lambda prediction, target: any(equal(prediction, target)), sequences=[predictions_top_k, targets])
return result
# CONVOLUTIONS
示例2: test_c
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import any [as 别名]
def test_c(self):
if not theano.config.cxx:
raise SkipTest("G++ not available, so we need to skip this test.")
for dtype in ["floatX", "complex64", "complex128", "int8", "uint8"]:
self.with_linker(gof.CLinker(), scalar.add, dtype=dtype)
self.with_linker(gof.CLinker(), scalar.mul, dtype=dtype)
for dtype in ["floatX", "int8", "uint8"]:
self.with_linker(gof.CLinker(), scalar.minimum, dtype=dtype)
self.with_linker(gof.CLinker(), scalar.maximum, dtype=dtype)
self.with_linker(gof.CLinker(), scalar.and_, dtype=dtype,
tensor_op=tensor.all)
self.with_linker(gof.CLinker(), scalar.or_, dtype=dtype,
tensor_op=tensor.any)
for dtype in ["int8", "uint8"]:
self.with_linker(gof.CLinker(), scalar.or_, dtype=dtype)
self.with_linker(gof.CLinker(), scalar.and_, dtype=dtype)
self.with_linker(gof.CLinker(), scalar.xor, dtype=dtype)
示例3: stop_gradient
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import any [as 别名]
def stop_gradient(variables):
"""Returns `variables` but with zero gradient w.r.t. every other variable.
# Arguments
variables: tensor or list of tensors to consider constant with respect
to any other variable.
# Returns
A single tensor or a list of tensors (depending on the passed argument)
that has constant gradient with respect to any other variable.
"""
if isinstance(variables, (list, tuple)):
return map(theano.gradient.disconnected_grad, variables)
else:
return theano.gradient.disconnected_grad(variables)
# CONTROL FLOW
示例4: any
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import any [as 别名]
def any(x, axis=None, keepdims=False):
'''Bitwise reduction (logical OR).
'''
return T.any(x, axis=axis, keepdims=keepdims)
示例5: get_output_mask
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import any [as 别名]
def get_output_mask(self, train=False):
X = self.get_input(train)
return T.any(T.ones_like(X) * (1. - T.eq(X, self.mask_value)), axis=-1)
示例6: test_perform
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import any [as 别名]
def test_perform(self):
for dtype in ["floatX", "complex64", "complex128", "int8", "uint8"]:
self.with_linker(gof.PerformLinker(), scalar.add, dtype=dtype)
self.with_linker(gof.PerformLinker(), scalar.mul, dtype=dtype)
self.with_linker(gof.PerformLinker(), scalar.maximum, dtype=dtype)
self.with_linker(gof.PerformLinker(), scalar.minimum, dtype=dtype)
self.with_linker(gof.PerformLinker(), scalar.and_, dtype=dtype,
tensor_op=tensor.all)
self.with_linker(gof.PerformLinker(), scalar.or_, dtype=dtype,
tensor_op=tensor.any)
for dtype in ["int8", "uint8"]:
self.with_linker(gof.PerformLinker(), scalar.or_, dtype=dtype)
self.with_linker(gof.PerformLinker(), scalar.and_, dtype=dtype)
self.with_linker(gof.PerformLinker(), scalar.xor, dtype=dtype)
示例7: test_perform_nan
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import any [as 别名]
def test_perform_nan(self):
for dtype in ["floatX", "complex64", "complex128"]:
self.with_linker(gof.PerformLinker(), scalar.add, dtype=dtype,
test_nan=True)
self.with_linker(gof.PerformLinker(), scalar.mul, dtype=dtype,
test_nan=True)
self.with_linker(gof.PerformLinker(), scalar.maximum, dtype=dtype,
test_nan=True)
self.with_linker(gof.PerformLinker(), scalar.minimum, dtype=dtype,
test_nan=True)
self.with_linker(gof.PerformLinker(), scalar.or_, dtype=dtype,
test_nan=True, tensor_op=tensor.any)
self.with_linker(gof.PerformLinker(), scalar.and_, dtype=dtype,
test_nan=True, tensor_op=tensor.all)
示例8: test_any_grad
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import any [as 别名]
def test_any_grad(self):
x = tensor.bmatrix('x')
x_all = x.any()
gx = theano.grad(x_all, x)
f = theano.function([x], gx)
x_random = self.rng.binomial(n=1, p=0.5, size=(5, 7)).astype('int8')
for x_val in (x_random,
numpy.zeros_like(x_random),
numpy.ones_like(x_random)):
gx_val = f(x_val)
assert gx_val.shape == x_val.shape
assert numpy.all(gx_val == 0)
示例9: any
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import any [as 别名]
def any(x, axis=None, keepdims=False):
"""Bitwise reduction (logical OR).
"""
y = T.any(x, axis=axis, keepdims=keepdims)
y = _set_keras_shape_for_reduction(x, y, axis, keepdims)
return y
示例10: any
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import any [as 别名]
def any(x, axis=None, keepdims=False):
"""Bitwise reduction (logical OR).
"""
return T.any(x, axis=axis, keepdims=keepdims)