Merge remote-tracking branch 'origin/develop' into develop

This commit is contained in:
SkalskiP 2024-08-05 15:02:51 +02:00
commit fde9cd4735
2 changed files with 14 additions and 11 deletions

View File

@ -487,12 +487,18 @@ class Detections:
transformers_results.__class__.__name__ == "Tensor"
or "segmentation" in transformers_results
):
return cls(**process_transformers_v5_segmentation_result(
transformers_results, id2label))
return cls(
**process_transformers_v5_segmentation_result(
transformers_results, id2label
)
)
if "masks" in transformers_results or "png_string" in transformers_results:
return cls(**process_transformers_v4_segmentation_result(
transformers_results, id2label))
return cls(
**process_transformers_v4_segmentation_result(
transformers_results, id2label
)
)
if "boxes" in transformers_results:
return cls(**process_detection_result(transformers_results, id2label))

View File

@ -1,5 +1,5 @@
import io
from typing import Dict, Optional, Any
from typing import Any, Dict, Optional
import numpy as np
from PIL import Image
@ -11,7 +11,7 @@ from supervision.detection.utils import mask_to_xyxy
def append_class_names_to_data(
class_ids: np.ndarray,
id2label: Optional[Dict[int, str]],
data: Optional[Dict[str, Any]] = None
data: Optional[Dict[str, Any]] = None,
) -> Dict[str, Any]:
"""
Helper function to create or append to a data dictionary with class names if
@ -119,7 +119,7 @@ def process_transformers_v4_segmentation_result(
mask=np.squeeze(masks, axis=1) if boxes is not None else masks,
confidence=segmentation_result["scores"].cpu().detach().numpy(),
class_id=class_ids,
data=append_class_names_to_data(class_ids, id2label ,{}),
data=append_class_names_to_data(class_ids, id2label, {}),
)
@ -202,10 +202,7 @@ def process_png_segmentation_result(
class_ids = np.array([segment["category_id"] for segment in segments_info])
label_mask = png_string_to_label_mask(segmentation_result["png_string"])
masks = np.array(
[
(label_mask == segment["id"]).astype(bool)
for segment in segments_info
]
[(label_mask == segment["id"]).astype(bool) for segment in segments_info]
)
data = append_class_names_to_data(class_ids, id2label, {})