From 186bfc44facca73b538e7cee10b9e29a149e28bf Mon Sep 17 00:00:00 2001 From: hd Date: Mon, 10 Jul 2023 18:03:56 +0200 Subject: [PATCH 1/3] paddledet initial support added --- supervision/detection/core.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/supervision/detection/core.py b/supervision/detection/core.py index b423aaad..cee2ef5f 100644 --- a/supervision/detection/core.py +++ b/supervision/detection/core.py @@ -354,6 +354,14 @@ class Detections: return Detections(xyxy=xywh_to_xyxy(boxes_xywh=xywh), mask=mask) + @classmethod + def from_paddledet(cls, paddledet_result): + return cls( + xyxy=paddledet_result[:, 2:6], + confidence=paddledet_result[:, 1], + class_id=paddledet_result[:, 0].astype(int), + ) + @classmethod def empty(cls) -> Detections: """ From 12ce5feab73208176f6c61ab9c7dc0705a8e6021 Mon Sep 17 00:00:00 2001 From: hd Date: Mon, 10 Jul 2023 18:13:50 +0200 Subject: [PATCH 2/3] paddledet refactored --- supervision/detection/core.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/supervision/detection/core.py b/supervision/detection/core.py index cee2ef5f..2f5e7d3c 100644 --- a/supervision/detection/core.py +++ b/supervision/detection/core.py @@ -357,9 +357,9 @@ class Detections: @classmethod def from_paddledet(cls, paddledet_result): return cls( - xyxy=paddledet_result[:, 2:6], - confidence=paddledet_result[:, 1], - class_id=paddledet_result[:, 0].astype(int), + xyxy=paddledet_result["bbox"][:, 2:6], + confidence=paddledet_result["bbox"][:, 1], + class_id=paddledet_result["bbox"][:, 0].astype(int), ) @classmethod From 985608146cd998adac94ac1a775a84daf8eae032 Mon Sep 17 00:00:00 2001 From: hd Date: Fri, 21 Jul 2023 12:13:46 +0200 Subject: [PATCH 3/3] Docstrings updated --- supervision/detection/core.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/supervision/detection/core.py b/supervision/detection/core.py index 2f5e7d3c..4e3cb520 100644 --- a/supervision/detection/core.py +++ b/supervision/detection/core.py @@ -356,6 +356,34 @@ class Detections: @classmethod def from_paddledet(cls, paddledet_result): + """ + Creates a Detections instance from [PaddleDetection](https://github.com/PaddlePaddle/PaddleDetection) inference result. + + Args: + paddledet_result (List[dict]): The output Results instance from SAM + + Returns: + Detections: A new Detections object. + + Example: + ```python + >>> import supervision as sv + >>> import paddle + >>> from ppdet.engine import Trainer + >>> from ppdet.core.workspace import load_config + + >>> weights = (...) + >>> config = (...) + + >>> cfg = load_config(config) + >>> trainer = Trainer(cfg, mode='test') + >>> trainer.load_weights(weights) + + >>> paddledet_result = trainer.predict([images])[0] + + >>> detections = sv.Detections.from_paddledet(paddledet_result=paddledet_result) + ``` + """ return cls( xyxy=paddledet_result["bbox"][:, 2:6], confidence=paddledet_result["bbox"][:, 1],