From d480ff5be22d2c125bbb6883fcdf62a3030055d6 Mon Sep 17 00:00:00 2001 From: kirilllzaitsev Date: Fri, 7 Jul 2023 22:34:23 +0200 Subject: [PATCH] add test_evaluate_detection_batch --- test/metrics/test_detection.py | 41 ++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/test/metrics/test_detection.py b/test/metrics/test_detection.py index 4055bd42..00559638 100644 --- a/test/metrics/test_detection.py +++ b/test/metrics/test_detection.py @@ -39,6 +39,7 @@ for class_id, count in zip(*np.unique(PREDICTIONS[:, 5], return_counts=True)): IDEAL_RESULT[class_id, class_id] = count classes = np.arange(80) +num_classes = len(classes) @pytest.mark.parametrize( @@ -77,8 +78,40 @@ def test_from_detections( assert np.array_equal(result.matrix, expected_result) -def test_evaluate_detection_batch(): - ... +@pytest.mark.parametrize( + "predictions, targets, num_classes, conf_threshold, iou_threshold, expected_result, exception", + [ + ( + CERTAIN_DETECTIONS, + DETECTIONS, + num_classes, + 0.3, + 0.5, + IDEAL_RESULT, + DoesNotRaise(), + ) + ], +) +def test_evaluate_detection_batch( + predictions, + targets, + num_classes, + conf_threshold, + iou_threshold, + expected_result: Optional[np.ndarray], + exception: Exception, +): + with exception: + result = ConfusionMatrix._evaluate_detection_batch( + true_detections=targets, + pred_detections=predictions, + num_classes=num_classes, + conf_threshold=conf_threshold, + iou_threshold=iou_threshold, + ) + + assert result.diagonal().sum() == result.sum() + assert np.array_equal(result, expected_result) def test_drop_extra_matches(): @@ -87,3 +120,7 @@ def test_drop_extra_matches(): def test_benchmark(): ... + + +def test_from_matrix(): + ...