Accumulate accuracy statistics. `labels` and `predictions` should have the same shape and type. Args: labels: Binary Tensor(containing 0 or 1). predictions: Tensor with probabilities or logits. weights: Optional weighting of each example. Defaults to 1. Returns:
(self, labels, predictions, weights=None)
| 472 | self.threshold = threshold |
| 473 | |
| 474 | def call(self, labels, predictions, weights=None): |
| 475 | """Accumulate accuracy statistics. |
| 476 | |
| 477 | `labels` and `predictions` should have the same shape and type. |
| 478 | |
| 479 | Args: |
| 480 | labels: Binary Tensor(containing 0 or 1). |
| 481 | predictions: Tensor with probabilities or logits. |
| 482 | weights: Optional weighting of each example. Defaults to 1. |
| 483 | |
| 484 | Returns: |
| 485 | The arguments, for easy chaining. |
| 486 | """ |
| 487 | check_ops.assert_equal( |
| 488 | array_ops.shape(labels), array_ops.shape(predictions), |
| 489 | message="Shapes of labels and predictions are unequal") |
| 490 | predictions = ops.convert_to_tensor(predictions) |
| 491 | predictions = predictions > self.threshold |
| 492 | # Convert labels to bool to match predictions. |
| 493 | labels = math_ops.cast(labels, dtypes.bool) |
| 494 | matches = math_ops.equal(labels, predictions) |
| 495 | matches = math_ops.cast(matches, self.dtype) |
| 496 | super(BinaryAccuracy, self).call(matches, weights=weights) |
| 497 | if weights is None: |
| 498 | return labels, predictions |
| 499 | return labels, predictions, weights |
| 500 | |
| 501 | |
| 502 | class SparseAccuracy(Mean): |
nothing calls this directly
no test coverage detected