本文整理汇总了Python中tensorflow.python.ops.math_ops.less_equal方法的典型用法代码示例。如果您正苦于以下问题:Python math_ops.less_equal方法的具体用法?Python math_ops.less_equal怎么用?Python math_ops.less_equal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.python.ops.math_ops
的用法示例。
在下文中一共展示了math_ops.less_equal方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from tensorflow.python.ops import math_ops [as 别名]
# 或者: from tensorflow.python.ops.math_ops import less_equal [as 别名]
def __init__(self, label_name, weight_column_name):
def loss_fn(logits, target):
check_shape_op = control_flow_ops.Assert(
math_ops.less_equal(array_ops.rank(target), 2),
["target's shape should be either [batch_size, 1] or [batch_size]"])
with ops.control_dependencies([check_shape_op]):
target = array_ops.reshape(
target, shape=[array_ops.shape(target)[0], 1])
return loss_ops.hinge_loss(logits, target)
super(_BinarySvmTargetColumn, self).__init__(
loss_fn=loss_fn,
n_classes=2,
label_name=label_name,
weight_column_name=weight_column_name)
示例2: __init__
# 需要导入模块: from tensorflow.python.ops import math_ops [as 别名]
# 或者: from tensorflow.python.ops.math_ops import less_equal [as 别名]
def __init__(self, label_name, weight_column_name, enable_centered_bias,
head_name, thresholds):
def loss_fn(logits, labels):
check_shape_op = control_flow_ops.Assert(
math_ops.less_equal(array_ops.rank(labels), 2),
["labels shape should be either [batch_size, 1] or [batch_size]"])
with ops.control_dependencies([check_shape_op]):
labels = array_ops.reshape(
labels, shape=[array_ops.shape(labels)[0], 1])
return losses.hinge_loss(logits, labels)
super(_BinarySvmHead, self).__init__(
train_loss_fn=loss_fn,
eval_loss_fn=loss_fn,
n_classes=2,
label_name=label_name,
weight_column_name=weight_column_name,
enable_centered_bias=enable_centered_bias,
head_name=head_name,
thresholds=thresholds)
示例3: _MinimumGrad
# 需要导入模块: from tensorflow.python.ops import math_ops [as 别名]
# 或者: from tensorflow.python.ops.math_ops import less_equal [as 别名]
def _MinimumGrad(op, grad):
"""Returns grad*(x < y, x >= y) with type of grad."""
return _MaximumMinimumGrad(op, grad, math_ops.less_equal)
示例4: less_equal
# 需要导入模块: from tensorflow.python.ops import math_ops [as 别名]
# 或者: from tensorflow.python.ops.math_ops import less_equal [as 别名]
def less_equal(x, y):
"""Element-wise truth value of (x <= y).
Arguments:
x: Tensor or variable.
y: Tensor or variable.
Returns:
A bool tensor.
"""
return math_ops.less_equal(x, y)
示例5: _assert_labels_rank
# 需要导入模块: from tensorflow.python.ops import math_ops [as 别名]
# 或者: from tensorflow.python.ops.math_ops import less_equal [as 别名]
def _assert_labels_rank(labels):
return control_flow_ops.Assert(
math_ops.less_equal(array_ops.rank(labels), 2),
("labels shape should be either [batch_size, 1] or [batch_size]",))
示例6: __le__
# 需要导入模块: from tensorflow.python.ops import math_ops [as 别名]
# 或者: from tensorflow.python.ops.math_ops import less_equal [as 别名]
def __le__(self, other):
return less_equal(self, other)
示例7: setUp
# 需要导入模块: from tensorflow.python.ops import math_ops [as 别名]
# 或者: from tensorflow.python.ops.math_ops import less_equal [as 别名]
def setUp(self):
super(CoreBinaryOpsTest, self).setUp()
self.x_probs_broadcast_tensor = array_ops.reshape(
self.x_probs_lt.tensor, [self.x_size, 1, self.probs_size])
self.channel_probs_broadcast_tensor = array_ops.reshape(
self.channel_probs_lt.tensor, [1, self.channel_size, self.probs_size])
# == and != are not element-wise for tf.Tensor, so they shouldn't be
# elementwise for LabeledTensor, either.
self.ops = [
('add', operator.add, math_ops.add, core.add),
('sub', operator.sub, math_ops.subtract, core.sub),
('mul', operator.mul, math_ops.multiply, core.mul),
('div', operator.truediv, math_ops.div, core.div),
('mod', operator.mod, math_ops.mod, core.mod),
('pow', operator.pow, math_ops.pow, core.pow_function),
('equal', None, math_ops.equal, core.equal),
('less', operator.lt, math_ops.less, core.less),
('less_equal', operator.le, math_ops.less_equal, core.less_equal),
('not_equal', None, math_ops.not_equal, core.not_equal),
('greater', operator.gt, math_ops.greater, core.greater),
('greater_equal', operator.ge, math_ops.greater_equal,
core.greater_equal),
]
self.test_lt_1 = self.x_probs_lt
self.test_lt_2 = self.channel_probs_lt
self.test_lt_1_broadcast = self.x_probs_broadcast_tensor
self.test_lt_2_broadcast = self.channel_probs_broadcast_tensor
self.broadcast_axes = [self.a0, self.a1, self.a3]
示例8: test_forward_rel_ops
# 需要导入模块: from tensorflow.python.ops import math_ops [as 别名]
# 或者: from tensorflow.python.ops.math_ops import less_equal [as 别名]
def test_forward_rel_ops():
t1 = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
t2 = np.array([[9, 8, 7], [6, 5, 4], [3, 2, 1]])
_test_forward_rel_op([t1, t2], math_ops.less)
_test_forward_rel_op([t1, t2], math_ops.greater)
_test_forward_rel_op([t1, t2], math_ops.less_equal)
_test_forward_rel_op([t1, t2], math_ops.greater_equal)
_test_forward_rel_op([t1, t2], math_ops.equal)
_test_forward_rel_op([t1, t2], math_ops.not_equal)
#######################################################################
# Main
# ----
示例9: _reshape_labels
# 需要导入模块: from tensorflow.python.ops import math_ops [as 别名]
# 或者: from tensorflow.python.ops.math_ops import less_equal [as 别名]
def _reshape_labels(labels):
""""Reshapes labels into [batch_size, 1] to be compatible with logits."""
check_shape_op = control_flow_ops.Assert(
math_ops.less_equal(array_ops.rank(labels), 2),
["labels shape should be either [batch_size, 1] or [batch_size]"])
with ops.control_dependencies([check_shape_op]):
labels = array_ops.reshape(labels,
shape=[array_ops.shape(labels)[0], 1])
return labels
示例10: __init__
# 需要导入模块: from tensorflow.python.ops import math_ops [as 别名]
# 或者: from tensorflow.python.ops.math_ops import less_equal [as 别名]
def __init__(self, label_name, weight_column_name):
def loss_fn(logits, target):
check_shape_op = control_flow_ops.Assert(
math_ops.less_equal(array_ops.rank(target), 2),
["target's shape should be either [batch_size, 1] or [batch_size]"])
with ops.control_dependencies([check_shape_op]):
target = array_ops.reshape(
target, shape=[array_ops.shape(target)[0], 1])
return losses.hinge_loss(logits, target)
super(_BinarySvmTargetColumn, self).__init__(
loss_fn=loss_fn,
n_classes=2,
label_name=label_name,
weight_column_name=weight_column_name)
示例11: is_mask_update_iter
# 需要导入模块: from tensorflow.python.ops import math_ops [as 别名]
# 或者: from tensorflow.python.ops.math_ops import less_equal [as 别名]
def is_mask_update_iter(self, global_step, last_update_step):
"""Function for checking if the current step is a mask update step.
It also creates the drop_fraction op and assigns it to the self object.
Args:
global_step: tf.Variable(int), current training step.
last_update_step: tf.Variable(int), holding the last iteration the mask
is updated. Used to determine whether current iteration is a mask
update step.
Returns:
bool, whether the current iteration is a mask_update step.
"""
gs_dtype = global_step.dtype
self._begin_step = math_ops.cast(self._begin_step, gs_dtype)
self._end_step = math_ops.cast(self._end_step, gs_dtype)
self._frequency = math_ops.cast(self._frequency, gs_dtype)
is_step_within_update_range = math_ops.logical_and(
math_ops.greater_equal(global_step, self._begin_step),
math_ops.logical_or(
math_ops.less_equal(global_step, self._end_step),
# If _end_step is negative, we never stop updating the mask.
# In other words we update the mask with given frequency until the
# training ends.
math_ops.less(self._end_step, 0)))
is_update_step = math_ops.less_equal(
math_ops.add(last_update_step, self._frequency), global_step)
is_mask_update_iter_op = math_ops.logical_and(
is_step_within_update_range, is_update_step)
self.drop_fraction = self.get_drop_fraction(global_step,
is_mask_update_iter_op)
return is_mask_update_iter_op
示例12: set_up_train
# 需要导入模块: from tensorflow.python.ops import math_ops [as 别名]
# 或者: from tensorflow.python.ops.math_ops import less_equal [as 别名]
def set_up_train(self, pretrain=False):
self.logger.info("Model setting up train starts")
decay_func = DECAY_DICT[self.args.dtype]
if hasattr(self, 'start_epoch'):
self.logger.info("Current start epoch : {}".format(self.start_epoch))
DECAY_PARAMS_DICT[self.args.hdtype][self.args.nbatch][self.args.hdptype]['initial_step'] = self.nbatch_train*self.start_epoch
self.lr, update_step_op = decay_func(**DECAY_PARAMS_DICT[self.args.dtype][self.args.nbatch][self.args.dptype])
print(vars_info_vl(tf.trainable_variables()))
update_ops = tf.get_collection("update_ops")
with tf.control_dependencies(update_ops+[update_step_op]):
self.train_op = get_multi_train_op(tf.train.AdamOptimizer, self.loss, [self.lr], [tf.trainable_variables()])
self.graph_ops_dict = {'train' : [self.train_op, self.loss], 'val' : self.loss, 'test' : self.loss}
self.val_embed_tensor1 = tf.placeholder(tf.float32, shape=[self.args.nbatch, self.args.m])
self.val_embed_tensor2 = tf.placeholder(tf.float32, shape=[self.nval, self.args.m])
self.p_dist = math_ops.add(
math_ops.reduce_sum(math_ops.square(self.val_embed_tensor1), axis=[1], keep_dims=True),
math_ops.reduce_sum(math_ops.square(array_ops.transpose(self.val_embed_tensor2)), axis=[0], keep_dims=True))-\
2.0 * math_ops.matmul(self.val_embed_tensor1, array_ops.transpose(self.val_embed_tensor2)) # [batch_size, 1], [1, ndata], [batch_size, ndata]
self.p_dist = math_ops.maximum(self.p_dist, 0.0) # [batch_size, ndata]
self.p_dist = math_ops.multiply(self.p_dist, math_ops.to_float(math_ops.logical_not(math_ops.less_equal(self.p_dist, 0.0))))
self.p_max_idx = tf.nn.top_k(-self.p_dist, k=2)[1] # [batch_size, 2] # get smallest 2
self.logger.info("Model setting up train ends")
示例13: set_up_train
# 需要导入模块: from tensorflow.python.ops import math_ops [as 别名]
# 或者: from tensorflow.python.ops.math_ops import less_equal [as 别名]
def set_up_train(self):
self.logger.info("Model setting up train starts")
decay_func = DECAY_DICT[self.args.dtype]
if hasattr(self, 'start_epoch'):
self.logger.info("Current start epoch : {}".format(self.start_epoch))
DECAY_PARAMS_DICT[self.args.hdtype][self.args.nbatch][self.args.hdptype]['initial_step'] = self.nbatch_train*self.start_epoch
self.lr, update_step_op = decay_func(**DECAY_PARAMS_DICT[self.args.dtype][self.args.nbatch][self.args.dptype])
print(vars_info_vl(tf.trainable_variables()))
update_ops = tf.get_collection("update_ops")
with tf.control_dependencies(update_ops+[update_step_op]):
self.train_op = get_multi_train_op(tf.train.AdamOptimizer, self.loss, [self.lr], [tf.trainable_variables()])
self.graph_ops_dict = {'train' : [self.train_op, self.loss], 'val' : self.loss, 'test' : self.loss}
self.val_embed_tensor1 = tf.placeholder(tf.float32, shape=[self.args.nbatch, self.args.m])
self.val_embed_tensor2 = tf.placeholder(tf.float32, shape=[self.nval, self.args.m])
self.p_dist = math_ops.add(
math_ops.reduce_sum(math_ops.square(self.val_embed_tensor1), axis=[1], keep_dims=True),
math_ops.reduce_sum(math_ops.square(array_ops.transpose(self.val_embed_tensor2)), axis=[0], keep_dims=True))-\
2.0 * math_ops.matmul(self.val_embed_tensor1, array_ops.transpose(self.val_embed_tensor2)) # [batch_size, 1], [1, ndata], [batch_size, ndata]
self.p_dist = math_ops.maximum(self.p_dist, 0.0) # [batch_size, ndata]
self.p_dist = math_ops.multiply(self.p_dist, math_ops.to_float(math_ops.logical_not(math_ops.less_equal(self.p_dist, 0.0))))
self.p_max_idx = tf.nn.top_k(-self.p_dist, k=2)[1] # [batch_size, 2] # get smallest 2
self.logger.info("Model setting up train ends")
示例14: _test_less_equal
# 需要导入模块: from tensorflow.python.ops import math_ops [as 别名]
# 或者: from tensorflow.python.ops.math_ops import less_equal [as 别名]
def _test_less_equal(data):
""" One iteration of less_equal """
return _test_elemwise(math_ops.less_equal, data)
#######################################################################
# Equal
# -----
示例15: test_forward_rel_ops
# 需要导入模块: from tensorflow.python.ops import math_ops [as 别名]
# 或者: from tensorflow.python.ops.math_ops import less_equal [as 别名]
def test_forward_rel_ops():
t1 = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
t2 = np.array([[9, 8, 7], [6, 5, 4], [3, 2, 1]])
_test_forward_rel_op([t1, t2], math_ops.less)
_test_forward_rel_op([t1, t2], math_ops.greater)
_test_forward_rel_op([t1, t2], math_ops.less_equal)
_test_forward_rel_op([t1, t2], math_ops.greater_equal)
_test_forward_rel_op([t1, t2], math_ops.equal)
_test_forward_rel_op([t1, t2], math_ops.not_equal)
#######################################################################
# ExpandDims
# ----------