From 04c5f18da09d076183ba4e678ab4b5fcbad7c321 Mon Sep 17 00:00:00 2001 From: LinasKo Date: Thu, 20 Jun 2024 15:49:13 +0300 Subject: [PATCH] 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