diff --git a/supervision/detection/core.py b/supervision/detection/core.py index 14f4c0ef8..a98676ec7 100644 --- a/supervision/detection/core.py +++ b/supervision/detection/core.py @@ -1,6 +1,5 @@ from __future__ import annotations -from contextlib import suppress from dataclasses import dataclass, field from typing import Any, Dict, Iterator, List, Optional, Tuple, Union @@ -606,8 +605,10 @@ def from_inference(cls, roboflow_result: Union[dict, Any]) -> Detections: detections = sv.Detections.from_inference(result) ``` """ - with suppress(AttributeError): + if hasattr(roboflow_result, "dict"): roboflow_result = roboflow_result.dict(exclude_none=True, by_alias=True) + elif hasattr(roboflow_result, "json"): + roboflow_result = roboflow_result.json() xyxy, confidence, class_id, masks, trackers, data = process_roboflow_result( roboflow_result=roboflow_result ) diff --git a/supervision/keypoint/core.py b/supervision/keypoint/core.py index 4b8e9d55b..945524156 100644 --- a/supervision/keypoint/core.py +++ b/supervision/keypoint/core.py @@ -1,6 +1,5 @@ from __future__ import annotations -from contextlib import suppress from dataclasses import dataclass, field from typing import Any, Dict, Iterable, Iterator, List, Optional, Tuple, Union @@ -204,9 +203,10 @@ def from_inference(cls, inference_result: Union[dict, Any]) -> KeyPoints: "You can retrieve it like so: inference_result = model.infer(image)[0]" ) - with suppress(AttributeError): + if hasattr(inference_result, "dict"): inference_result = inference_result.dict(exclude_none=True, by_alias=True) - + elif hasattr(inference_result, "json"): + inference_result = inference_result.json() if not inference_result.get("predictions"): return cls.empty()