Skip to content

Commit 3b20f6b

Browse files
committed
code coverage
1 parent 556154a commit 3b20f6b

9 files changed

Lines changed: 56 additions & 26 deletions

File tree

src/valor_lite/cache/compute.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def paginate_index(
167167
"""
168168
Iterate through a paginated cache reader.
169169
170-
Note this function expects unqiue keys to be fragment-aligned and in ascending order.
170+
Note this function expects unqiue keys to be fragment-aligned.
171171
"""
172172
total = source.count_rows()
173173
limit = limit if limit else total
@@ -185,6 +185,7 @@ def paginate_index(
185185
if tbl.num_rows == 0:
186186
continue
187187

188+
# sort the unique keys as they may be out of order
188189
unique_values = pc.unique(tbl[column_key]).sort() # type: ignore[reportAttributeAccessIssue]
189190
n_unique = len(unique_values)
190191
prev_idx = curr_idx

tests/object_detection/conftest.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ def basic_detections(
377377

378378

379379
@pytest.fixture
380-
def torchmetrics_detections(loader: Loader) -> Evaluator:
380+
def torchmetrics_detections() -> list[Detection[BoundingBox]]:
381381
"""Creates a model called "test_model" with some predicted
382382
detections on the dataset "test_dataset". These predictions are taken
383383
from a torchmetrics unit test (see test_metrics.py)
@@ -520,7 +520,14 @@ def torchmetrics_detections(loader: Loader) -> Evaluator:
520520
)
521521
for idx, (gt, pd) in enumerate(zip(groundtruths, predictions))
522522
]
523-
loader.add_bounding_boxes(detections)
523+
return detections
524+
525+
526+
@pytest.fixture
527+
def torchmetrics_evaluator(
528+
loader: Loader, torchmetrics_detections: list[Detection[BoundingBox]]
529+
) -> Evaluator:
530+
loader.add_bounding_boxes(torchmetrics_detections)
524531
return loader.finalize()
525532

526533

tests/object_detection/test_average_precision.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,12 +249,12 @@ def test_ap_basic_detections(basic_detections: Evaluator):
249249
assert m in actual_metrics
250250

251251

252-
def test_ap_using_torch_metrics_example(torchmetrics_detections: Evaluator):
252+
def test_ap_using_torch_metrics_example(torchmetrics_evaluator: Evaluator):
253253
"""
254254
cf with torch metrics/pycocotools results listed here:
255255
https://github.com/Lightning-AI/metrics/blob/107dbfd5fb158b7ae6d76281df44bd94c836bfce/tests/unittests/detection/test_map.py#L231
256256
"""
257-
evaluator = torchmetrics_detections
257+
evaluator = torchmetrics_evaluator
258258
assert evaluator.info.number_of_datums == 4
259259
assert evaluator.info.number_of_labels == 6
260260
assert evaluator.info.number_of_groundtruth_annotations == 20

tests/object_detection/test_average_recall.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,12 @@ def test_ar_metrics_second_class(basic_detections_second_class: Evaluator):
205205
assert m in actual_metrics
206206

207207

208-
def test_ar_using_torch_metrics_example(torchmetrics_detections: Evaluator):
208+
def test_ar_using_torch_metrics_example(torchmetrics_evaluator: Evaluator):
209209
"""
210210
cf with torch metrics/pycocotools results listed here:
211211
https://github.com/Lightning-AI/metrics/blob/107dbfd5fb158b7ae6d76281df44bd94c836bfce/tests/unittests/detection/test_map.py#L231
212212
"""
213-
evaluator = torchmetrics_detections
213+
evaluator = torchmetrics_evaluator
214214

215215
assert evaluator.info.number_of_datums == 4
216216
assert evaluator.info.number_of_labels == 6

tests/object_detection/test_confusion_matrix.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,13 +322,13 @@ def test_confusion_matrix(detections_for_detailed_counting: Evaluator):
322322

323323

324324
def test_confusion_matrix_using_torch_metrics_example(
325-
torchmetrics_detections: Evaluator,
325+
torchmetrics_evaluator: Evaluator,
326326
):
327327
"""
328328
cf with torch metrics/pycocotools results listed here:
329329
https://github.com/Lightning-AI/metrics/blob/107dbfd5fb158b7ae6d76281df44bd94c836bfce/tests/unittests/detection/test_map.py#L231
330330
"""
331-
evaluator = torchmetrics_detections
331+
evaluator = torchmetrics_evaluator
332332
assert evaluator.info.number_of_datums == 4
333333
assert evaluator.info.number_of_labels == 6
334334
assert evaluator.info.number_of_groundtruth_annotations == 20

tests/object_detection/test_confusion_matrix_with_examples.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -838,13 +838,13 @@ def _filter_out_examples_and_zero_counts(cm: dict, hl: dict, mp: dict):
838838

839839

840840
def test_confusion_matrix_with_examples_using_torch_metrics_example(
841-
torchmetrics_detections: Evaluator,
841+
torchmetrics_evaluator: Evaluator,
842842
):
843843
"""
844844
cf with torch metrics/pycocotools results listed here:
845845
https://github.com/Lightning-AI/metrics/blob/107dbfd5fb158b7ae6d76281df44bd94c836bfce/tests/unittests/detection/test_map.py#L231
846846
"""
847-
evaluator = torchmetrics_detections
847+
evaluator = torchmetrics_evaluator
848848
assert evaluator.info.number_of_datums == 4
849849
assert evaluator.info.number_of_labels == 6
850850
assert evaluator.info.number_of_groundtruth_annotations == 20

tests/object_detection/test_evaluator.py

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@
44
import numpy as np
55
import 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

1017
def 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

5762
def 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)

tests/object_detection/test_examples.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,13 +283,13 @@ def test_examples(detections_for_detailed_counting: Evaluator):
283283

284284

285285
def test_examples_using_torch_metrics_example(
286-
torchmetrics_detections: Evaluator,
286+
torchmetrics_evaluator: Evaluator,
287287
):
288288
"""
289289
cf with torch metrics/pycocotools results listed here:
290290
https://github.com/Lightning-AI/metrics/blob/107dbfd5fb158b7ae6d76281df44bd94c836bfce/tests/unittests/detection/test_map.py#L231
291291
"""
292-
evaluator = torchmetrics_detections
292+
evaluator = torchmetrics_evaluator
293293
assert evaluator.info.number_of_datums == 4
294294
assert evaluator.info.number_of_labels == 6
295295
assert evaluator.info.number_of_groundtruth_annotations == 20
@@ -1079,13 +1079,13 @@ def test_examples_ranked_pair_ordering(
10791079

10801080

10811081
def test_examples_using_torch_metrics_example_paginated(
1082-
torchmetrics_detections: Evaluator,
1082+
torchmetrics_evaluator: Evaluator,
10831083
):
10841084
"""
10851085
cf with torch metrics/pycocotools results listed here:
10861086
https://github.com/Lightning-AI/metrics/blob/107dbfd5fb158b7ae6d76281df44bd94c836bfce/tests/unittests/detection/test_map.py#L231
10871087
"""
1088-
evaluator = torchmetrics_detections
1088+
evaluator = torchmetrics_evaluator
10891089
assert evaluator.info.number_of_datums == 4
10901090
assert evaluator.info.number_of_labels == 6
10911091
assert evaluator.info.number_of_groundtruth_annotations == 20

tests/object_detection/test_pr_curve.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33

44
def test_pr_curve_using_torch_metrics_example(
5-
torchmetrics_detections: Evaluator,
5+
torchmetrics_evaluator: Evaluator,
66
):
77
"""
88
cf with torch metrics/pycocotools results listed here:
99
https://github.com/Lightning-AI/metrics/blob/107dbfd5fb158b7ae6d76281df44bd94c836bfce/tests/unittests/detection/test_map.py#L231
1010
"""
11-
evaluator = torchmetrics_detections
11+
evaluator = torchmetrics_evaluator
1212
assert evaluator.info.number_of_datums == 4
1313
assert evaluator.info.number_of_labels == 6
1414
assert evaluator.info.number_of_groundtruth_annotations == 20

0 commit comments

Comments
 (0)