From 2f88bb2b8e44b1e02f5a1202f4917470d22216e9 Mon Sep 17 00:00:00 2001 From: LinasKo Date: Thu, 20 Jun 2024 13:34:30 +0300 Subject: [PATCH 01/12] Add Florence 2 support --- supervision/detection/core.py | 24 +++++++++-- supervision/detection/lmm.py | 78 +++++++++++++++++++++++++++++++++-- 2 files changed, 96 insertions(+), 6 deletions(-) diff --git a/supervision/detection/core.py b/supervision/detection/core.py index 37dde153..d31e07bd 100644 --- a/supervision/detection/core.py +++ b/supervision/detection/core.py @@ -7,7 +7,12 @@ from typing import Any, Dict, Iterator, List, Optional, Tuple, Union import numpy as np from supervision.config import CLASS_NAME_DATA_FIELD, ORIENTED_BOX_COORDINATES -from supervision.detection.lmm import LMM, from_paligemma, validate_lmm_and_kwargs +from supervision.detection.lmm import ( + LMM, + from_florence_2, + from_paligemma, + validate_lmm_parameters, +) from supervision.detection.overlap_filter import ( box_non_max_merge, box_non_max_suppression, @@ -811,7 +816,9 @@ class Detections: ) @classmethod - def from_lmm(cls, lmm: Union[LMM, str], result: str, **kwargs) -> Detections: + def from_lmm( + cls, lmm: Union[LMM, str], result: Union[str, dict], **kwargs + ) -> Detections: """ Creates a Detections object from the given result string based on the specified Large Multimodal Model (LMM). @@ -847,13 +854,24 @@ class Detections: # array([0]) ``` """ - lmm = validate_lmm_and_kwargs(lmm, kwargs) + lmm = validate_lmm_parameters(lmm, result, kwargs) if lmm == LMM.PALIGEMMA: + assert isinstance(result, str) xyxy, class_id, class_name = from_paligemma(result, **kwargs) data = {CLASS_NAME_DATA_FIELD: class_name} return cls(xyxy=xyxy, class_id=class_id, data=data) + if lmm == LMM.FLORENCE_2: + assert isinstance(result, dict) + xyxy, labels, xyxyxyxy = from_florence_2(result, **kwargs) + data = {} + if labels is not None: + data[CLASS_NAME_DATA_FIELD] = labels + if xyxyxyxy is not None: + data[ORIENTED_BOX_COORDINATES] = xyxyxyxy + return cls(xyxy=xyxy, data=data) + raise ValueError(f"Unsupported LMM: {lmm}") @classmethod diff --git a/supervision/detection/lmm.py b/supervision/detection/lmm.py index 5f61db0a..910ca30c 100644 --- a/supervision/detection/lmm.py +++ b/supervision/detection/lmm.py @@ -4,17 +4,38 @@ from typing import Any, Dict, List, Optional, Tuple, Union import numpy as np +from supervision.detection.utils import polygon_to_xyxy + class LMM(Enum): PALIGEMMA = "paligemma" + FLORENCE_2 = "florence_2" -REQUIRED_ARGUMENTS: Dict[LMM, List[str]] = {LMM.PALIGEMMA: ["resolution_wh"]} +RESULT_TYPES: Dict[LMM, type] = {LMM.PALIGEMMA: str, LMM.FLORENCE_2: dict} -ALLOWED_ARGUMENTS: Dict[LMM, List[str]] = {LMM.PALIGEMMA: ["resolution_wh", "classes"]} +REQUIRED_ARGUMENTS: Dict[LMM, List[str]] = { + LMM.PALIGEMMA: ["resolution_wh"], + LMM.FLORENCE_2: [], +} + +ALLOWED_ARGUMENTS: Dict[LMM, List[str]] = { + LMM.PALIGEMMA: ["resolution_wh", "classes"], + LMM.FLORENCE_2: [], +} + +SUPPORTED_TASKS_FLORENCE_2 = [ + "", + "", + "", + "", + "", +] -def validate_lmm_and_kwargs(lmm: Union[LMM, str], kwargs: Dict[str, Any]) -> LMM: +def validate_lmm_parameters( + lmm: Union[LMM, str], result: Any, kwargs: Dict[str, Any] +) -> LMM: if isinstance(lmm, str): try: lmm = LMM(lmm.lower()) @@ -23,6 +44,11 @@ def validate_lmm_and_kwargs(lmm: Union[LMM, str], kwargs: Dict[str, Any]) -> LMM f"Invalid lmm value: {lmm}. Must be one of {[e.value for e in LMM]}" ) + if not isinstance(result, RESULT_TYPES[lmm]): + raise ValueError( + f"Invalid LMM result type: {type(result)}. Must be {RESULT_TYPES[lmm]}" + ) + required_args = REQUIRED_ARGUMENTS.get(lmm, []) for arg in required_args: if arg not in kwargs: @@ -57,3 +83,49 @@ def from_paligemma( class_id = np.array([classes.index(name) for name in class_name]) return xyxy, class_id, class_name + + +def from_florence_2( + result: dict, +) -> Tuple[np.ndarray, Optional[np.ndarray], Optional[np.ndarray]]: + """ + Parse results from the Florence 2 multi-model model. + https://huggingface.co/microsoft/Florence-2-large + + Parameters: + result: dict containing the model output + + Returns: + xyxy (np.ndarray): An array of shape `(n, 4)` containing + the bounding boxes coordinates in format `[x1, y1, x2, y2]` + labels: (Optional[np.ndarray]): An array of shape `(n,)` containing + the class labels for each bounding box + obb_boxes: (Optional[np.ndarray]): An array of shape `(n, 4, 2)` containing + oriented bounding boxes. + """ + for task in ["", "", ""]: + if task in result: + result = result[task] + xyxy = np.array(result["bboxes"], dtype=np.float32) + labels = np.array(result["labels"]) + return xyxy, labels, None + + if "" in result: + result = result[""] + xyxy = np.array(result["bboxes"], dtype=np.float32) + # provides labels, but they are ["", "", "", ...] + return xyxy, None, None + + if "" in result: + result = result[""] + xyxyxyxy = np.array(result["quad_boxes"], dtype=np.float32) + xyxyxyxy = xyxyxyxy.reshape(-1, 4, 2) + xyxy = np.array([polygon_to_xyxy(polygon) for polygon in xyxyxyxy]) + + labels = np.array(result["labels"]) + return xyxy, labels, xyxyxyxy + + task = list(result.keys())[0] + raise NotImplementedError( + f"{task} task not supported. Supported tasks are: {SUPPORTED_TASKS_FLORENCE_2}" + ) From 04c5f18da09d076183ba4e678ab4b5fcbad7c321 Mon Sep 17 00:00:00 2001 From: LinasKo Date: Thu, 20 Jun 2024 15:49:13 +0300 Subject: [PATCH 02/12] Bugfix: florence 2, handle case with no detections --- supervision/detection/core.py | 3 +++ supervision/detection/lmm.py | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/supervision/detection/core.py b/supervision/detection/core.py index d31e07bd..da90cb10 100644 --- a/supervision/detection/core.py +++ b/supervision/detection/core.py @@ -865,6 +865,9 @@ class Detections: if lmm == LMM.FLORENCE_2: assert isinstance(result, dict) xyxy, labels, xyxyxyxy = from_florence_2(result, **kwargs) + if len(xyxy) == 0: + return cls.empty() + data = {} if labels is not None: data[CLASS_NAME_DATA_FIELD] = labels diff --git a/supervision/detection/lmm.py b/supervision/detection/lmm.py index 910ca30c..e70170ab 100644 --- a/supervision/detection/lmm.py +++ b/supervision/detection/lmm.py @@ -121,7 +121,6 @@ def from_florence_2( xyxyxyxy = np.array(result["quad_boxes"], dtype=np.float32) xyxyxyxy = xyxyxyxy.reshape(-1, 4, 2) xyxy = np.array([polygon_to_xyxy(polygon) for polygon in xyxyxyxy]) - labels = np.array(result["labels"]) return xyxy, labels, xyxyxyxy From bb513f880adc7ee8b4d8a3df6d03a78d451d535b Mon Sep 17 00:00:00 2001 From: LinasKo Date: Thu, 20 Jun 2024 20:41:23 +0300 Subject: [PATCH 03/12] Add segmentation and region methods --- supervision/detection/core.py | 5 ++- supervision/detection/lmm.py | 82 ++++++++++++++++++++++++++++++----- 2 files changed, 73 insertions(+), 14 deletions(-) diff --git a/supervision/detection/core.py b/supervision/detection/core.py index da90cb10..4d913e1b 100644 --- a/supervision/detection/core.py +++ b/supervision/detection/core.py @@ -864,7 +864,7 @@ class Detections: if lmm == LMM.FLORENCE_2: assert isinstance(result, dict) - xyxy, labels, xyxyxyxy = from_florence_2(result, **kwargs) + xyxy, labels, mask, xyxyxyxy = from_florence_2(result, **kwargs) if len(xyxy) == 0: return cls.empty() @@ -873,7 +873,8 @@ class Detections: data[CLASS_NAME_DATA_FIELD] = labels if xyxyxyxy is not None: data[ORIENTED_BOX_COORDINATES] = xyxyxyxy - return cls(xyxy=xyxy, data=data) + + return cls(xyxy=xyxy, mask=mask, data=data) raise ValueError(f"Unsupported LMM: {lmm}") diff --git a/supervision/detection/lmm.py b/supervision/detection/lmm.py index e70170ab..d7ca5d3c 100644 --- a/supervision/detection/lmm.py +++ b/supervision/detection/lmm.py @@ -4,7 +4,7 @@ from typing import Any, Dict, List, Optional, Tuple, Union import numpy as np -from supervision.detection.utils import polygon_to_xyxy +from supervision.detection.utils import polygon_to_mask, polygon_to_xyxy class LMM(Enum): @@ -16,12 +16,12 @@ RESULT_TYPES: Dict[LMM, type] = {LMM.PALIGEMMA: str, LMM.FLORENCE_2: dict} REQUIRED_ARGUMENTS: Dict[LMM, List[str]] = { LMM.PALIGEMMA: ["resolution_wh"], - LMM.FLORENCE_2: [], + LMM.FLORENCE_2: ["resolution_wh"], } ALLOWED_ARGUMENTS: Dict[LMM, List[str]] = { LMM.PALIGEMMA: ["resolution_wh", "classes"], - LMM.FLORENCE_2: [], + LMM.FLORENCE_2: ["resolution_wh"], } SUPPORTED_TASKS_FLORENCE_2 = [ @@ -30,6 +30,11 @@ SUPPORTED_TASKS_FLORENCE_2 = [ "", "", "", + "", + "", + "", + "", + "", ] @@ -86,8 +91,10 @@ def from_paligemma( def from_florence_2( - result: dict, -) -> Tuple[np.ndarray, Optional[np.ndarray], Optional[np.ndarray]]: + result: dict, resolution_wh: Tuple[int, int] +) -> Tuple[ + np.ndarray, Optional[np.ndarray], Optional[np.ndarray], Optional[np.ndarray] +]: """ Parse results from the Florence 2 multi-model model. https://huggingface.co/microsoft/Florence-2-large @@ -100,21 +107,24 @@ def from_florence_2( the bounding boxes coordinates in format `[x1, y1, x2, y2]` labels: (Optional[np.ndarray]): An array of shape `(n,)` containing the class labels for each bounding box + masks: (Optional[np.ndarray]): An array of shape `(n, h, w)` containing + the segmentation masks for each bounding box obb_boxes: (Optional[np.ndarray]): An array of shape `(n, 4, 2)` containing oriented bounding boxes. """ for task in ["", "", ""]: - if task in result: - result = result[task] - xyxy = np.array(result["bboxes"], dtype=np.float32) - labels = np.array(result["labels"]) - return xyxy, labels, None + if task not in result: + continue + result = result[task] + xyxy = np.array(result["bboxes"], dtype=np.float32) + labels = np.array(result["labels"]) + return xyxy, labels, None, None if "" in result: result = result[""] xyxy = np.array(result["bboxes"], dtype=np.float32) # provides labels, but they are ["", "", "", ...] - return xyxy, None, None + return xyxy, None, None, None if "" in result: result = result[""] @@ -122,9 +132,57 @@ def from_florence_2( xyxyxyxy = xyxyxyxy.reshape(-1, 4, 2) xyxy = np.array([polygon_to_xyxy(polygon) for polygon in xyxyxyxy]) labels = np.array(result["labels"]) - return xyxy, labels, xyxyxyxy + return xyxy, labels, None, xyxyxyxy + + for task in ["", ""]: + if task not in result: + continue + + result = result[task] + xyxy_list = [] + masks_list = [] + for polygons_of_same_class in result["polygons"]: + for polygon in polygons_of_same_class: + mask = polygon_to_mask(polygon, resolution_wh) + masks_list.append(mask) + xyxy = polygon_to_xyxy(polygon) + xyxy_list.append(xyxy) + # per-class labels also provided, but they are ["", "", "", ...] + # when we figure out how to set class names, we can do + # zip(result["labels"], result["polygons"]) + xyxy = np.array(xyxy_list, dtype=np.float32) + masks = np.array(masks_list) + return xyxy, None, masks, None + + if "" in result: + result = result[""] + xyxy = np.array(result["bboxes"], dtype=np.float32) + labels = np.array(result["bboxes_labels"]) + # Also has "polygons" and "polygons_labels", but they don't seem to be used + return xyxy, labels, None, None + + for task in ["", ""]: + if task not in result: + continue + + result = result[task] + assert isinstance( + result, str + ), f"Expected string as result, got {type(result)}" + + pattern = re.compile(r"") + match = pattern.search(result) + assert ( + match is not None + ), f"Expected string to end in location tags, but got {result}" + + xyxy = np.array(match.groups(), dtype=np.float32) + result_string = result[: match.start()] + labels = np.array([result_string]) + return xyxy, labels, None, None task = list(result.keys())[0] + assert task not in SUPPORTED_TASKS_FLORENCE_2, f"Expected to support task {task}" raise NotImplementedError( f"{task} task not supported. Supported tasks are: {SUPPORTED_TASKS_FLORENCE_2}" ) From 4599548eebb13279c79317e6691f25483bbeb2e7 Mon Sep 17 00:00:00 2001 From: LinasKo Date: Thu, 20 Jun 2024 21:22:15 +0300 Subject: [PATCH 04/12] Fix, from_florence_2: polygons must be shaped (-1, 2) --- supervision/detection/lmm.py | 1 + 1 file changed, 1 insertion(+) diff --git a/supervision/detection/lmm.py b/supervision/detection/lmm.py index d7ca5d3c..e6555706 100644 --- a/supervision/detection/lmm.py +++ b/supervision/detection/lmm.py @@ -143,6 +143,7 @@ def from_florence_2( masks_list = [] for polygons_of_same_class in result["polygons"]: for polygon in polygons_of_same_class: + polygon = np.reshape(polygon, (-1, 2)) mask = polygon_to_mask(polygon, resolution_wh) masks_list.append(mask) xyxy = polygon_to_xyxy(polygon) From ec75a86a8322743b17c39b7d4e6dccb5ab4bf707 Mon Sep 17 00:00:00 2001 From: LinasKo Date: Thu, 20 Jun 2024 21:26:54 +0300 Subject: [PATCH 05/12] Fix, from_florence_2: polygon_to_mask expects np.int32 --- supervision/detection/lmm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/supervision/detection/lmm.py b/supervision/detection/lmm.py index e6555706..c450403b 100644 --- a/supervision/detection/lmm.py +++ b/supervision/detection/lmm.py @@ -143,7 +143,7 @@ def from_florence_2( masks_list = [] for polygons_of_same_class in result["polygons"]: for polygon in polygons_of_same_class: - polygon = np.reshape(polygon, (-1, 2)) + polygon = np.reshape(polygon, (-1, 2)).astype(np.int32) mask = polygon_to_mask(polygon, resolution_wh) masks_list.append(mask) xyxy = polygon_to_xyxy(polygon) From 23e63501eb795ee7a0dc3cdc3b2a36e2f04df765 Mon Sep 17 00:00:00 2001 From: LinasKo Date: Thu, 20 Jun 2024 21:35:49 +0300 Subject: [PATCH 06/12] fix, from_florence_2: extra dimension for xyxy, REGION_TO_CATEGORY --- supervision/detection/lmm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/supervision/detection/lmm.py b/supervision/detection/lmm.py index c450403b..30e5ded9 100644 --- a/supervision/detection/lmm.py +++ b/supervision/detection/lmm.py @@ -177,7 +177,7 @@ def from_florence_2( match is not None ), f"Expected string to end in location tags, but got {result}" - xyxy = np.array(match.groups(), dtype=np.float32) + xyxy = np.array([match.groups()], dtype=np.float32) result_string = result[: match.start()] labels = np.array([result_string]) return xyxy, labels, None, None From ec517124f8c3b371a6d286532322a82be1c7bc16 Mon Sep 17 00:00:00 2001 From: LinasKo Date: Fri, 21 Jun 2024 12:34:09 +0300 Subject: [PATCH 07/12] florence_2: Clean up task selector --- supervision/detection/lmm.py | 40 ++++++++++++++---------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/supervision/detection/lmm.py b/supervision/detection/lmm.py index 30e5ded9..41a7a71a 100644 --- a/supervision/detection/lmm.py +++ b/supervision/detection/lmm.py @@ -112,33 +112,32 @@ def from_florence_2( obb_boxes: (Optional[np.ndarray]): An array of shape `(n, 4, 2)` containing oriented bounding boxes. """ - for task in ["", "", ""]: - if task not in result: - continue - result = result[task] + assert len(result) == 1, f"Expected result with a single element. Got: {result}" + task = list(result.keys())[0] + if task not in SUPPORTED_TASKS_FLORENCE_2: + raise ValueError( + f"{task} not supported. Supported tasks are: {SUPPORTED_TASKS_FLORENCE_2}" + ) + result = result[task] + + if task in ["", "", ""]: xyxy = np.array(result["bboxes"], dtype=np.float32) labels = np.array(result["labels"]) return xyxy, labels, None, None - if "" in result: - result = result[""] + if task == "": xyxy = np.array(result["bboxes"], dtype=np.float32) # provides labels, but they are ["", "", "", ...] return xyxy, None, None, None - if "" in result: - result = result[""] + if task == "": xyxyxyxy = np.array(result["quad_boxes"], dtype=np.float32) xyxyxyxy = xyxyxyxy.reshape(-1, 4, 2) xyxy = np.array([polygon_to_xyxy(polygon) for polygon in xyxyxyxy]) labels = np.array(result["labels"]) return xyxy, labels, None, xyxyxyxy - for task in ["", ""]: - if task not in result: - continue - - result = result[task] + if task in ["", ""]: xyxy_list = [] masks_list = [] for polygons_of_same_class in result["polygons"]: @@ -155,18 +154,13 @@ def from_florence_2( masks = np.array(masks_list) return xyxy, None, masks, None - if "" in result: - result = result[""] + if task == "": xyxy = np.array(result["bboxes"], dtype=np.float32) labels = np.array(result["bboxes_labels"]) # Also has "polygons" and "polygons_labels", but they don't seem to be used return xyxy, labels, None, None - for task in ["", ""]: - if task not in result: - continue - - result = result[task] + if task in ["", ""]: assert isinstance( result, str ), f"Expected string as result, got {type(result)}" @@ -182,8 +176,4 @@ def from_florence_2( labels = np.array([result_string]) return xyxy, labels, None, None - task = list(result.keys())[0] - assert task not in SUPPORTED_TASKS_FLORENCE_2, f"Expected to support task {task}" - raise NotImplementedError( - f"{task} task not supported. Supported tasks are: {SUPPORTED_TASKS_FLORENCE_2}" - ) + assert False, f"Unimplemented task: {task}" From fc11f4d7af57e934aede96e501368b45780e3342 Mon Sep 17 00:00:00 2001 From: LinasKo Date: Fri, 21 Jun 2024 12:56:14 +0300 Subject: [PATCH 08/12] Masks are now bool --- supervision/detection/lmm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/supervision/detection/lmm.py b/supervision/detection/lmm.py index 41a7a71a..9cd9e99a 100644 --- a/supervision/detection/lmm.py +++ b/supervision/detection/lmm.py @@ -143,7 +143,7 @@ def from_florence_2( for polygons_of_same_class in result["polygons"]: for polygon in polygons_of_same_class: polygon = np.reshape(polygon, (-1, 2)).astype(np.int32) - mask = polygon_to_mask(polygon, resolution_wh) + mask = polygon_to_mask(polygon, resolution_wh).astype(bool) masks_list.append(mask) xyxy = polygon_to_xyxy(polygon) xyxy_list.append(xyxy) From 19bf41781018c7aaee65ad1b328be3cd4635d910 Mon Sep 17 00:00:00 2001 From: LinasKo Date: Fri, 21 Jun 2024 15:38:21 +0300 Subject: [PATCH 09/12] Special case for REGION_TO_DESCRIPTION when nothing is detected --- supervision/detection/lmm.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/supervision/detection/lmm.py b/supervision/detection/lmm.py index 9cd9e99a..e39e434f 100644 --- a/supervision/detection/lmm.py +++ b/supervision/detection/lmm.py @@ -165,6 +165,9 @@ def from_florence_2( result, str ), f"Expected string as result, got {type(result)}" + if result == "No object detected.": + return np.empty((0, 4), dtype=np.float32), np.array([]), None, None + pattern = re.compile(r"") match = pattern.search(result) assert ( From 9ef697cd1056209d1445ac1b5e9a24b13c341c53 Mon Sep 17 00:00:00 2001 From: LinasKo Date: Fri, 21 Jun 2024 16:59:01 +0300 Subject: [PATCH 10/12] Florence 2 units tests --- test/detection/test_lmm_florence_2.py | 302 ++++++++++++++++++++++++++ 1 file changed, 302 insertions(+) create mode 100644 test/detection/test_lmm_florence_2.py diff --git a/test/detection/test_lmm_florence_2.py b/test/detection/test_lmm_florence_2.py new file mode 100644 index 00000000..4a5a0094 --- /dev/null +++ b/test/detection/test_lmm_florence_2.py @@ -0,0 +1,302 @@ +from typing import List, Optional, Tuple +from contextlib import ExitStack as DoesNotRaise + +import numpy as np +import pytest + +from supervision.detection.lmm import from_florence_2 + + +@pytest.mark.parametrize( + "florence_result, resolution_wh, expected_results, exception", + [ + ( # Object detection: empty + {"":{ + "bboxes": [], + "labels": [] + }}, + (10, 10), + ( + np.array([], dtype=np.float32), + np.array([]), + None, + None + ), + DoesNotRaise() + ), + ( # Object detection: two detections + {"":{ + "bboxes": [[4, 4, 6, 6], [5, 5, 7, 7]], + "labels": ["car", "door"] + }}, + (10, 10), + ( + np.array([[4, 4, 6, 6], [5, 5, 7, 7]], dtype=np.float32), + np.array(["car", "door"]), + None, + None + ), + DoesNotRaise() + ), + + ( # Caption: unsupported + {"": 'A green car parked in front of a yellow building.'}, + (10, 10), + None, + pytest.raises(ValueError) + ), + ( # Detailed Caption: unsupported + {"": 'The image shows a blue Volkswagen Beetle parked ' + 'in front of a yellow building with two brown doors, surrounded by ' + 'trees and a clear blue sky.'}, + (10, 10), + None, + pytest.raises(ValueError) + ), + ( # More Detailed Caption: unsupported + { + "": 'The image shows a vintage Volkswagen ' + 'Beetle car parked on a ' + 'cobblestone street in front of a yellow building with two wooden ' + 'doors. The car is painted in a bright turquoise color and has a ' + 'white stripe running along the side. It has two doors on either side ' + 'of the car, one on top of the other, and a small window on the ' + 'front. The building appears to be old and dilapidated, with peeling ' + 'paint and crumbling walls. The sky is blue and there are trees in ' + 'the background.' + }, + (10, 10), + None, + pytest.raises(ValueError) + ), + + ( # Caption to Phrase Grounding: empty + {"":{ + "bboxes": [], + "labels": [] + }}, + (10, 10), + ( + np.array([], dtype=np.float32), + np.array([]), + None, + None + ), + DoesNotRaise() + ), + ( # Caption to Phrase Grounding: two detections + {"":{ + "bboxes": [[4, 4, 6, 6], [5, 5, 7, 7]], + "labels": ["a green car", "a yellow building"] + }}, + (10, 10), + ( + np.array([[4, 4, 6, 6], [5, 5, 7, 7]], dtype=np.float32), + np.array(["a green car", "a yellow building"]), + None, + None + ), + DoesNotRaise() + ), + + ( # Dense Region caption: empty + {"":{ + "bboxes": [], + "labels": [] + }}, + (10, 10), + ( + np.array([], dtype=np.float32), + np.array([]), + None, + None + ), + DoesNotRaise() + ), + ( # Caption to Phrase Grounding: two detections + {"":{ + "bboxes": [[4, 4, 6, 6], [5, 5, 7, 7]], + "labels": ["a green car", "a yellow building"] + }}, + (10, 10), + ( + np.array([[4, 4, 6, 6], [5, 5, 7, 7]], dtype=np.float32), + np.array(["a green car", "a yellow building"]), + None, + None + ), + DoesNotRaise() + ), + + ( # Region proposal + {"":{ + "bboxes": [[4, 4, 6, 6], [5, 5, 7, 7]], + "labels": ["", ""] + }}, + (10, 10), + ( + np.array([[4, 4, 6, 6], [5, 5, 7, 7]], dtype=np.float32), + None, + None, + None + ), + DoesNotRaise() + ), + + ( # Referring Expression Segmentation + {"":{ + "polygons": [[[1, 1, 2, 1, 2, 2, 1, 2]]], + "labels": [""] + }}, + (10, 10), + ( + np.array([[1., 1., 2., 2.]], dtype=np.float32), + None, + np.array([[ + [False, False, False, False, False, False, False, False, False, False], + [False, True, True, False, False, False, False, False, False, False], + [False, True, True, False, False, False, False, False, False, False], + [False, False, False, False, False, False, False, False, False, False], + [False, False, False, False, False, False, False, False, False, False], + [False, False, False, False, False, False, False, False, False, False], + [False, False, False, False, False, False, False, False, False, False], + [False, False, False, False, False, False, False, False, False, False], + [False, False, False, False, False, False, False, False, False, False], + [False, False, False, False, False, False, False, False, False, False] + ]]), + None + ), + DoesNotRaise() + ), + + ( # Referring Expression Segmentation + {"":{ + "polygons": [[[1, 1, 2, 1, 2, 2, 1, 2]]], + "labels": [""] + }}, + (10, 10), + ( + np.array([[1., 1., 2., 2.]], dtype=np.float32), + None, + np.array([[ + [False, False, False, False, False, False, False, False, False, False], + [False, True, True, False, False, False, False, False, False, False], + [False, True, True, False, False, False, False, False, False, False], + [False, False, False, False, False, False, False, False, False, False], + [False, False, False, False, False, False, False, False, False, False], + [False, False, False, False, False, False, False, False, False, False], + [False, False, False, False, False, False, False, False, False, False], + [False, False, False, False, False, False, False, False, False, False], + [False, False, False, False, False, False, False, False, False, False], + [False, False, False, False, False, False, False, False, False, False] + ]]), + None + ), + DoesNotRaise() + ), + + ( # OCR: unsupported + {"": 'A'}, + (10, 10), + None, + pytest.raises(ValueError) + ), + + ( # OCR with Region: obb boxes + {"":{ + "quad_boxes": [[2, 2, 6, 4, 5, 6, 1, 5], [4, 4, 5, 5, 4, 6, 3, 5]], + "labels": ["some text", "other text"] + }}, + (10, 10), + ( + np.array([[1, 2, 6, 6], [3, 4, 5, 6]], dtype=np.float32), + np.array(["some text", "other text"]), + None, + np.array([[[2, 2], [6, 4], [5, 6], [1, 5]], [[4, 4], [5, 5], [4, 6], [3, 5]]]) + ), + DoesNotRaise() + ), + + ( # Open Vocabulary Detection + {"":{ + "bboxes": [[4, 4, 6, 6], [5, 5, 7, 7]], + "bboxes_labels": ["cat", "cat"], + "polygon": [], + "polygons_labels": [] + }}, + (10, 10), + ( + np.array([[4, 4, 6, 6], [5, 5, 7, 7]], dtype=np.float32), + np.array(["cat", "cat"]), + None, + None + ), + DoesNotRaise() + ), + + ( # Region to Category: empty + {'': 'No object detected.'}, + (10, 10), + ( + np.empty((0, 4), dtype=np.float32), + np.array([]), + None, + None + ), + DoesNotRaise() + ), + ( # Region to Category: detected + {'': 'some object category'}, + (10, 10), + ( + np.array([[3, 4, 5, 6]], dtype=np.float32), + np.array(["some object category"]), + None, + None + ), + DoesNotRaise() + ), + ( # Region to Description: empty + {'': 'No object detected.'}, + (10, 10), + ( + np.empty((0, 4), dtype=np.float32), + np.array([]), + None, + None + ), + DoesNotRaise() + ), + ( # Region to Description: detected + {'': 'some description'}, + (10, 10), + ( + np.array([[3, 4, 5, 6]], dtype=np.float32), + np.array(["some description"]), + None, + None + ), + DoesNotRaise() + ) + ]) +def test_florence_2( + florence_result: dict, + resolution_wh: Tuple[int, int], + expected_results: Tuple[np.ndarray, Optional[np.ndarray], Optional[np.ndarray], Optional[np.ndarray]], + exception: Exception +) -> None: + with exception: + result = from_florence_2(florence_result, resolution_wh) + np.testing.assert_array_equal(result[0], expected_results[0]) + if expected_results[1] is None: + assert result[1] is None + else: + np.testing.assert_array_equal(result[1], expected_results[1]) + if expected_results[2] is None: + assert result[2] is None + else: + np.testing.assert_array_equal(result[2], expected_results[2]) + if expected_results[3] is None: + assert result[3] is None + else: + np.testing.assert_array_equal(result[3], expected_results[3]) From bcd3e1be173cd52caef8efa0e9c938f08d3bdbc7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 21 Jun 2024 13:59:39 +0000 Subject: [PATCH 11/12] =?UTF-8?q?fix(pre=5Fcommit):=20=F0=9F=8E=A8=20auto?= =?UTF-8?q?=20format=20pre-commit=20hooks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/detection/test_lmm_florence_2.py | 655 +++++++++++++++++--------- 1 file changed, 432 insertions(+), 223 deletions(-) diff --git a/test/detection/test_lmm_florence_2.py b/test/detection/test_lmm_florence_2.py index 4a5a0094..46d333c9 100644 --- a/test/detection/test_lmm_florence_2.py +++ b/test/detection/test_lmm_florence_2.py @@ -1,5 +1,5 @@ -from typing import List, Optional, Tuple from contextlib import ExitStack as DoesNotRaise +from typing import Optional, Tuple import numpy as np import pytest @@ -10,280 +10,489 @@ from supervision.detection.lmm import from_florence_2 @pytest.mark.parametrize( "florence_result, resolution_wh, expected_results, exception", [ - ( # Object detection: empty - {"":{ - "bboxes": [], - "labels": [] - }}, + ( # Object detection: empty + {"": {"bboxes": [], "labels": []}}, (10, 10), - ( - np.array([], dtype=np.float32), - np.array([]), - None, - None - ), - DoesNotRaise() + (np.array([], dtype=np.float32), np.array([]), None, None), + DoesNotRaise(), ), - ( # Object detection: two detections - {"":{ - "bboxes": [[4, 4, 6, 6], [5, 5, 7, 7]], - "labels": ["car", "door"] - }}, + ( # Object detection: two detections + { + "": { + "bboxes": [[4, 4, 6, 6], [5, 5, 7, 7]], + "labels": ["car", "door"], + } + }, (10, 10), ( np.array([[4, 4, 6, 6], [5, 5, 7, 7]], dtype=np.float32), np.array(["car", "door"]), None, - None + None, ), - DoesNotRaise() + DoesNotRaise(), ), - - ( # Caption: unsupported - {"": 'A green car parked in front of a yellow building.'}, + ( # Caption: unsupported + {"": "A green car parked in front of a yellow building."}, (10, 10), None, - pytest.raises(ValueError) + pytest.raises(ValueError), ), - ( # Detailed Caption: unsupported - {"": 'The image shows a blue Volkswagen Beetle parked ' - 'in front of a yellow building with two brown doors, surrounded by ' - 'trees and a clear blue sky.'}, - (10, 10), - None, - pytest.raises(ValueError) - ), - ( # More Detailed Caption: unsupported + ( # Detailed Caption: unsupported { - "": 'The image shows a vintage Volkswagen ' - 'Beetle car parked on a ' - 'cobblestone street in front of a yellow building with two wooden ' - 'doors. The car is painted in a bright turquoise color and has a ' - 'white stripe running along the side. It has two doors on either side ' - 'of the car, one on top of the other, and a small window on the ' - 'front. The building appears to be old and dilapidated, with peeling ' - 'paint and crumbling walls. The sky is blue and there are trees in ' - 'the background.' + "": "The image shows a blue Volkswagen Beetle parked " + "in front of a yellow building with two brown doors, surrounded by " + "trees and a clear blue sky." }, (10, 10), None, - pytest.raises(ValueError) + pytest.raises(ValueError), ), - - ( # Caption to Phrase Grounding: empty - {"":{ - "bboxes": [], - "labels": [] - }}, - (10, 10), - ( - np.array([], dtype=np.float32), - np.array([]), - None, - None - ), - DoesNotRaise() - ), - ( # Caption to Phrase Grounding: two detections - {"":{ - "bboxes": [[4, 4, 6, 6], [5, 5, 7, 7]], - "labels": ["a green car", "a yellow building"] - }}, - (10, 10), - ( - np.array([[4, 4, 6, 6], [5, 5, 7, 7]], dtype=np.float32), - np.array(["a green car", "a yellow building"]), - None, - None - ), - DoesNotRaise() - ), - - ( # Dense Region caption: empty - {"":{ - "bboxes": [], - "labels": [] - }}, - (10, 10), - ( - np.array([], dtype=np.float32), - np.array([]), - None, - None - ), - DoesNotRaise() - ), - ( # Caption to Phrase Grounding: two detections - {"":{ - "bboxes": [[4, 4, 6, 6], [5, 5, 7, 7]], - "labels": ["a green car", "a yellow building"] - }}, - (10, 10), - ( - np.array([[4, 4, 6, 6], [5, 5, 7, 7]], dtype=np.float32), - np.array(["a green car", "a yellow building"]), - None, - None - ), - DoesNotRaise() - ), - - ( # Region proposal - {"":{ - "bboxes": [[4, 4, 6, 6], [5, 5, 7, 7]], - "labels": ["", ""] - }}, - (10, 10), - ( - np.array([[4, 4, 6, 6], [5, 5, 7, 7]], dtype=np.float32), - None, - None, - None - ), - DoesNotRaise() - ), - - ( # Referring Expression Segmentation - {"":{ - "polygons": [[[1, 1, 2, 1, 2, 2, 1, 2]]], - "labels": [""] - }}, - (10, 10), - ( - np.array([[1., 1., 2., 2.]], dtype=np.float32), - None, - np.array([[ - [False, False, False, False, False, False, False, False, False, False], - [False, True, True, False, False, False, False, False, False, False], - [False, True, True, False, False, False, False, False, False, False], - [False, False, False, False, False, False, False, False, False, False], - [False, False, False, False, False, False, False, False, False, False], - [False, False, False, False, False, False, False, False, False, False], - [False, False, False, False, False, False, False, False, False, False], - [False, False, False, False, False, False, False, False, False, False], - [False, False, False, False, False, False, False, False, False, False], - [False, False, False, False, False, False, False, False, False, False] - ]]), - None - ), - DoesNotRaise() - ), - - ( # Referring Expression Segmentation - {"":{ - "polygons": [[[1, 1, 2, 1, 2, 2, 1, 2]]], - "labels": [""] - }}, - (10, 10), - ( - np.array([[1., 1., 2., 2.]], dtype=np.float32), - None, - np.array([[ - [False, False, False, False, False, False, False, False, False, False], - [False, True, True, False, False, False, False, False, False, False], - [False, True, True, False, False, False, False, False, False, False], - [False, False, False, False, False, False, False, False, False, False], - [False, False, False, False, False, False, False, False, False, False], - [False, False, False, False, False, False, False, False, False, False], - [False, False, False, False, False, False, False, False, False, False], - [False, False, False, False, False, False, False, False, False, False], - [False, False, False, False, False, False, False, False, False, False], - [False, False, False, False, False, False, False, False, False, False] - ]]), - None - ), - DoesNotRaise() - ), - - ( # OCR: unsupported - {"": 'A'}, + ( # More Detailed Caption: unsupported + { + "": "The image shows a vintage Volkswagen " + "Beetle car parked on a " + "cobblestone street in front of a yellow building with two wooden " + "doors. The car is painted in a bright turquoise color and has a " + "white stripe running along the side. It has two doors on either side " + "of the car, one on top of the other, and a small window on the " + "front. The building appears to be old and dilapidated, with peeling " + "paint and crumbling walls. The sky is blue and there are trees in " + "the background." + }, (10, 10), None, - pytest.raises(ValueError) + pytest.raises(ValueError), ), - - ( # OCR with Region: obb boxes - {"":{ - "quad_boxes": [[2, 2, 6, 4, 5, 6, 1, 5], [4, 4, 5, 5, 4, 6, 3, 5]], - "labels": ["some text", "other text"] - }}, + ( # Caption to Phrase Grounding: empty + {"": {"bboxes": [], "labels": []}}, + (10, 10), + (np.array([], dtype=np.float32), np.array([]), None, None), + DoesNotRaise(), + ), + ( # Caption to Phrase Grounding: two detections + { + "": { + "bboxes": [[4, 4, 6, 6], [5, 5, 7, 7]], + "labels": ["a green car", "a yellow building"], + } + }, + (10, 10), + ( + np.array([[4, 4, 6, 6], [5, 5, 7, 7]], dtype=np.float32), + np.array(["a green car", "a yellow building"]), + None, + None, + ), + DoesNotRaise(), + ), + ( # Dense Region caption: empty + {"": {"bboxes": [], "labels": []}}, + (10, 10), + (np.array([], dtype=np.float32), np.array([]), None, None), + DoesNotRaise(), + ), + ( # Caption to Phrase Grounding: two detections + { + "": { + "bboxes": [[4, 4, 6, 6], [5, 5, 7, 7]], + "labels": ["a green car", "a yellow building"], + } + }, + (10, 10), + ( + np.array([[4, 4, 6, 6], [5, 5, 7, 7]], dtype=np.float32), + np.array(["a green car", "a yellow building"]), + None, + None, + ), + DoesNotRaise(), + ), + ( # Region proposal + { + "": { + "bboxes": [[4, 4, 6, 6], [5, 5, 7, 7]], + "labels": ["", ""], + } + }, + (10, 10), + ( + np.array([[4, 4, 6, 6], [5, 5, 7, 7]], dtype=np.float32), + None, + None, + None, + ), + DoesNotRaise(), + ), + ( # Referring Expression Segmentation + { + "": { + "polygons": [[[1, 1, 2, 1, 2, 2, 1, 2]]], + "labels": [""], + } + }, + (10, 10), + ( + np.array([[1.0, 1.0, 2.0, 2.0]], dtype=np.float32), + None, + np.array( + [ + [ + [ + False, + False, + False, + False, + False, + False, + False, + False, + False, + False, + ], + [ + False, + True, + True, + False, + False, + False, + False, + False, + False, + False, + ], + [ + False, + True, + True, + False, + False, + False, + False, + False, + False, + False, + ], + [ + False, + False, + False, + False, + False, + False, + False, + False, + False, + False, + ], + [ + False, + False, + False, + False, + False, + False, + False, + False, + False, + False, + ], + [ + False, + False, + False, + False, + False, + False, + False, + False, + False, + False, + ], + [ + False, + False, + False, + False, + False, + False, + False, + False, + False, + False, + ], + [ + False, + False, + False, + False, + False, + False, + False, + False, + False, + False, + ], + [ + False, + False, + False, + False, + False, + False, + False, + False, + False, + False, + ], + [ + False, + False, + False, + False, + False, + False, + False, + False, + False, + False, + ], + ] + ] + ), + None, + ), + DoesNotRaise(), + ), + ( # Referring Expression Segmentation + { + "": { + "polygons": [[[1, 1, 2, 1, 2, 2, 1, 2]]], + "labels": [""], + } + }, + (10, 10), + ( + np.array([[1.0, 1.0, 2.0, 2.0]], dtype=np.float32), + None, + np.array( + [ + [ + [ + False, + False, + False, + False, + False, + False, + False, + False, + False, + False, + ], + [ + False, + True, + True, + False, + False, + False, + False, + False, + False, + False, + ], + [ + False, + True, + True, + False, + False, + False, + False, + False, + False, + False, + ], + [ + False, + False, + False, + False, + False, + False, + False, + False, + False, + False, + ], + [ + False, + False, + False, + False, + False, + False, + False, + False, + False, + False, + ], + [ + False, + False, + False, + False, + False, + False, + False, + False, + False, + False, + ], + [ + False, + False, + False, + False, + False, + False, + False, + False, + False, + False, + ], + [ + False, + False, + False, + False, + False, + False, + False, + False, + False, + False, + ], + [ + False, + False, + False, + False, + False, + False, + False, + False, + False, + False, + ], + [ + False, + False, + False, + False, + False, + False, + False, + False, + False, + False, + ], + ] + ] + ), + None, + ), + DoesNotRaise(), + ), + ( # OCR: unsupported + {"": "A"}, + (10, 10), + None, + pytest.raises(ValueError), + ), + ( # OCR with Region: obb boxes + { + "": { + "quad_boxes": [[2, 2, 6, 4, 5, 6, 1, 5], [4, 4, 5, 5, 4, 6, 3, 5]], + "labels": ["some text", "other text"], + } + }, (10, 10), ( np.array([[1, 2, 6, 6], [3, 4, 5, 6]], dtype=np.float32), np.array(["some text", "other text"]), None, - np.array([[[2, 2], [6, 4], [5, 6], [1, 5]], [[4, 4], [5, 5], [4, 6], [3, 5]]]) + np.array( + [[[2, 2], [6, 4], [5, 6], [1, 5]], [[4, 4], [5, 5], [4, 6], [3, 5]]] + ), ), - DoesNotRaise() + DoesNotRaise(), ), - - ( # Open Vocabulary Detection - {"":{ - "bboxes": [[4, 4, 6, 6], [5, 5, 7, 7]], - "bboxes_labels": ["cat", "cat"], - "polygon": [], - "polygons_labels": [] - }}, + ( # Open Vocabulary Detection + { + "": { + "bboxes": [[4, 4, 6, 6], [5, 5, 7, 7]], + "bboxes_labels": ["cat", "cat"], + "polygon": [], + "polygons_labels": [], + } + }, (10, 10), ( np.array([[4, 4, 6, 6], [5, 5, 7, 7]], dtype=np.float32), np.array(["cat", "cat"]), None, - None - ), - DoesNotRaise() - ), - - ( # Region to Category: empty - {'': 'No object detected.'}, - (10, 10), - ( - np.empty((0, 4), dtype=np.float32), - np.array([]), None, - None ), - DoesNotRaise() + DoesNotRaise(), ), - ( # Region to Category: detected - {'': 'some object category'}, + ( # Region to Category: empty + {"": "No object detected."}, + (10, 10), + (np.empty((0, 4), dtype=np.float32), np.array([]), None, None), + DoesNotRaise(), + ), + ( # Region to Category: detected + { + "": "some object category" + }, (10, 10), ( np.array([[3, 4, 5, 6]], dtype=np.float32), np.array(["some object category"]), None, - None - ), - DoesNotRaise() - ), - ( # Region to Description: empty - {'': 'No object detected.'}, - (10, 10), - ( - np.empty((0, 4), dtype=np.float32), - np.array([]), None, - None ), - DoesNotRaise() + DoesNotRaise(), ), - ( # Region to Description: detected - {'': 'some description'}, + ( # Region to Description: empty + {"": "No object detected."}, + (10, 10), + (np.empty((0, 4), dtype=np.float32), np.array([]), None, None), + DoesNotRaise(), + ), + ( # Region to Description: detected + {"": "some description"}, (10, 10), ( np.array([[3, 4, 5, 6]], dtype=np.float32), np.array(["some description"]), None, - None + None, ), - DoesNotRaise() - ) - ]) + DoesNotRaise(), + ), + ], +) def test_florence_2( florence_result: dict, resolution_wh: Tuple[int, int], - expected_results: Tuple[np.ndarray, Optional[np.ndarray], Optional[np.ndarray], Optional[np.ndarray]], - exception: Exception + expected_results: Tuple[ + np.ndarray, Optional[np.ndarray], Optional[np.ndarray], Optional[np.ndarray] + ], + exception: Exception, ) -> None: with exception: result = from_florence_2(florence_result, resolution_wh) From 61579af25a20dd31f758c7b489f0bd21290f8c97 Mon Sep 17 00:00:00 2001 From: LinasKo Date: Fri, 21 Jun 2024 17:49:43 +0300 Subject: [PATCH 12/12] Make ruff happy --- test/detection/test_lmm_florence_2.py | 272 +++----------------------- 1 file changed, 26 insertions(+), 246 deletions(-) diff --git a/test/detection/test_lmm_florence_2.py b/test/detection/test_lmm_florence_2.py index 46d333c9..9ffec2a1 100644 --- a/test/detection/test_lmm_florence_2.py +++ b/test/detection/test_lmm_florence_2.py @@ -138,128 +138,19 @@ from supervision.detection.lmm import from_florence_2 np.array( [ [ - [ - False, - False, - False, - False, - False, - False, - False, - False, - False, - False, - ], - [ - False, - True, - True, - False, - False, - False, - False, - False, - False, - False, - ], - [ - False, - True, - True, - False, - False, - False, - False, - False, - False, - False, - ], - [ - False, - False, - False, - False, - False, - False, - False, - False, - False, - False, - ], - [ - False, - False, - False, - False, - False, - False, - False, - False, - False, - False, - ], - [ - False, - False, - False, - False, - False, - False, - False, - False, - False, - False, - ], - [ - False, - False, - False, - False, - False, - False, - False, - False, - False, - False, - ], - [ - False, - False, - False, - False, - False, - False, - False, - False, - False, - False, - ], - [ - False, - False, - False, - False, - False, - False, - False, - False, - False, - False, - ], - [ - False, - False, - False, - False, - False, - False, - False, - False, - False, - False, - ], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 1, 1, 0, 0, 0, 0, 0, 0, 0], + [0, 1, 1, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], ] - ] + ], + dtype=bool, ), None, ), @@ -279,128 +170,19 @@ from supervision.detection.lmm import from_florence_2 np.array( [ [ - [ - False, - False, - False, - False, - False, - False, - False, - False, - False, - False, - ], - [ - False, - True, - True, - False, - False, - False, - False, - False, - False, - False, - ], - [ - False, - True, - True, - False, - False, - False, - False, - False, - False, - False, - ], - [ - False, - False, - False, - False, - False, - False, - False, - False, - False, - False, - ], - [ - False, - False, - False, - False, - False, - False, - False, - False, - False, - False, - ], - [ - False, - False, - False, - False, - False, - False, - False, - False, - False, - False, - ], - [ - False, - False, - False, - False, - False, - False, - False, - False, - False, - False, - ], - [ - False, - False, - False, - False, - False, - False, - False, - False, - False, - False, - ], - [ - False, - False, - False, - False, - False, - False, - False, - False, - False, - False, - ], - [ - False, - False, - False, - False, - False, - False, - False, - False, - False, - False, - ], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 1, 1, 0, 0, 0, 0, 0, 0, 0], + [0, 1, 1, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], ] - ] + ], + dtype=bool, ), None, ), @@ -455,13 +237,11 @@ from supervision.detection.lmm import from_florence_2 DoesNotRaise(), ), ( # Region to Category: detected - { - "": "some object category" - }, + {"": "some object"}, (10, 10), ( np.array([[3, 4, 5, 6]], dtype=np.float32), - np.array(["some object category"]), + np.array(["some object"]), None, None, ),