Skip to content

Commit

Permalink
Fixed Average-Precision Integration Error (#684)
Browse files Browse the repository at this point in the history
  • Loading branch information
czaloom authored Jul 29, 2024
1 parent b1d5030 commit 5fcbd52
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
12 changes: 6 additions & 6 deletions api/tests/functional-tests/backend/metrics/test_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1197,7 +1197,7 @@ def _metric_to_dict(m) -> dict:
expected_ap_metrics = [
{"iou": 0.5, "value": 0.505, "label": {"key": "class", "value": "2"}},
{"iou": 0.75, "value": 0.505, "label": {"key": "class", "value": "2"}},
{"iou": 0.5, "value": 0.79, "label": {"key": "class", "value": "49"}},
{"iou": 0.5, "value": 0.791, "label": {"key": "class", "value": "49"}},
{
"iou": 0.75,
"value": 0.576,
Expand All @@ -1222,7 +1222,7 @@ def _metric_to_dict(m) -> dict:
},
{
"ious": iou_thresholds,
"value": 0.555, # note COCO had 0.556
"value": 0.556,
"label": {"key": "class", "value": "49"},
},
{
Expand Down Expand Up @@ -1434,7 +1434,7 @@ def _metric_to_dict(m) -> dict:
expected_ap_metrics = [
{"iou": 0.5, "value": 0.505, "label": {"key": "class", "value": "2"}},
{"iou": 0.75, "value": 0.505, "label": {"key": "class", "value": "2"}},
{"iou": 0.5, "value": 0.79, "label": {"key": "class", "value": "49"}},
{"iou": 0.5, "value": 0.791, "label": {"key": "class", "value": "49"}},
{
"iou": 0.75,
"value": 0.576,
Expand All @@ -1459,7 +1459,7 @@ def _metric_to_dict(m) -> dict:
},
{
"ious": iou_thresholds,
"value": 0.555, # note COCO had 0.556
"value": 0.556,
"label": {"key": "class", "value": "49"},
},
{
Expand Down Expand Up @@ -1671,7 +1671,7 @@ def _metric_to_dict(m) -> dict:
expected_ap_metrics = [
{"iou": 0.5, "value": 0.505, "label": {"key": "class", "value": "2"}},
{"iou": 0.75, "value": 0.505, "label": {"key": "class", "value": "2"}},
{"iou": 0.5, "value": 0.79, "label": {"key": "class", "value": "49"}},
{"iou": 0.5, "value": 0.791, "label": {"key": "class", "value": "49"}},
{
"iou": 0.75,
"value": 0.576,
Expand All @@ -1696,7 +1696,7 @@ def _metric_to_dict(m) -> dict:
},
{
"ious": iou_thresholds,
"value": 0.555, # note COCO had 0.556
"value": 0.556,
"label": {"key": "class", "value": "49"},
},
{
Expand Down
6 changes: 5 additions & 1 deletion api/valor_api/backend/metrics/detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ def _calculate_101_pt_interp(precisions, recalls) -> float:
cutoff_idx = 0
ret = 0
for r in [0.01 * i for i in range(101)]:
while cutoff_idx < len(data) and data[cutoff_idx][1] < r:
while (
cutoff_idx < len(data)
and data[cutoff_idx][1] < r
and not math.isclose(data[cutoff_idx][1], r)
):
cutoff_idx += 1
while prec_heap and prec_heap[0][1] < cutoff_idx:
heapq.heappop(prec_heap)
Expand Down

0 comments on commit 5fcbd52

Please sign in to comment.