本文整理汇总了Python中tensorflow.greater方法的典型用法代码示例。如果您正苦于以下问题:Python tensorflow.greater方法的具体用法?Python tensorflow.greater怎么用?Python tensorflow.greater使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow
的用法示例。
在下文中一共展示了tensorflow.greater方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build_cross_entropy_loss
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import greater [as 别名]
def build_cross_entropy_loss(logits, gold):
"""Constructs a cross entropy from logits and one-hot encoded gold labels.
Supports skipping rows where the gold label is the magic -1 value.
Args:
logits: float Tensor of scores.
gold: int Tensor of one-hot labels.
Returns:
cost, correct, total: the total cost, the total number of correctly
predicted labels, and the total number of valid labels.
"""
valid = tf.reshape(tf.where(tf.greater(gold, -1)), [-1])
gold = tf.gather(gold, valid)
logits = tf.gather(logits, valid)
correct = tf.reduce_sum(tf.to_int32(tf.nn.in_top_k(logits, gold, 1)))
total = tf.size(gold)
cost = tf.reduce_sum(
tf.contrib.nn.deprecated_flipped_sparse_softmax_cross_entropy_with_logits(
logits, tf.cast(gold, tf.int64))) / tf.cast(total, tf.float32)
return cost, correct, total
示例2: retain_groundtruth_with_positive_classes
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import greater [as 别名]
def retain_groundtruth_with_positive_classes(tensor_dict):
"""Retains only groundtruth with positive class ids.
Args:
tensor_dict: a dictionary of following groundtruth tensors -
fields.InputDataFields.groundtruth_boxes
fields.InputDataFields.groundtruth_classes
fields.InputDataFields.groundtruth_is_crowd
fields.InputDataFields.groundtruth_area
fields.InputDataFields.groundtruth_label_types
fields.InputDataFields.groundtruth_difficult
Returns:
a dictionary of tensors containing only the groundtruth with positive
classes.
Raises:
ValueError: If groundtruth_classes tensor is not in tensor_dict.
"""
if fields.InputDataFields.groundtruth_classes not in tensor_dict:
raise ValueError('`groundtruth classes` not in tensor_dict.')
keep_indices = tf.where(tf.greater(
tensor_dict[fields.InputDataFields.groundtruth_classes], 0))
return retain_groundtruth(tensor_dict, keep_indices)
示例3: pad_tensor
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import greater [as 别名]
def pad_tensor(t, length):
"""Pads the input tensor with 0s along the first dimension up to the length.
Args:
t: the input tensor, assuming the rank is at least 1.
length: a tensor of shape [1] or an integer, indicating the first dimension
of the input tensor t after padding, assuming length <= t.shape[0].
Returns:
padded_t: the padded tensor, whose first dimension is length. If the length
is an integer, the first dimension of padded_t is set to length
statically.
"""
t_rank = tf.rank(t)
t_shape = tf.shape(t)
t_d0 = t_shape[0]
pad_d0 = tf.expand_dims(length - t_d0, 0)
pad_shape = tf.cond(
tf.greater(t_rank, 1), lambda: tf.concat([pad_d0, t_shape[1:]], 0),
lambda: tf.expand_dims(length - t_d0, 0))
padded_t = tf.concat([t, tf.zeros(pad_shape, dtype=t.dtype)], 0)
if not _is_tensor(length):
padded_t = _set_dim_0(padded_t, length)
return padded_t
示例4: pad_or_clip_tensor
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import greater [as 别名]
def pad_or_clip_tensor(t, length):
"""Pad or clip the input tensor along the first dimension.
Args:
t: the input tensor, assuming the rank is at least 1.
length: a tensor of shape [1] or an integer, indicating the first dimension
of the input tensor t after processing.
Returns:
processed_t: the processed tensor, whose first dimension is length. If the
length is an integer, the first dimension of the processed tensor is set
to length statically.
"""
processed_t = tf.cond(
tf.greater(tf.shape(t)[0], length),
lambda: clip_tensor(t, length),
lambda: pad_tensor(t, length))
if not _is_tensor(length):
processed_t = _set_dim_0(processed_t, length)
return processed_t
示例5: _padded_batched_proposals_indicator
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import greater [as 别名]
def _padded_batched_proposals_indicator(self,
num_proposals,
max_num_proposals):
"""Creates indicator matrix of non-pad elements of padded batch proposals.
Args:
num_proposals: Tensor of type tf.int32 with shape [batch_size].
max_num_proposals: Maximum number of proposals per image (integer).
Returns:
A Tensor of type tf.bool with shape [batch_size, max_num_proposals].
"""
batch_size = tf.size(num_proposals)
tiled_num_proposals = tf.tile(
tf.expand_dims(num_proposals, 1), [1, max_num_proposals])
tiled_proposal_index = tf.tile(
tf.expand_dims(tf.range(max_num_proposals), 0), [batch_size, 1])
return tf.greater(tiled_num_proposals, tiled_proposal_index)
示例6: test_visualize_boxes_in_image
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import greater [as 别名]
def test_visualize_boxes_in_image(self):
image = tf.zeros((6, 4, 3))
corners = tf.constant([[0, 0, 5, 3],
[0, 0, 3, 2]], tf.float32)
boxes = box_list.BoxList(corners)
image_and_boxes = box_list_ops.visualize_boxes_in_image(image, boxes)
image_and_boxes_bw = tf.to_float(
tf.greater(tf.reduce_sum(image_and_boxes, 2), 0.0))
exp_result = [[1, 1, 1, 0],
[1, 1, 1, 0],
[1, 1, 1, 0],
[1, 0, 1, 0],
[1, 1, 1, 0],
[0, 0, 0, 0]]
with self.test_session() as sess:
output = sess.run(image_and_boxes_bw)
self.assertAllEqual(output.astype(int), exp_result)
示例7: filter_groundtruth_with_nan_box_coordinates
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import greater [as 别名]
def filter_groundtruth_with_nan_box_coordinates(tensor_dict):
"""Filters out groundtruth with no bounding boxes.
Args:
tensor_dict: a dictionary of following groundtruth tensors -
fields.InputDataFields.groundtruth_boxes
fields.InputDataFields.groundtruth_classes
fields.InputDataFields.groundtruth_is_crowd
fields.InputDataFields.groundtruth_area
fields.InputDataFields.groundtruth_label_types
Returns:
a dictionary of tensors containing only the groundtruth that have bounding
boxes.
"""
groundtruth_boxes = tensor_dict[fields.InputDataFields.groundtruth_boxes]
nan_indicator_vector = tf.greater(tf.reduce_sum(tf.to_int32(
tf.is_nan(groundtruth_boxes)), reduction_indices=[1]), 0)
valid_indicator_vector = tf.logical_not(nan_indicator_vector)
valid_indices = tf.where(valid_indicator_vector)
return retain_groundtruth(tensor_dict, valid_indices)
示例8: test_gather_with_dynamic_indexing
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import greater [as 别名]
def test_gather_with_dynamic_indexing(self):
corners = tf.constant([4 * [0.0], 4 * [1.0], 4 * [2.0], 4 * [3.0], 4 * [4.0]
])
weights = tf.constant([.5, .3, .7, .1, .9], tf.float32)
indices = tf.reshape(tf.where(tf.greater(weights, 0.4)), [-1])
expected_subset = [4 * [0.0], 4 * [2.0], 4 * [4.0]]
expected_weights = [.5, .7, .9]
boxes = box_list.BoxList(corners)
boxes.add_field('weights', weights)
subset = box_list_ops.gather(boxes, indices, ['weights'])
with self.test_session() as sess:
subset_output, weights_output = sess.run([subset.get(), subset.get_field(
'weights')])
self.assertAllClose(subset_output, expected_subset)
self.assertAllClose(weights_output, expected_weights)
示例9: _reshape_instance_masks
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import greater [as 别名]
def _reshape_instance_masks(self, keys_to_tensors):
"""Reshape instance segmentation masks.
The instance segmentation masks are reshaped to [num_instances, height,
width].
Args:
keys_to_tensors: a dictionary from keys to tensors.
Returns:
A 3-D float tensor of shape [num_instances, height, width] with values
in {0, 1}.
"""
height = keys_to_tensors['image/height']
width = keys_to_tensors['image/width']
to_shape = tf.cast(tf.stack([-1, height, width]), tf.int32)
masks = keys_to_tensors['image/object/mask']
if isinstance(masks, tf.SparseTensor):
masks = tf.sparse_tensor_to_dense(masks)
masks = tf.reshape(tf.to_float(tf.greater(masks, 0.0)), to_shape)
return tf.cast(masks, tf.float32)
示例10: filter_groundtruth_with_nan_box_coordinates
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import greater [as 别名]
def filter_groundtruth_with_nan_box_coordinates(tensor_dict):
"""Filters out groundtruth with no bounding boxes.
Args:
tensor_dict: a dictionary of following groundtruth tensors -
fields.InputDataFields.groundtruth_boxes
fields.InputDataFields.groundtruth_classes
fields.InputDataFields.groundtruth_keypoints
fields.InputDataFields.groundtruth_instance_masks
fields.InputDataFields.groundtruth_is_crowd
fields.InputDataFields.groundtruth_area
fields.InputDataFields.groundtruth_label_types
Returns:
a dictionary of tensors containing only the groundtruth that have bounding
boxes.
"""
groundtruth_boxes = tensor_dict[fields.InputDataFields.groundtruth_boxes]
nan_indicator_vector = tf.greater(tf.reduce_sum(tf.to_int32(
tf.is_nan(groundtruth_boxes)), reduction_indices=[1]), 0)
valid_indicator_vector = tf.logical_not(nan_indicator_vector)
valid_indices = tf.where(valid_indicator_vector)
return retain_groundtruth(tensor_dict, valid_indices)
示例11: _get_refined_encodings_for_postitive_class
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import greater [as 别名]
def _get_refined_encodings_for_postitive_class(
self, refined_box_encodings, flat_cls_targets_with_background,
batch_size):
# We only predict refined location encodings for the non background
# classes, but we now pad it to make it compatible with the class
# predictions
refined_box_encodings_with_background = tf.pad(refined_box_encodings,
[[0, 0], [1, 0], [0, 0]])
refined_box_encodings_masked_by_class_targets = (
box_list_ops.boolean_mask(
box_list.BoxList(
tf.reshape(refined_box_encodings_with_background,
[-1, self._box_coder.code_size])),
tf.reshape(tf.greater(flat_cls_targets_with_background, 0), [-1]),
use_static_shapes=self._use_static_shapes,
indicator_sum=batch_size * self.max_num_proposals
if self._use_static_shapes else None).get())
return tf.reshape(
refined_box_encodings_masked_by_class_targets, [
batch_size, self.max_num_proposals,
self._box_coder.code_size
])
示例12: mode
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import greater [as 别名]
def mode(cls, parameters: Dict[str, Tensor]) -> Tensor:
mu = parameters["mu"]
tau = parameters["tau"]
nu = parameters["nu"]
beta = parameters["beta"]
lam = 1./beta
mode = tf.zeros_like(mu) * tf.zeros_like(mu)
mode = tf.where(tf.logical_and(tf.greater(nu, mu),
tf.less(mu+lam/tau, nu)),
mu+lam/tau,
mode)
mode = tf.where(tf.logical_and(tf.greater(nu, mu),
tf.greater_equal(mu+lam/tau, nu)),
nu,
mode)
mode = tf.where(tf.logical_and(tf.less_equal(nu, mu),
tf.greater(mu-lam/tau, nu)),
mu-lam/tau,
mode)
mode = tf.where(tf.logical_and(tf.less_equal(nu, mu),
tf.less_equal(mu-lam/tau, nu)),
nu,
mode)
return(mode)
示例13: _filter_input_rows
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import greater [as 别名]
def _filter_input_rows(self, *row_parts) -> tf.bool:
row_parts = self.model_input_tensors_former.from_model_input_form(row_parts)
#assert all(tensor.shape == (self.config.MAX_CONTEXTS,) for tensor in
# {row_parts.path_source_token_indices, row_parts.path_indices,
# row_parts.path_target_token_indices, row_parts.context_valid_mask})
# FIXME: Does "valid" here mean just "no padding" or "neither padding nor OOV"? I assumed just "no padding".
any_word_valid_mask_per_context_part = [
tf.not_equal(tf.reduce_max(row_parts.path_source_token_indices, axis=0),
self.vocabs.token_vocab.word_to_index[self.vocabs.token_vocab.special_words.PAD]),
tf.not_equal(tf.reduce_max(row_parts.path_target_token_indices, axis=0),
self.vocabs.token_vocab.word_to_index[self.vocabs.token_vocab.special_words.PAD]),
tf.not_equal(tf.reduce_max(row_parts.path_indices, axis=0),
self.vocabs.path_vocab.word_to_index[self.vocabs.path_vocab.special_words.PAD])]
any_contexts_is_valid = reduce(tf.logical_or, any_word_valid_mask_per_context_part) # scalar
if self.estimator_action.is_evaluate:
cond = any_contexts_is_valid # scalar
else: # training
word_is_valid = tf.greater(
row_parts.target_index, self.vocabs.target_vocab.word_to_index[self.vocabs.target_vocab.special_words.OOV]) # scalar
cond = tf.logical_and(word_is_valid, any_contexts_is_valid) # scalar
return cond # scalar
示例14: smooth_l1_loss_rpn
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import greater [as 别名]
def smooth_l1_loss_rpn(bbox_pred, bbox_targets, label, sigma=1.0):
'''
:param bbox_pred: [-1, 4]
:param bbox_targets: [-1, 4]
:param label: [-1]
:param sigma:
:return:
'''
value = _smooth_l1_loss_base(bbox_pred, bbox_targets, sigma=sigma)
value = tf.reduce_sum(value, axis=1) # to sum in axis 1
# rpn_select = tf.reshape(tf.where(tf.greater_equal(label, 0)), [-1])
rpn_select = tf.where(tf.greater(label, 0))
# rpn_select = tf.stop_gradient(rpn_select) # to avoid
selected_value = tf.gather(value, rpn_select)
non_ignored_mask = tf.stop_gradient(
1.0 - tf.to_float(tf.equal(label, -1))) # positve is 1.0 others is 0.0
bbox_loss = tf.reduce_sum(selected_value) / tf.maximum(1.0, tf.reduce_sum(non_ignored_mask))
return bbox_loss
示例15: apply_mask
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import greater [as 别名]
def apply_mask(gan, config, net,x=None):
if x == None:
x = gan.inputs.x
filtered = net
shape = gan.ops.shape(x)
mask = tf.ones([shape[1], shape[2], shape[3]])
mask = tf.greater(mask, 0)
scaling = 0.6
mask = tf.image.central_crop(mask, scaling)
left = (shape[1]*scaling)//2 * 0.75
top = (shape[2]*scaling)//2 * 0.75
mask = tf.image.pad_to_bounding_box(mask, int(top), int(left), shape[1], shape[2])
mask = tf.cast(mask, tf.float32)
backmask = (1.0-mask)
filtered = backmask* x + mask * filtered
print("FRAMING IMAGE", filtered)
return filtered