44import numpy as np
55import pytest
66
7- from valor_lite .object_detection import Evaluator , Metric , MetricType
7+ from valor_lite .object_detection import (
8+ BoundingBox ,
9+ Detection ,
10+ Evaluator ,
11+ Loader ,
12+ Metric ,
13+ MetricType ,
14+ )
815
916
1017def test_evaluator_file_not_found (tmp_path : Path ):
@@ -21,7 +28,7 @@ def test_evaluator_not_a_directory(tmp_path: Path):
2128 Evaluator .load (filepath )
2229
2330
24- def test_evaluator_valid_thresholds (tmp_path : Path ):
31+ def test_evaluator_valid_thresholds ():
2532 eval = Evaluator (
2633 detailed_reader = None , # type: ignore - testing
2734 ranked_reader = None , # type: ignore - testing
@@ -41,17 +48,15 @@ def test_evaluator_valid_thresholds(tmp_path: Path):
4148 assert "score" in str (e )
4249
4350
44- def test_info_using_torch_metrics_example (torchmetrics_detections : Evaluator ):
51+ def test_info_using_torch_metrics_example (torchmetrics_evaluator : Evaluator ):
4552 """
4653 cf with torch metrics/pycocotools results listed here:
4754 https://github.com/Lightning-AI/metrics/blob/107dbfd5fb158b7ae6d76281df44bd94c836bfce/tests/unittests/detection/test_map.py#L231
4855 """
49- evaluator = torchmetrics_detections
50-
51- assert evaluator .info .number_of_datums == 4
52- assert evaluator .info .number_of_labels == 6
53- assert evaluator .info .number_of_groundtruth_annotations == 20
54- assert evaluator .info .number_of_prediction_annotations == 19
56+ assert torchmetrics_evaluator .info .number_of_datums == 4
57+ assert torchmetrics_evaluator .info .number_of_labels == 6
58+ assert torchmetrics_evaluator .info .number_of_groundtruth_annotations == 20
59+ assert torchmetrics_evaluator .info .number_of_prediction_annotations == 19
5560
5661
5762def test_no_thresholds (detection_ranked_pair_ordering : Evaluator ):
@@ -177,3 +182,20 @@ def test_output_types_dont_contain_numpy(basic_detections: Evaluator):
177182 for value in values :
178183 if isinstance (value , (np .generic , np .ndarray )):
179184 raise TypeError (f"Value `{ value } ` has type `{ type (value )} `." )
185+
186+
187+ def test_evaluator_loading_using_torch_metrics_example (
188+ tmp_path : Path , torchmetrics_detections : list [Detection [BoundingBox ]]
189+ ):
190+ loader = Loader .persistent (path = tmp_path )
191+ loader .add_bounding_boxes (torchmetrics_detections )
192+ original_evaluator = loader .finalize ()
193+ loaded_evaluator = Evaluator .load (path = tmp_path )
194+
195+ kwargs = dict (
196+ score_thresholds = [0.25 , 0.5 , 0.75 , 0.9 ],
197+ iou_thresholds = [0.1 , 0.25 , 0.5 , 0.75 ],
198+ )
199+ assert original_evaluator .compute_precision_recall (
200+ ** kwargs
201+ ) == loaded_evaluator .compute_precision_recall (** kwargs )
0 commit comments