-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_detection.py
30 lines (24 loc) · 1.18 KB
/
test_detection.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from pathlib import Path
import numpy as np
import pytest
import debobo
@pytest.mark.parametrize('idx, iou_thresh, max_detections', pytest.coco_params)
def test_map_score_evaluator(idx, iou_thresh, max_detections, detection_data, coco_results):
image_ids = list(set(detection_data.dt['image_id']).union(detection_data.gt['image_id']))
groundtruths = (
detection_data.gt.loc[detection_data.gt['image_id'] == image_id] \
.to_records(index=False)[['x1', 'y1', 'x2', 'y2', 'class']]
for image_id in image_ids)
detections = (
detection_data.dt.loc[detection_data.dt['image_id'] == image_id]
.to_records(index=False)[['x1', 'y1', 'x2', 'y2', 'class', 'score']]
for image_id in image_ids)
rank_arrays = debobo.evaluate_frames(
groundtruths, detections, iou_thresh=iou_thresh,
max_detections=max_detections)
# make sure mAP score agrees with
y = debobo.mean_average_precision_score(rank_arrays)
np.testing.assert_almost_equal(y, coco_results[idx], decimal=2)
# make sure all classes have a number
classes = set(detection_data.gt['class']).union(detection_data.dt['class'])
assert set(rank_arrays) == classes