Python tensorflow.python.ops.math_ops.logical_and() Examples
The following are 30
code examples of tensorflow.python.ops.math_ops.logical_and().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
tensorflow.python.ops.math_ops
, or try the search function
.
Example #1
Source File: tensor_util.py From keras-lambda with MIT License | 6 votes |
def _is_shape(expected_shape, actual_tensor, actual_shape=None): """Returns whether actual_tensor's shape is expected_shape. Args: expected_shape: Integer list defining the expected shape, or tensor of same. actual_tensor: Tensor to test. actual_shape: Shape of actual_tensor, if we already have it. Returns: New tensor. """ with ops.name_scope('is_shape', values=[actual_tensor]) as scope: is_rank = _is_rank(array_ops.size(expected_shape), actual_tensor) if actual_shape is None: actual_shape = array_ops.shape(actual_tensor, name='actual') shape_equal = _all_equal( ops.convert_to_tensor(expected_shape, name='expected'), actual_shape) return math_ops.logical_and(is_rank, shape_equal, name=scope)
Example #2
Source File: tensor_util.py From deep_image_model with Apache License 2.0 | 6 votes |
def _is_shape(expected_shape, actual_tensor, actual_shape=None): """Returns whether actual_tensor's shape is expected_shape. Args: expected_shape: Integer list defining the expected shape, or tensor of same. actual_tensor: Tensor to test. actual_shape: Shape of actual_tensor, if we already have it. Returns: New tensor. """ with ops.name_scope('is_shape', values=[actual_tensor]) as scope: is_rank = _is_rank(array_ops.size(expected_shape), actual_tensor) if actual_shape is None: actual_shape = array_ops.shape(actual_tensor, name='actual') shape_equal = _all_equal( ops.convert_to_tensor(expected_shape, name='expected'), actual_shape) return math_ops.logical_and(is_rank, shape_equal, name=scope)
Example #3
Source File: tensor_util.py From auto-alt-text-lambda-api with MIT License | 6 votes |
def _is_shape(expected_shape, actual_tensor, actual_shape=None): """Returns whether actual_tensor's shape is expected_shape. Args: expected_shape: Integer list defining the expected shape, or tensor of same. actual_tensor: Tensor to test. actual_shape: Shape of actual_tensor, if we already have it. Returns: New tensor. """ with ops.name_scope('is_shape', values=[actual_tensor]) as scope: is_rank = _is_rank(array_ops.size(expected_shape), actual_tensor) if actual_shape is None: actual_shape = array_ops.shape(actual_tensor, name='actual') shape_equal = _all_equal( ops.convert_to_tensor(expected_shape, name='expected'), actual_shape) return math_ops.logical_and(is_rank, shape_equal, name=scope)
Example #4
Source File: bijector.py From auto-alt-text-lambda-api with MIT License | 6 votes |
def _process_matrix(self, matrix, min_rank, event_ndims): """Helper to __init__ which gets matrix in batch-ready form.""" # Pad the matrix so that matmul works in the case of a matrix and vector # input. Keep track if the matrix was padded, to distinguish between a # rank 3 tensor and a padded rank 2 tensor. # TODO(srvasude): Remove side-effects from functions. Its currently unbroken # but error-prone since the function call order may change in the future. self._rank_two_event_ndims_one = math_ops.logical_and( math_ops.equal(array_ops.rank(matrix), min_rank), math_ops.equal(event_ndims, 1)) left = array_ops.where(self._rank_two_event_ndims_one, 1, 0) pad = array_ops.concat( [array_ops.ones( [left], dtype=dtypes.int32), array_ops.shape(matrix)], 0) return array_ops.reshape(matrix, pad)
Example #5
Source File: beta.py From auto-alt-text-lambda-api with MIT License | 6 votes |
def _mode(self): mode = (self.a - 1.)/ (self.a_b_sum - 2.) if self.allow_nan_stats: nan = np.array(np.nan, dtype=self.dtype.as_numpy_dtype()) return array_ops.where( math_ops.logical_and( math_ops.greater(self.a, 1.), math_ops.greater(self.b, 1.)), mode, array_ops.fill(self.batch_shape(), nan, name="nan")) else: return control_flow_ops.with_dependencies([ check_ops.assert_less( array_ops.ones((), dtype=self.dtype), self.a, message="Mode not defined for components of a <= 1."), check_ops.assert_less( array_ops.ones((), dtype=self.dtype), self.b, message="Mode not defined for components of b <= 1."), ], mode)
Example #6
Source File: beta.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 6 votes |
def _mode(self): mode = (self.concentration1 - 1.) / (self.total_concentration - 2.) if self.allow_nan_stats: nan = array_ops.fill( self.batch_shape_tensor(), np.array(np.nan, dtype=self.dtype.as_numpy_dtype()), name="nan") is_defined = math_ops.logical_and(self.concentration1 > 1., self.concentration0 > 1.) return array_ops.where(is_defined, mode, nan) return control_flow_ops.with_dependencies([ check_ops.assert_less( array_ops.ones([], dtype=self.dtype), self.concentration1, message="Mode undefined for concentration1 <= 1."), check_ops.assert_less( array_ops.ones([], dtype=self.dtype), self.concentration0, message="Mode undefined for concentration0 <= 1.") ], mode)
Example #7
Source File: tensor_util.py From lambda-packs with MIT License | 6 votes |
def _is_shape(expected_shape, actual_tensor, actual_shape=None): """Returns whether actual_tensor's shape is expected_shape. Args: expected_shape: Integer list defining the expected shape, or tensor of same. actual_tensor: Tensor to test. actual_shape: Shape of actual_tensor, if we already have it. Returns: New tensor. """ with ops.name_scope('is_shape', values=[actual_tensor]) as scope: is_rank = _is_rank(array_ops.size(expected_shape), actual_tensor) if actual_shape is None: actual_shape = array_ops.shape(actual_tensor, name='actual') shape_equal = _all_equal( ops.convert_to_tensor(expected_shape, name='expected'), actual_shape) return math_ops.logical_and(is_rank, shape_equal, name=scope)
Example #8
Source File: affine_impl.py From lambda-packs with MIT License | 6 votes |
def _process_matrix(self, matrix, min_rank, event_ndims): """Helper to __init__ which gets matrix in batch-ready form.""" # Pad the matrix so that matmul works in the case of a matrix and vector # input. Keep track if the matrix was padded, to distinguish between a # rank 3 tensor and a padded rank 2 tensor. # TODO(srvasude): Remove side-effects from functions. Its currently unbroken # but error-prone since the function call order may change in the future. self._rank_two_event_ndims_one = math_ops.logical_and( math_ops.equal(array_ops.rank(matrix), min_rank), math_ops.equal(event_ndims, 1)) left = array_ops.where(self._rank_two_event_ndims_one, 1, 0) pad = array_ops.concat( [array_ops.ones( [left], dtype=dtypes.int32), array_ops.shape(matrix)], 0) return array_ops.reshape(matrix, pad)
Example #9
Source File: beta.py From keras-lambda with MIT License | 6 votes |
def _mode(self): mode = (self.a - 1.)/ (self.a_b_sum - 2.) if self.allow_nan_stats: nan = np.array(np.nan, dtype=self.dtype.as_numpy_dtype()) return array_ops.where( math_ops.logical_and( math_ops.greater(self.a, 1.), math_ops.greater(self.b, 1.)), mode, array_ops.fill(self.batch_shape(), nan, name="nan")) else: return control_flow_ops.with_dependencies([ check_ops.assert_less( array_ops.ones((), dtype=self.dtype), self.a, message="Mode not defined for components of a <= 1."), check_ops.assert_less( array_ops.ones((), dtype=self.dtype), self.b, message="Mode not defined for components of b <= 1."), ], mode)
Example #10
Source File: beta.py From lambda-packs with MIT License | 6 votes |
def _mode(self): mode = (self.concentration1 - 1.) / (self.total_concentration - 2.) if self.allow_nan_stats: nan = array_ops.fill( self.batch_shape_tensor(), np.array(np.nan, dtype=self.dtype.as_numpy_dtype()), name="nan") is_defined = math_ops.logical_and(self.concentration1 > 1., self.concentration0 > 1.) return array_ops.where(is_defined, mode, nan) return control_flow_ops.with_dependencies([ check_ops.assert_less( array_ops.ones([], dtype=self.dtype), self.concentration1, message="Mode undefined for concentration1 <= 1."), check_ops.assert_less( array_ops.ones([], dtype=self.dtype), self.concentration0, message="Mode undefined for concentration0 <= 1.") ], mode)
Example #11
Source File: bijector.py From keras-lambda with MIT License | 6 votes |
def _process_matrix(self, matrix, min_rank, event_ndims): """Helper to __init__ which gets matrix in batch-ready form.""" # Pad the matrix so that matmul works in the case of a matrix and vector # input. Keep track if the matrix was padded, to distinguish between a # rank 3 tensor and a padded rank 2 tensor. # TODO(srvasude): Remove side-effects from functions. Its currently unbroken # but error-prone since the function call order may change in the future. self._rank_two_event_ndims_one = math_ops.logical_and( math_ops.equal(array_ops.rank(matrix), min_rank), math_ops.equal(event_ndims, 1)) left = array_ops.where(self._rank_two_event_ndims_one, 1, 0) pad = array_ops.concat( [array_ops.ones( [left], dtype=dtypes.int32), array_ops.shape(matrix)], 0) return array_ops.reshape(matrix, pad)
Example #12
Source File: sequence_queueing_state_saver.py From deep_image_model with Apache License 2.0 | 5 votes |
def _check_multiple_of(value, multiple_of): """Checks that value `value` is a non-zero multiple of `multiple_of`. Args: value: an int32 scalar Tensor. multiple_of: an int or int32 scalar Tensor. Returns: new_value: an int32 scalar Tensor matching `value`, but which includes an assertion that `value` is a multiple of `multiple_of`. """ assert isinstance(value, ops.Tensor) with ops.control_dependencies([ control_flow_ops.Assert( math_ops.logical_and( math_ops.equal(math_ops.mod(value, multiple_of), 0), math_ops.not_equal(value, 0)), [string_ops.string_join( ["Tensor %s should be a multiple of: " % value.name, string_ops.as_string(multiple_of), ", but saw value: ", string_ops.as_string(value), ". Consider setting pad=True."])])]): new_value = array_ops.identity( value, name="multiple_of_checked") return new_value
Example #13
Source File: metrics_impl.py From keras-lambda with MIT License | 5 votes |
def false_negatives(labels, predictions, weights=None, metrics_collections=None, updates_collections=None, name=None): """Computes the total number of false positives. If `weights` is `None`, weights default to 1. Use weights of 0 to mask values. Args: labels: The ground truth values, a `Tensor` whose dimensions must match `predictions`. Will be cast to `bool`. predictions: The predicted values, a `Tensor` of arbitrary dimensions. Will be cast to `bool`. weights: Optional `Tensor` whose rank is either 0, or the same rank as `labels`, and must be broadcastable to `labels` (i.e., all dimensions must be either `1`, or the same as the corresponding `labels` dimension). metrics_collections: An optional list of collections that the metric value variable should be added to. updates_collections: An optional list of collections that the metric update ops should be added to. name: An optional variable_scope name. Returns: value_tensor: A `Tensor` representing the current value of the metric. update_op: An operation that accumulates the error from a batch of data. Raises: ValueError: If `weights` is not `None` and its shape doesn't match `values`, or if either `metrics_collections` or `updates_collections` are not a list or tuple. """ with variable_scope.variable_scope( name, 'false_negatives', (predictions, labels, weights)): labels = math_ops.cast(labels, dtype=dtypes.bool) predictions = math_ops.cast(predictions, dtype=dtypes.bool) predictions.get_shape().assert_is_compatible_with(labels.get_shape()) is_false_negative = math_ops.logical_and(math_ops.equal(labels, True), math_ops.equal(predictions, False)) return _count_condition(is_false_negative, weights, metrics_collections, updates_collections)
Example #14
Source File: embedding_ops.py From deep_image_model with Apache License 2.0 | 5 votes |
def _prune_invalid_ids(sparse_ids, sparse_weights): """Prune invalid IDs (< 0) from the input ids and weights.""" is_id_valid = math_ops.greater_equal(sparse_ids.values, 0) if sparse_weights is not None: is_id_valid = math_ops.logical_and( is_id_valid, math_ops.greater(sparse_weights.values, 0)) sparse_ids = sparse_ops.sparse_retain(sparse_ids, is_id_valid) if sparse_weights is not None: sparse_weights = sparse_ops.sparse_retain(sparse_weights, is_id_valid) return sparse_ids, sparse_weights
Example #15
Source File: metric_ops.py From deep_image_model with Apache License 2.0 | 5 votes |
def _streaming_false_negatives(predictions, labels, weights=None, metrics_collections=None, updates_collections=None, name=None): """Computes the total number of false positives. If `weights` is `None`, weights default to 1. Use weights of 0 to mask values. Args: predictions: The predicted values, a `bool` `Tensor` of arbitrary dimensions. labels: The ground truth values, a `bool` `Tensor` whose dimensions must match `predictions`. weights: An optional `Tensor` whose shape is broadcastable to `predictions`. metrics_collections: An optional list of collections that the metric value variable should be added to. updates_collections: An optional list of collections that the metric update ops should be added to. name: An optional variable_scope name. Returns: value_tensor: A tensor representing the current value of the metric. update_op: An operation that accumulates the error from a batch of data. Raises: ValueError: If `weights` is not `None` and its shape doesn't match `values`, or if either `metrics_collections` or `updates_collections` are not a list or tuple. """ with variable_scope.variable_scope( name, 'false_negatives', [predictions, labels]): predictions.get_shape().assert_is_compatible_with(labels.get_shape()) is_false_negative = math_ops.logical_and(math_ops.equal(labels, 1), math_ops.equal(predictions, 0)) return _count_condition(is_false_negative, weights, metrics_collections, updates_collections)
Example #16
Source File: core.py From keras-lambda with MIT License | 5 votes |
def __and__(self, other): return logical_and(self, other)
Example #17
Source File: metrics.py From ULTRA with Apache License 2.0 | 5 votes |
def ordered_pair_accuracy(labels, predictions, weights=None, name=None): """Computes the percentage of correctedly ordered pair. For any pair of examples, we compare their orders determined by `labels` and `predictions`. They are correctly ordered if the two orders are compatible. That is, labels l_i > l_j and predictions s_i > s_j and the weight for this pair is the weight from the l_i. Args: labels: A `Tensor` of the same shape as `predictions`. predictions: A `Tensor` with shape [batch_size, list_size]. Each value is the ranking score of the corresponding example. weights: A `Tensor` of the same shape of predictions or [batch_size, 1]. The former case is per-example and the latter case is per-list. name: A string used as the name for this metric. Returns: A metric for the accuracy or ordered pairs. """ with ops.name_scope(name, 'ordered_pair_accuracy', (labels, predictions, weights)): clean_labels, predictions, weights, _ = _prepare_and_validate_params( labels, predictions, weights) label_valid = math_ops.equal(clean_labels, labels) valid_pair = math_ops.logical_and( array_ops.expand_dims(label_valid, 2), array_ops.expand_dims(label_valid, 1)) pair_label_diff = array_ops.expand_dims( clean_labels, 2) - array_ops.expand_dims(clean_labels, 1) pair_pred_diff = array_ops.expand_dims( predictions, 2) - array_ops.expand_dims(predictions, 1) # Correct pairs are represented twice in the above pair difference tensors. # We only take one copy for each pair. correct_pairs = math_ops.to_float(pair_label_diff > 0) * math_ops.to_float( pair_pred_diff > 0) pair_weights = math_ops.to_float( pair_label_diff > 0) * array_ops.expand_dims( weights, 2) * math_ops.to_float(valid_pair) return math_ops.reduce_mean(correct_pairs * pair_weights)
Example #18
Source File: tpu_estimator.py From embedding-as-service with MIT License | 5 votes |
def should_stop(scalar_stopping_signal): """Detects whether scalar_stopping_signal indicates stopping.""" if isinstance(scalar_stopping_signal, ops.Tensor): # STOPPING_SIGNAL is a constant True. Here, the logical_and is just the TF # way to express the bool check whether scalar_stopping_signal is True. return math_ops.logical_and(scalar_stopping_signal, _StopSignals.STOPPING_SIGNAL) else: # For non Tensor case, it is used in SessionRunHook. So, we cannot modify # the graph anymore. Here, we use pure Python. return bool(scalar_stopping_signal)
Example #19
Source File: tpu_estimator.py From transformer-xl with Apache License 2.0 | 5 votes |
def should_stop(scalar_stopping_signal): """Detects whether scalar_stopping_signal indicates stopping.""" if isinstance(scalar_stopping_signal, ops.Tensor): # STOPPING_SIGNAL is a constant True. Here, the logical_and is just the TF # way to express the bool check whether scalar_stopping_signal is True. return math_ops.logical_and( scalar_stopping_signal, _StopSignals.STOPPING_SIGNAL) else: # For non Tensor case, it is used in SessionRunHook. So, we cannot modify # the graph anymore. Here, we use pure Python. return bool(scalar_stopping_signal)
Example #20
Source File: sparse_optimizers.py From rigl with Apache License 2.0 | 5 votes |
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
Example #21
Source File: tpu_estimator.py From xlnet with Apache License 2.0 | 5 votes |
def should_stop(scalar_stopping_signal): """Detects whether scalar_stopping_signal indicates stopping.""" if isinstance(scalar_stopping_signal, ops.Tensor): # STOPPING_SIGNAL is a constant True. Here, the logical_and is just the TF # way to express the bool check whether scalar_stopping_signal is True. return math_ops.logical_and(scalar_stopping_signal, _StopSignals.STOPPING_SIGNAL) else: # For non Tensor case, it is used in SessionRunHook. So, we cannot modify # the graph anymore. Here, we use pure Python. return bool(scalar_stopping_signal)
Example #22
Source File: test_forward.py From incubator-tvm with Apache License 2.0 | 5 votes |
def _test_forward_logical_and(data): """ One iteration of logical and """ return _test_logical_binary(math_ops.logical_and, data)
Example #23
Source File: transformed_distribution.py From keras-lambda with MIT License | 5 votes |
def _logical_and(*args): """Convenience function which attempts to statically `reduce_all`.""" args_ = [_static_value(x) for x in args] if any(x is not None and not bool(x) for x in args_): return constant_op.constant(False) if all(x is not None and bool(x) for x in args_): return constant_op.constant(True) if len(args) == 2: return math_ops.logical_and(*args) return math_ops.reduce_all(args)
Example #24
Source File: transformed_distribution.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 5 votes |
def _logical_and(*args): """Convenience function which attempts to statically `reduce_all`.""" args_ = [_static_value(x) for x in args] if any(x is not None and not bool(x) for x in args_): return constant_op.constant(False) if all(x is not None and bool(x) for x in args_): return constant_op.constant(True) if len(args) == 2: return math_ops.logical_and(*args) return math_ops.reduce_all(args)
Example #25
Source File: sequence_queueing_state_saver.py From keras-lambda with MIT License | 5 votes |
def _check_multiple_of(value, multiple_of): """Checks that value `value` is a non-zero multiple of `multiple_of`. Args: value: an int32 scalar Tensor. multiple_of: an int or int32 scalar Tensor. Returns: new_value: an int32 scalar Tensor matching `value`, but which includes an assertion that `value` is a multiple of `multiple_of`. """ assert isinstance(value, ops.Tensor) with ops.control_dependencies([ control_flow_ops.Assert( math_ops.logical_and( math_ops.equal(math_ops.mod(value, multiple_of), 0), math_ops.not_equal(value, 0)), [ string_ops.string_join([ "Tensor %s should be a multiple of: " % value.name, string_ops.as_string(multiple_of), ", but saw value: ", string_ops.as_string(value), ". Consider setting pad=True." ]) ]) ]): new_value = array_ops.identity(value, name="multiple_of_checked") return new_value
Example #26
Source File: metric_ops.py From deep_image_model with Apache License 2.0 | 5 votes |
def _streaming_false_positives(predictions, labels, weights=None, metrics_collections=None, updates_collections=None, name=None): """Sum the weights of false positives. If `weights` is `None`, weights default to 1. Use weights of 0 to mask values. Args: predictions: The predicted values, a `bool` `Tensor` of arbitrary dimensions. labels: The ground truth values, a `bool` `Tensor` whose dimensions must match `predictions`. weights: An optional `Tensor` whose shape is broadcastable to `predictions`. metrics_collections: An optional list of collections that the metric value variable should be added to. updates_collections: An optional list of collections that the metric update ops should be added to. name: An optional variable_scope name. Returns: value_tensor: A tensor representing the current value of the metric. update_op: An operation that accumulates the error from a batch of data. Raises: ValueError: If `predictions` and `labels` have mismatched shapes, or if `weights` is not `None` and its shape doesn't match `predictions`, or if either `metrics_collections` or `updates_collections` are not a list or tuple. """ with variable_scope.variable_scope( name, 'false_positives', [predictions, labels]): predictions.get_shape().assert_is_compatible_with(labels.get_shape()) is_false_positive = math_ops.logical_and(math_ops.equal(labels, 0), math_ops.equal(predictions, 1)) return _count_condition(is_false_positive, weights, metrics_collections, updates_collections)
Example #27
Source File: embedding_ops.py From lambda-packs with MIT License | 5 votes |
def _prune_invalid_ids(sparse_ids, sparse_weights): """Prune invalid IDs (< 0) from the input ids and weights.""" is_id_valid = math_ops.greater_equal(sparse_ids.values, 0) if sparse_weights is not None: is_id_valid = math_ops.logical_and( is_id_valid, math_ops.greater(sparse_weights.values, 0)) sparse_ids = sparse_ops.sparse_retain(sparse_ids, is_id_valid) if sparse_weights is not None: sparse_weights = sparse_ops.sparse_retain(sparse_weights, is_id_valid) return sparse_ids, sparse_weights
Example #28
Source File: sequence_queueing_state_saver.py From lambda-packs with MIT License | 5 votes |
def _check_multiple_of(value, multiple_of): """Checks that value `value` is a non-zero multiple of `multiple_of`. Args: value: an int32 scalar Tensor. multiple_of: an int or int32 scalar Tensor. Returns: new_value: an int32 scalar Tensor matching `value`, but which includes an assertion that `value` is a multiple of `multiple_of`. """ assert isinstance(value, ops.Tensor) with ops.control_dependencies([ control_flow_ops.Assert( math_ops.logical_and( math_ops.equal(math_ops.mod(value, multiple_of), 0), math_ops.not_equal(value, 0)), [ string_ops.string_join([ "Tensor %s should be a multiple of: " % value.name, string_ops.as_string(multiple_of), ", but saw value: ", string_ops.as_string(value), ". Consider setting pad=True." ]) ]) ]): new_value = array_ops.identity(value, name="multiple_of_checked") return new_value
Example #29
Source File: transformed_distribution.py From lambda-packs with MIT License | 5 votes |
def _logical_and(*args): """Convenience function which attempts to statically `reduce_all`.""" args_ = [_static_value(x) for x in args] if any(x is not None and not bool(x) for x in args_): return constant_op.constant(False) if all(x is not None and bool(x) for x in args_): return constant_op.constant(True) if len(args) == 2: return math_ops.logical_and(*args) return math_ops.reduce_all(args)
Example #30
Source File: metrics_impl.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def false_negatives(labels, predictions, weights=None, metrics_collections=None, updates_collections=None, name=None): """Computes the total number of false positives. If `weights` is `None`, weights default to 1. Use weights of 0 to mask values. Args: labels: The ground truth values, a `Tensor` whose dimensions must match `predictions`. Will be cast to `bool`. predictions: The predicted values, a `Tensor` of arbitrary dimensions. Will be cast to `bool`. weights: Optional `Tensor` whose rank is either 0, or the same rank as `labels`, and must be broadcastable to `labels` (i.e., all dimensions must be either `1`, or the same as the corresponding `labels` dimension). metrics_collections: An optional list of collections that the metric value variable should be added to. updates_collections: An optional list of collections that the metric update ops should be added to. name: An optional variable_scope name. Returns: value_tensor: A `Tensor` representing the current value of the metric. update_op: An operation that accumulates the error from a batch of data. Raises: ValueError: If `weights` is not `None` and its shape doesn't match `values`, or if either `metrics_collections` or `updates_collections` are not a list or tuple. """ with variable_scope.variable_scope( name, 'false_negatives', (predictions, labels, weights)): labels = math_ops.cast(labels, dtype=dtypes.bool) predictions = math_ops.cast(predictions, dtype=dtypes.bool) predictions.get_shape().assert_is_compatible_with(labels.get_shape()) is_false_negative = math_ops.logical_and(math_ops.equal(labels, True), math_ops.equal(predictions, False)) return _count_condition(is_false_negative, weights, metrics_collections, updates_collections)