feat: 🚀 enhance Google Gemini 2.5 integration to include confidence scores in detection results

This commit is contained in:
Onuralp SEZER
2025-07-14 10:58:59 +03:00
parent d34f050642
commit c7ebfeb4bc
2 changed files with 14 additions and 5 deletions
+2 -2
View File
@@ -1041,9 +1041,9 @@ class Detections:
return cls(xyxy=xyxy, data=data)
if vlm == VLM.GOOGLE_GEMINI_2_5:
xyxy, class_id, class_name, mask = from_google_gemini_2_5(result, **kwargs)
xyxy, class_id, class_name, mask, confidence = from_google_gemini_2_5(result, **kwargs)
data = {CLASS_NAME_DATA_FIELD: class_name}
return cls(xyxy=xyxy, class_id=class_id, mask=mask, data=data)
return cls(xyxy=xyxy, class_id=class_id, mask=mask, confidence=confidence, data=data)
return cls.empty()
+12 -3
View File
@@ -402,7 +402,7 @@ def from_google_gemini(
def from_google_gemini_2_5(
result: str,
resolution_wh: Tuple[int, int],
) -> Tuple[np.ndarray, np.ndarray, np.ndarray, Optional[np.ndarray]]:
) -> Tuple[np.ndarray, np.ndarray, np.ndarray, Optional[np.ndarray], Optional[np.ndarray]]:
"""
Parse and scale bounding boxes and masks from Google Gemini 2.5 style
[JSON output](https://ai.google.dev/gemini-api/docs/vision?lang=python).
@@ -454,7 +454,8 @@ def from_google_gemini_2_5(
class_name: list = []
class_id: list = []
xyxy: list = []
masks: Optional[list] = []
masks: list = []
confidence: list = []
for item in data:
if "box_2d" not in item or "label" not in item:
@@ -497,6 +498,14 @@ def from_google_gemini_2_5(
else:
masks.append(np.zeros((h, w), dtype=bool))
if "confidence" in item:
# if confidence is provided
confidence.append(item["confidence"])
else:
# if confidence is not provided, we assume 0
confidence.append(0.0)
if not xyxy:
return (
np.empty((0, 4)),
@@ -511,4 +520,4 @@ def from_google_gemini_2_5(
for label in class_name:
class_id.append(unique_labels.index(label))
return np.array(xyxy), np.array(class_id), np.array(class_name), mask
return np.array(xyxy), np.array(class_id), np.array(class_name), mask, np.array(confidence)