Accumulate accuracy statistics. `labels` and `predictions` should have the same shape except the predictions must have one additional trailing dimension equal to the number of classes(you want to predict). Type of labels and predictions can be different. Args: labels: Te
(self, labels, predictions, weights=None)
| 518 | super(SparseAccuracy, self).__init__(name=name, dtype=dtype) |
| 519 | |
| 520 | def call(self, labels, predictions, weights=None): |
| 521 | """Accumulate accuracy statistics. |
| 522 | |
| 523 | `labels` and `predictions` should have the same shape except the |
| 524 | predictions must have one additional trailing dimension equal to the |
| 525 | number of classes(you want to predict). |
| 526 | |
| 527 | Type of labels and predictions can be different. |
| 528 | |
| 529 | Args: |
| 530 | labels: Tensor of shape (batch_size, ) containing integers |
| 531 | predictions: Tensor with the logits or probabilities for each example. |
| 532 | weights: Optional weighting of each example. Defaults to 1. |
| 533 | |
| 534 | Returns: |
| 535 | The arguments, for easy chaining. |
| 536 | """ |
| 537 | check_ops.assert_equal( |
| 538 | array_ops.shape(labels), array_ops.shape(predictions)[0], |
| 539 | message="First axis of labels and predictions is unequal") |
| 540 | predictions = math_ops.argmax(predictions, axis=-1) |
| 541 | labels = math_ops.cast(labels, dtypes.int64) |
| 542 | matches = math_ops.equal(labels, predictions) |
| 543 | matches = math_ops.cast(matches, self.dtype) |
| 544 | super(SparseAccuracy, self).call(matches, weights=weights) |
| 545 | if weights is None: |
| 546 | return labels, predictions |
| 547 | return labels, predictions, weights |