From a27d82a1b8d970857749999677c35af108660591 Mon Sep 17 00:00:00 2001 From: "E. Malagoli" Date: Tue, 9 Apr 2024 23:43:34 +0200 Subject: [PATCH 01/16] Update test_odmetrics.py --- tests/test_odmetrics.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/test_odmetrics.py b/tests/test_odmetrics.py index 4f8c508..06d5c68 100644 --- a/tests/test_odmetrics.py +++ b/tests/test_odmetrics.py @@ -130,10 +130,16 @@ def _test_summary( def test_equivalence(self) -> None: """Test equivalence: `od_metrics.ODMetrics` class and `pycocotools`.""" # Get annotations - y_true_od_metrics = annotations_generator( - **self.annotations_settings["y_true"]) - y_pred_od_metrics = annotations_generator( - **self.annotations_settings["y_pred"], include_score=True) + if getattr(self, "y_true", None): + y_true_od_metrics = self.y_true + else: + y_true_od_metrics = annotations_generator( + **self.annotations_settings["y_true"]) + if getattr(self, "y_pred", None): + y_pred_od_metrics = self.y_pred + else: + y_pred_od_metrics = annotations_generator( + **self.annotations_settings["y_pred"], include_score=True) # max detections: Only used for max_detections_thresholds=None case real_max_detections = ( max(detect["boxes"].shape[0] for detect in y_pred_od_metrics) From eca14e717d597c5656871afe96458db0d5e049a3 Mon Sep 17 00:00:00 2001 From: "E. Malagoli" Date: Tue, 9 Apr 2024 23:45:00 +0200 Subject: [PATCH 02/16] Introduce annotations_tests --- tests/config.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/tests/config.py b/tests/config.py index ff5b0ea..1b4d8ee 100644 --- a/tests/config.py +++ b/tests/config.py @@ -678,11 +678,8 @@ }, ] -misc_tests = [ - { - "compute_settings": {"extended_summary": True}, - "ids": "default_COCO", - }, + +annotations_tests = [ { "compute_settings": {"extended_summary": True}, "annotations_settings": { @@ -700,6 +697,14 @@ "exceptions": {"compute": ValidationError}, "ids": "misc_exception_compute_different_images" }, + ] + + +misc_tests = [ + { + "compute_settings": {"extended_summary": True}, + "ids": "default_COCO", + }, { "compute_settings": {"extended_summary": "yes"}, "exceptions": {"compute": ValidationError}, @@ -717,6 +722,7 @@ + objects_number_tests + objects_size_tests + mean_evaluator_tests + + annotations_tests + misc_tests ) From 9c7eb88385c300bcb4e5b28748aa29a06557d656 Mon Sep 17 00:00:00 2001 From: "E. Malagoli" Date: Tue, 9 Apr 2024 23:49:12 +0200 Subject: [PATCH 03/16] Update config.py --- tests/config.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/tests/config.py b/tests/config.py index 1b4d8ee..8783ccc 100644 --- a/tests/config.py +++ b/tests/config.py @@ -686,7 +686,7 @@ "y_true": {"n_classes": 3}, "y_pred": {"n_classes": 7}, }, - "ids": "misc_default_COCO_different_classes_y_true_y_pred" + "ids": "annotations_exception_different_classes_y_true_y_pred" }, { "compute_settings": {"extended_summary": True}, @@ -695,7 +695,20 @@ "y_pred": {"n_images": 5}, }, "exceptions": {"compute": ValidationError}, - "ids": "misc_exception_compute_different_images" + "ids": "annotations_exception_different_images" + }, + { + "compute_settings": {"extended_summary": True}, + "y_true": [ + {"labels": [0], + "boxes": [[17, 83, 97, 47], [57, 86, 96, 73]]} + ], + "y_pred": [ + {"labels": [0, 2], + "boxes": [[17, 83, 97, 47], [57, 86, 96, 73]], "scores": [.2, .3]} + ], + "exceptions": {"compute": ValidationError}, + "ids": "annotations_exception_different_attributes_length" }, ] From d46b21ce073573eb744bb91990b483f040517c6c Mon Sep 17 00:00:00 2001 From: "E. Malagoli" Date: Wed, 10 Apr 2024 00:04:26 +0200 Subject: [PATCH 04/16] Add new annotations test --- tests/config.py | 18 ++++++++++++++++++ tests/test_odmetrics.py | 11 +++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/tests/config.py b/tests/config.py index 8783ccc..d2b556c 100644 --- a/tests/config.py +++ b/tests/config.py @@ -710,6 +710,20 @@ "exceptions": {"compute": ValidationError}, "ids": "annotations_exception_different_attributes_length" }, + { + "compute_settings": {"extended_summary": True}, + "y_true": [ + {"labels": [0, 2], + "boxes": [[17, 83, 97], [57, 86, 96, 73]]} + ], + "y_pred": [ + {"labels": [0, 2], + "boxes": [[17, 83, 97, 47], [57, 86, 96, 73]], "scores": [.2, .3]} + ], + "exceptions": {"compute": ValidationError}, + "to_cover": {"pycoco_converter": False}, + "ids": "annotations_exception_boxes_length" + }, ] @@ -769,4 +783,8 @@ "exceptions", {} ) + test_tmp["to_cover"] = test_tmp.get( + "to_cover", + {} + ) TESTS.append(test_tmp) diff --git a/tests/test_odmetrics.py b/tests/test_odmetrics.py index 06d5c68..711fd19 100644 --- a/tests/test_odmetrics.py +++ b/tests/test_odmetrics.py @@ -33,6 +33,9 @@ class TestBaseODMetrics(unittest.TestCase): annotations_settings: dict mean_evaluator_settings: dict exceptions: dict + y_true: list | None + y_pred: list | None + to_cover: dict def get_pycoco_params( self, @@ -149,8 +152,12 @@ def test_equivalence(self) -> None: ) # Prepare pycoco annotations - y_true_pycoco = pycoco_converter(y_true_od_metrics) - y_pred_pycoco = pycoco_converter(y_pred_od_metrics) + if self.to_cover.get("pycoco_converter", True): + y_true_pycoco = pycoco_converter(y_true_od_metrics) + y_pred_pycoco = pycoco_converter(y_pred_od_metrics) + else: + y_true_pycoco = None + y_pred_pycoco = None # Run Od_metrics evaluation # Init From 4a8f28fae5f96c4e6432f1c64b88ee531dfe0572 Mon Sep 17 00:00:00 2001 From: "E. Malagoli" Date: Wed, 10 Apr 2024 00:37:48 +0200 Subject: [PATCH 05/16] Add annotation test --- tests/config.py | 12 ++++++++++++ tests/test_odmetrics.py | 16 +++++++--------- tests/utils.py | 35 ++++++++++++++++++++++++++++++++++- 3 files changed, 53 insertions(+), 10 deletions(-) diff --git a/tests/config.py b/tests/config.py index d2b556c..4dac41e 100644 --- a/tests/config.py +++ b/tests/config.py @@ -680,6 +680,18 @@ annotations_tests = [ + { + "compute_settings": {"extended_summary": True}, + "y_true": [ + {"labels": [0, 2], + "boxes": np.array([[17, 83, 97, 47], [57, 86, 96, 73]])} + ], + "y_pred": [ + {"labels": [0, 2], + "boxes": [[17, 83, 97, 47], [57, 86, 96, 73]], "scores": [.2, .3]} + ], + "ids": "annotations_boxes_numpy_array" + }, { "compute_settings": {"extended_summary": True}, "annotations_settings": { diff --git a/tests/test_odmetrics.py b/tests/test_odmetrics.py index 711fd19..6775f2d 100644 --- a/tests/test_odmetrics.py +++ b/tests/test_odmetrics.py @@ -5,13 +5,14 @@ import unittest import copy from typing import Any, Literal +from functools import partial import numpy as np from parameterized import parameterized, parameterized_class from src.od_metrics import ODMetrics, iou from src.od_metrics.constants import DEFAULT_COCO from tests.utils import annotations_generator, pycoco_converter, \ - test_equality, rename_dict, xywh_to + test_equality, rename_dict, xywh_to, apply_function from tests.config import TESTS try: @@ -169,17 +170,14 @@ def test_equivalence(self) -> None: od_metrics_obj = ODMetrics(**self.metrics_settings) return # Box format + convert_fn = partial(xywh_to, box_format=od_metrics_obj.box_format) y_true_od_metrics = [ - ann | { - "boxes": [ - list(xywh_to(box, od_metrics_obj.box_format)) - for box in ann["boxes"]]} for ann in y_true_od_metrics + ann | {"boxes": apply_function(ann["boxes"], convert_fn)} + for ann in y_true_od_metrics ] y_pred_od_metrics = [ - ann | { - "boxes": [ - list(xywh_to(box, od_metrics_obj.box_format)) - for box in ann["boxes"]]} for ann in y_pred_od_metrics + ann | {"boxes": apply_function(ann["boxes"], convert_fn)} + for ann in y_pred_od_metrics ] # Compute diff --git a/tests/utils.py b/tests/utils.py index 8c1d69d..08000ff 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -8,9 +8,10 @@ "test_equality", "rename_dict", "xywh_to", + "apply_function", ] -from typing import Literal +from typing import Literal, Callable import random import numpy as np @@ -332,3 +333,35 @@ def xywh_to( return xywh_cxcywh(bbox) raise ValueError("`box_format` can be `'xyxy'`, `'xywh'`, `'cxcywh'`. " f"Found {box_format}") + + +def apply_function( + x: list | np.ndarray, + func: Callable, + ) -> list | np.ndarray: + """ + Apply a function to every element of a `list` or `np.ndarray`. + + Parameters + ---------- + x : list | np.ndarray + Input data. It can be a `list` or `np.ndarray`. + func : Callable + Function to apply to every element of input `x`. + + Raises + ------ + TypeError + If input is neither a `list` or `np.ndarray`. + + Returns + ------- + list | np.ndarray + Input with function applied to every element of `x`. + """ + if isinstance(x, list): + return [func(elem) for elem in x] + if isinstance(x, np.ndarray): + return np.array([func(elem) for elem in x]) + raise TypeError("Type not supported. Supported types are: `list` or" + f"`np.ndarray`. Found: {type(x)}") From 8b0c2fe43eca087e017f24e1d59bc434d81d6c87 Mon Sep 17 00:00:00 2001 From: "E. Malagoli" Date: Wed, 10 Apr 2024 22:38:05 +0200 Subject: [PATCH 06/16] Add annotations tests --- tests/config.py | 26 ++++++++++++++++++++++++++ tests/test_odmetrics.py | 19 ++++++++++--------- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/tests/config.py b/tests/config.py index 4dac41e..4865225 100644 --- a/tests/config.py +++ b/tests/config.py @@ -736,6 +736,32 @@ "to_cover": {"pycoco_converter": False}, "ids": "annotations_exception_boxes_length" }, + { + "compute_settings": {"extended_summary": True}, + "y_true": [ + {"labels": [0, 2]} + ], + "y_pred": [ + {"labels": [0, 2], + "boxes": [[17, 83, 97, 47], [57, 86, 96, 73]], "scores": [.2, .3]} + ], + "exceptions": {"compute": ValidationError}, + "to_cover": {"pycoco_converter": False, "box_format_converter": False}, + "ids": "annotations_exception_ytrue_no_boxes" + }, + { + "compute_settings": {"extended_summary": True}, + "y_true": [ + {"labels": [0, 2], + "boxes": [[17, 83, 97, 47], [57, 86, 96, 73]]} + ], + "y_pred": [ + {"labels": [0, 2], "scores": [.2, .3]} + ], + "exceptions": {"compute": ValidationError}, + "to_cover": {"pycoco_converter": False, "box_format_converter": False}, + "ids": "annotations_exception_ypred_no_boxes" + }, ] diff --git a/tests/test_odmetrics.py b/tests/test_odmetrics.py index 6775f2d..afc1708 100644 --- a/tests/test_odmetrics.py +++ b/tests/test_odmetrics.py @@ -170,15 +170,16 @@ def test_equivalence(self) -> None: od_metrics_obj = ODMetrics(**self.metrics_settings) return # Box format - convert_fn = partial(xywh_to, box_format=od_metrics_obj.box_format) - y_true_od_metrics = [ - ann | {"boxes": apply_function(ann["boxes"], convert_fn)} - for ann in y_true_od_metrics - ] - y_pred_od_metrics = [ - ann | {"boxes": apply_function(ann["boxes"], convert_fn)} - for ann in y_pred_od_metrics - ] + if self.to_cover.get("box_format_converter", True): + convert_fn = partial(xywh_to, box_format=od_metrics_obj.box_format) + y_true_od_metrics = [ + ann | {"boxes": apply_function(ann["boxes"], convert_fn)} + for ann in y_true_od_metrics + ] + y_pred_od_metrics = [ + ann | {"boxes": apply_function(ann["boxes"], convert_fn)} + for ann in y_pred_od_metrics + ] # Compute _compute_exception = self.exceptions.get("compute", None) From 96ca4a4f5bc610e84a0eac234149824b5ea21b90 Mon Sep 17 00:00:00 2001 From: "E. Malagoli" Date: Wed, 10 Apr 2024 22:42:29 +0200 Subject: [PATCH 07/16] Add annotations test --- tests/config.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/config.py b/tests/config.py index 4865225..31e4111 100644 --- a/tests/config.py +++ b/tests/config.py @@ -692,6 +692,20 @@ ], "ids": "annotations_boxes_numpy_array" }, + { + "compute_settings": {"extended_summary": True}, + "y_true": [ + {"labels": [0, 2], + "boxes": np.array([[17, 83, 97, 47], [57, 86, 96, 73]]), + "area": np.array([4559, 7008]), + } + ], + "y_pred": [ + {"labels": [0, 2], + "boxes": [[17, 83, 97, 47], [57, 86, 96, 73]], "scores": [.2, .3]} + ], + "ids": "annotations_area_numpy_array" + }, { "compute_settings": {"extended_summary": True}, "annotations_settings": { From 8af6a4196a148c80ed4c6bd361a8a048c3a5c752 Mon Sep 17 00:00:00 2001 From: "E. Malagoli" Date: Wed, 10 Apr 2024 22:48:00 +0200 Subject: [PATCH 08/16] Add cover exceptions for validators.py --- src/od_metrics/validators.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/od_metrics/validators.py b/src/od_metrics/validators.py index efb0f56..fca0e38 100644 --- a/src/od_metrics/validators.py +++ b/src/od_metrics/validators.py @@ -227,8 +227,8 @@ def iou_recall_validator( or "default_value" not in info.context or info.field_name is None ): - raise ValueError("Missing required context or field name " - "information.") + raise ValueError( # pragma: no cover + "Missing required context or field name information.") return _common_validator( name=info.field_name, @@ -271,8 +271,8 @@ def max_detection_validator( or "default_value" not in info.context or info.field_name is None ): - raise ValueError("Missing required context or field name " - "information.") + raise ValueError( # pragma: no cover + "Missing required context or field name information.") return _common_validator( name=info.field_name, @@ -315,8 +315,8 @@ def area_ranges_validator( or "default_value" not in info.context or info.field_name is None ): - raise ValueError("Missing required context or field name " - "information.") + raise ValueError( # pragma: no cover + "Missing required context or field name information.") return _area_ranges_validator( name=info.field_name, @@ -680,8 +680,8 @@ def annotation_parser( Ground truth or predictions annotations. """ if info.context is None or "box_format" not in info.context: - raise ValueError("Missing required context or `box_format` " - "information.") + raise ValueError( # pragma: no cover + "Missing required context or `box_format` information.") box_format = info.context["box_format"] # y_true @@ -750,8 +750,8 @@ def iou_threshold_validator( or "default_value" not in info.context or info.field_name is None ): - raise ValueError("Missing required context or field name " - "information.") + raise ValueError( # pragma: no cover + "Missing required context or field name information.") return _common_validator( name=info.field_name, @@ -789,8 +789,8 @@ def area_range_key_validator( or "default_value" not in info.context or info.field_name is None ): - raise ValueError("Missing required context or field name " - "information.") + raise ValueError( # pragma: no cover + "Missing required context or field name information.") return _common_validator( name=info.field_name, @@ -828,8 +828,8 @@ def max_detection_label_id_validator( or "default_value" not in info.context or info.field_name is None ): - raise ValueError("Missing required context or field name " - "information.") + raise ValueError( # pragma: no cover + "Missing required context or field name information.") return _common_validator( name=info.field_name, From f7e2c0b59a8320d73694780171db5eb4d8d294c0 Mon Sep 17 00:00:00 2001 From: "E. Malagoli" Date: Wed, 10 Apr 2024 22:53:52 +0200 Subject: [PATCH 09/16] Update utils.py --- src/od_metrics/utils.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/od_metrics/utils.py b/src/od_metrics/utils.py index 202e5d1..cbdd414 100644 --- a/src/od_metrics/utils.py +++ b/src/od_metrics/utils.py @@ -145,8 +145,10 @@ def to_xywh( return xyxy_xywh(bbox) if box_format == "cxcywh": return cxcywh_xywh(bbox) - raise ValueError("`box_format` can be `'xyxy'`, `'xywh'`, `'cxcywh'`. " - f"Found {box_format}") + raise ValueError( # pragma: no cover + "`box_format` can be `'xyxy'`, `'xywh'`, `'cxcywh'`. " + f"Found {box_format}" + ) def get_suffix( From fee9f90289ac61681f6c089e46ab7efdc38c1ddb Mon Sep 17 00:00:00 2001 From: "E. Malagoli" Date: Wed, 10 Apr 2024 23:35:35 +0200 Subject: [PATCH 10/16] Clean to_array function --- src/od_metrics/od_metrics.py | 6 +++--- src/od_metrics/utils.py | 29 +---------------------------- 2 files changed, 4 insertions(+), 31 deletions(-) diff --git a/src/od_metrics/od_metrics.py b/src/od_metrics/od_metrics.py index 9051eb9..76d7231 100644 --- a/src/od_metrics/od_metrics.py +++ b/src/od_metrics/od_metrics.py @@ -16,7 +16,7 @@ import numpy as np from .constants import DEFAULT_COCO, _STANDARD_OUTPUT -from .utils import to_array, get_indexes, get_suffix, _Missing +from .utils import get_indexes, get_suffix, _Missing from .validators import ConstructorModel, ComputeModel, MeanModel @@ -899,8 +899,8 @@ def _get_mean( # Default default_value = { "iou_threshold": self.iou_thresholds, - "label_id": to_array(label_ids), - "area_range_key": to_array(list(self.area_ranges.keys())), + "label_id": np.array(label_ids), + "area_range_key": np.array(list(self.area_ranges.keys())), "max_detection_threshold": self.max_detection_thresholds, } diff --git a/src/od_metrics/utils.py b/src/od_metrics/utils.py index cbdd414..6882b3a 100644 --- a/src/od_metrics/utils.py +++ b/src/od_metrics/utils.py @@ -4,12 +4,11 @@ __all__ = [ "_Missing", - "to_array", "get_indexes", "get_suffix", ] -from typing import Literal, Any +from typing import Literal import numpy as np @@ -17,32 +16,6 @@ class _Missing: """Sentinel class for missing values.""" -def to_array( - input_: Any, - ) -> np.ndarray: - """ - Trasform input to `np.ndarray`. - - Parameters - ---------- - input_ : Any | None, optional - Input to be converted. - - Returns - ------- - np.ndarray - Input converted to `np.ndarray`. - """ - if not isinstance(input_, np.ndarray): - output = np.array(input_) - else: - output = input_ - - if output.ndim == 0: - output = output.reshape(-1) - return output - - def get_indexes( array1: np.ndarray, array2: np.ndarray From b1988130877eb8a8af98f321153056aece085c1e Mon Sep 17 00:00:00 2001 From: "E. Malagoli" Date: Wed, 10 Apr 2024 23:38:47 +0200 Subject: [PATCH 11/16] Update test_odmetrics.py --- tests/test_odmetrics.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/test_odmetrics.py b/tests/test_odmetrics.py index afc1708..a34d108 100644 --- a/tests/test_odmetrics.py +++ b/tests/test_odmetrics.py @@ -20,9 +20,11 @@ from pycocotools import mask as maskUtils from pycocotools.coco import COCO from pycocotools.cocoeval import COCOeval -except ImportError: - print("This unittest needs `pycocotools`. Please intall by " - "running `pip install pycocotools`") +except ImportError: # pragma: no cover + print( # pragma: no cover + "This unittest needs `pycocotools`. Please intall by " + "running `pip install pycocotools`" + ) @parameterized_class(TESTS) From f3d508f3316aab23cb40954b093fd4541fe5eaa1 Mon Sep 17 00:00:00 2001 From: "E. Malagoli" Date: Wed, 10 Apr 2024 23:42:26 +0200 Subject: [PATCH 12/16] Update utils.py --- tests/utils.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/utils.py b/tests/utils.py index 08000ff..3a21f0f 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -363,5 +363,7 @@ def apply_function( return [func(elem) for elem in x] if isinstance(x, np.ndarray): return np.array([func(elem) for elem in x]) - raise TypeError("Type not supported. Supported types are: `list` or" - f"`np.ndarray`. Found: {type(x)}") + raise TypeError( # pragma: no cover + "Type not supported. Supported types are: `list` or" + f"`np.ndarray`. Found: {type(x)}" + ) From 076ecc1e7d4ac2557831300ba294de9aaabca789 Mon Sep 17 00:00:00 2001 From: "E. Malagoli" Date: Wed, 10 Apr 2024 23:49:35 +0200 Subject: [PATCH 13/16] Update utils.py --- tests/utils.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/utils.py b/tests/utils.py index 3a21f0f..7fa719d 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -331,8 +331,10 @@ def xywh_to( return xywh_xyxy(bbox) if box_format == "cxcywh": return xywh_cxcywh(bbox) - raise ValueError("`box_format` can be `'xyxy'`, `'xywh'`, `'cxcywh'`. " - f"Found {box_format}") + raise ValueError( # pragma: no cover + "`box_format` can be `'xyxy'`, `'xywh'`, `'cxcywh'`. " + f"Found {box_format}" + ) def apply_function( From f06dd77a5ab8fe2afffb966763b5fc158f3c9f1b Mon Sep 17 00:00:00 2001 From: "E. Malagoli" Date: Wed, 10 Apr 2024 23:52:34 +0200 Subject: [PATCH 14/16] Update utils.py --- tests/utils.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/utils.py b/tests/utils.py index 7fa719d..fc13e95 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -221,11 +221,11 @@ def test_equality( "length.") for el1, el2 in zip(input1, input2): - checks.append(test_equality(el1, el2)) - else: - checks.append(input1 == input2) - except AssertionError: - checks = [False] + checks.append(test_equality(el1, el2)) # pragma: no cover + else: # pragma: no cover + checks.append(input1 == input2) # pragma: no cover + except AssertionError: # pragma: no cover + checks = [False] # pragma: no cover return all(checks) From f3c369812fe33b981fd09f2da520be5d7395b01e Mon Sep 17 00:00:00 2001 From: "E. Malagoli" Date: Wed, 10 Apr 2024 23:56:00 +0200 Subject: [PATCH 15/16] Update utils.py --- tests/utils.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/tests/utils.py b/tests/utils.py index fc13e95..3339e04 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -200,12 +200,13 @@ def test_equality( """ try: if isinstance(input1, np.int64): - input1 = int(input1) + input1 = int(input1) # pragma: no cover if isinstance(input2, np.int64): - input2 = int(input2) + input2 = int(input2) # pragma: no cover if not isinstance(input1, type(input2)): - raise ValueError(f"Found: {type(input1)} and {type(input2)}") + raise ValueError( # pragma: no cover + f"Found: {type(input1)} and {type(input2)}") checks = [] if isinstance(input1, np.ndarray) and isinstance(input2, np.ndarray): @@ -222,10 +223,10 @@ def test_equality( for el1, el2 in zip(input1, input2): checks.append(test_equality(el1, el2)) # pragma: no cover - else: # pragma: no cover - checks.append(input1 == input2) # pragma: no cover - except AssertionError: # pragma: no cover - checks = [False] # pragma: no cover + else: # pragma: no cover + checks.append(input1 == input2) # pragma: no cover + except AssertionError: # pragma: no cover + checks = [False] # pragma: no cover return all(checks) From 5c971a6309079da2f46768e160a55a0f75cfe7b2 Mon Sep 17 00:00:00 2001 From: "E. Malagoli" Date: Thu, 11 Apr 2024 00:00:26 +0200 Subject: [PATCH 16/16] Update test_odmetrics.py --- tests/test_odmetrics.py | 61 +++++++++++------------------------------ 1 file changed, 16 insertions(+), 45 deletions(-) diff --git a/tests/test_odmetrics.py b/tests/test_odmetrics.py index a34d108..d118d79 100644 --- a/tests/test_odmetrics.py +++ b/tests/test_odmetrics.py @@ -222,58 +222,29 @@ def test_equivalence(self) -> None: pycoco_obj.summarize() # Test IoUs equivalence - _iou_excpetion = self.exceptions.get("iou", None) - if _iou_excpetion is None: - with self.subTest("Test IoU"): - self.assertTrue(self._test_ious( - od_metrics_ious=od_metrics_output["IoU"], - pycoco_ious=pycoco_obj.ious - ) + with self.subTest("Test IoU"): + self.assertTrue(self._test_ious( + od_metrics_ious=od_metrics_output["IoU"], + pycoco_ious=pycoco_obj.ious ) - else: - with self.assertRaises(_iou_excpetion): - with self.subTest("Test IoU"): - self._test_ious( - od_metrics_ious=od_metrics_output["IoU"], - pycoco_ious=pycoco_obj.ious - ) - return + ) # Test aggregate equivalence - _aggregate_exception = self.exceptions.get("aggregate", None) - if _aggregate_exception is None: - with self.subTest("Test aggregate"): - self.assertTrue(self._test_aggregate( - od_metrics_output=od_metrics_output, - pycoco_eval=pycoco_obj.eval - ) + with self.subTest("Test aggregate"): + self.assertTrue(self._test_aggregate( + od_metrics_output=od_metrics_output, + pycoco_eval=pycoco_obj.eval ) - else: - with self.assertRaises(_aggregate_exception): - self._test_aggregate( - od_metrics_output=od_metrics_output, - pycoco_eval=pycoco_obj.eval - ) - return + ) # Test summary equivalence - _summarize_exception = self.exceptions.get("summarize", None) - if _summarize_exception is None: - with self.subTest("Test summarize"): - self.assertTrue(self._test_summary( - od_metrics_output=od_metrics_output, - pycoco_stats=pycoco_obj.stats, - is_default_coco=is_default_coco, - ) + with self.subTest("Test summarize"): + self.assertTrue(self._test_summary( + od_metrics_output=od_metrics_output, + pycoco_stats=pycoco_obj.stats, + is_default_coco=is_default_coco, ) - else: - with self.assertRaises(_summarize_exception): - self._test_summary( - od_metrics_output=od_metrics_output, - pycoco_stats=pycoco_obj.stats, - is_default_coco=is_default_coco, - ) - return + ) # Test mean evalautor _mean_evaluator_exception = self.exceptions.get("mean_evaluator", None)