Skip to content

Commit

Permalink
safe division
Browse files Browse the repository at this point in the history
  • Loading branch information
tlpss committed Sep 29, 2023
1 parent 64b3bdd commit d0cbb05
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions keypoint_detection/models/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ def calculate_precision_recall(
else:
false_positives += 1

precision.append(true_positives / (true_positives + false_positives))
recall.append(true_positives / total_ground_truth_keypoints)
precision.append(_zero_aware_division(true_positives, (true_positives + false_positives)))
recall.append(_zero_aware_division(true_positives, total_ground_truth_keypoints))

precision.append(0.0)
recall.append(1.0)
Expand Down Expand Up @@ -230,6 +230,15 @@ def reset(self) -> None:
metric.reset()


def _zero_aware_division(num: float, denom: float) -> float:
if num == 0:
return 0
if denom == 0 and num != 0:
return float("inf")
else:
return num / denom


if __name__ == "__main__":
print(
check_forward_full_state_property(
Expand Down

0 comments on commit d0cbb05

Please sign in to comment.