From 3a31ea2986f9de12fee0ffe2ae1a930af04f1fca Mon Sep 17 00:00:00 2001 From: SkalskiP Date: Sun, 6 Aug 2023 13:24:51 +0200 Subject: [PATCH] More small changes --- supervision/metrics/detection.py | 16 +++++----------- test/metrics/test_detection.py | 4 ++-- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/supervision/metrics/detection.py b/supervision/metrics/detection.py index 0b29bb07..153da248 100644 --- a/supervision/metrics/detection.py +++ b/supervision/metrics/detection.py @@ -23,12 +23,6 @@ def detections_to_tensor( Returns: (np.ndarray): Detections as numpy tensors as in (xyxy, class_id, confidence) order """ - if len(detections) == 0: - if with_confidence: - return np.zeros((0, 6)) - else: - return np.zeros((0, 5)) - if detections.class_id is None: raise ValueError( "ConfusionMatrix can only be calculated for Detections with class_id" @@ -46,7 +40,7 @@ def detections_to_tensor( return np.concatenate(arrays_to_concat, axis=1) -def _validate_input_tensors(predictions: List[np.ndarray], targets: List[np.ndarray]): +def validate_input_tensors(predictions: List[np.ndarray], targets: List[np.ndarray]): """ Checks for shape consistency of input tensors. """ @@ -221,7 +215,7 @@ class ConfusionMatrix: ]) ``` """ - _validate_input_tensors(predictions, targets) + validate_input_tensors(predictions, targets) num_classes = len(classes) matrix = np.zeros((num_classes + 1, num_classes + 1)) @@ -521,7 +515,7 @@ class MeanAveragePrecision: >>> mean_average_precison.map 0.2899 - ``` + ``` """ prediction_tensors = [] target_tensors = [] @@ -635,7 +629,7 @@ class MeanAveragePrecision: 0.2899 ``` """ - _validate_input_tensors(predictions, targets) + validate_input_tensors(predictions, targets) map, map50, map75 = 0, 0, 0 class_index = 4 @@ -730,7 +724,7 @@ class MeanAveragePrecision: recall (np.ndarray): The recall curve precision (np.ndarray): The precision curve Returns: - (np.ndarray) Average precision, precision curve, recall curve + (np.ndarray): Average precision, precision curve, recall curve """ mrec = np.concatenate(([0.0], recall, [1.0])) mpre = np.concatenate(([1.0], precision, [0.0])) diff --git a/test/metrics/test_detection.py b/test/metrics/test_detection.py index 0ecab3f0..1d4a5740 100644 --- a/test/metrics/test_detection.py +++ b/test/metrics/test_detection.py @@ -5,7 +5,7 @@ import numpy as np import pytest from supervision.detection.core import Detections -from supervision.metrics.detection import ConfusionMatrix +from supervision.metrics.detection import ConfusionMatrix, detections_to_tensor from test.utils import mock_detections CLASSES = np.arange(80) @@ -167,7 +167,7 @@ def test_detections_to_tensor( exception: Exception ): with exception: - result = ConfusionMatrix.detections_to_tensor( + result = detections_to_tensor( detections=detections, with_confidence=with_confidence )