From f0bc628eafbe321f7a11500ca694ac662375e8d8 Mon Sep 17 00:00:00 2001 From: Mayank Agarwal Date: Fri, 11 Aug 2023 17:47:17 +0530 Subject: [PATCH 01/12] classification ultralytics --- supervision/classification/core.py | 41 +++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/supervision/classification/core.py b/supervision/classification/core.py index 2f654b79..8ce20b36 100644 --- a/supervision/classification/core.py +++ b/supervision/classification/core.py @@ -5,6 +5,8 @@ from typing import Any, Optional, Tuple import numpy as np +from supervision.utils.internal import deprecated + def _validate_class_ids(class_id: Any, n: int) -> None: """ @@ -40,6 +42,9 @@ class Classifications: _validate_confidence(self.confidence, n) @classmethod + @deprecated( + "This method is deprecated and removed in 0.15.0 release. Use sv.Classifications.from_ultralytics() instead." + ) def from_yolov8(cls, yolov8_results) -> Classifications: """ Creates a Classifications instance from a [YOLOv8](https://github.com/ultralytics/ultralytics) inference result. @@ -48,7 +53,7 @@ class Classifications: yolov8_results (ultralytics.yolo.engine.results.Results): The output Results instance from YOLOv8 Returns: - Detections: A new Classifications object. + Classifications: A new Classifications object. Example: ```python @@ -65,6 +70,40 @@ class Classifications: confidence = yolov8_results.probs.data.cpu().numpy() return cls(class_id=np.arange(confidence.shape[0]), confidence=confidence) + @classmethod + def from_ultralytics(cls, ultralytics_results) -> Classifications: + """ + Creates a Classifications instance from a (https://github.com/ultralytics/ultralytics) inference result. + + Args: + ultralytics_results (ultralytics.yolo.engine.results.Results): The output Results instance from ultralytics model + + Returns: + Classifications: A new Classifications object. + + Example: + ```python + >>> import cv2 + >>> from ultralytics import YOLO, FastSAM, SAM, RTDETR + >>> import supervision as sv + + >>> image = cv2.imread(SOURCE_IMAGE_PATH) + >>> model = YOLO('yolov8s.pt') + >>> model = SAM('sam_b.pt') + >>> model = SAM('mobile_sam.pt') + >>> model = FastSAM('FastSAM-s.pt') + >>> model = RTDETR('rtdetr-l.pt') + + >>> result = model(image)[0] + >>> classifications = sv.Classifications.from_ultralytics(result) + ``` + """ + confidence = ultralytics_results.boxes.conf.cpu().numpy() + return cls(class_id=np.arange(confidence.shape[0]), confidence=confidence) + + + + def get_top_k(self, k: int) -> Tuple[np.ndarray, np.ndarray]: """ Retrieve the top k class IDs and confidences, ordered in descending order by confidence. From 67a81afcfa5a351017af104426aa2d68b85e3e1b Mon Sep 17 00:00:00 2001 From: Mayank Agarwal Date: Fri, 11 Aug 2023 17:55:13 +0530 Subject: [PATCH 02/12] format fix --- supervision/classification/core.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/supervision/classification/core.py b/supervision/classification/core.py index 8ce20b36..02432c07 100644 --- a/supervision/classification/core.py +++ b/supervision/classification/core.py @@ -101,9 +101,6 @@ class Classifications: confidence = ultralytics_results.boxes.conf.cpu().numpy() return cls(class_id=np.arange(confidence.shape[0]), confidence=confidence) - - - def get_top_k(self, k: int) -> Tuple[np.ndarray, np.ndarray]: """ Retrieve the top k class IDs and confidences, ordered in descending order by confidence. From b90f9a16779a3ecc4ca7793fb08570745588fd47 Mon Sep 17 00:00:00 2001 From: Mayank Agarwal Date: Fri, 11 Aug 2023 18:27:04 +0530 Subject: [PATCH 03/12] doc fix --- supervision/classification/core.py | 2 +- supervision/detection/core.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/supervision/classification/core.py b/supervision/classification/core.py index 02432c07..076abc37 100644 --- a/supervision/classification/core.py +++ b/supervision/classification/core.py @@ -43,7 +43,7 @@ class Classifications: @classmethod @deprecated( - "This method is deprecated and removed in 0.15.0 release. Use sv.Classifications.from_ultralytics() instead." + "This method is deprecated and removed in 0.16.0 release. Use sv.Classifications.from_ultralytics() instead." ) def from_yolov8(cls, yolov8_results) -> Classifications: """ diff --git a/supervision/detection/core.py b/supervision/detection/core.py index 410b216a..6d3cd682 100644 --- a/supervision/detection/core.py +++ b/supervision/detection/core.py @@ -172,7 +172,7 @@ class Detections: @classmethod @deprecated( - "This method is deprecated and removed in 0.15.0 release. Use sv.Detections.from_ultralytics() instead." + "This method is deprecated and removed in 0.16.0 release. Use sv.Detections.from_ultralytics() instead." ) def from_yolov8(cls, yolov8_results) -> Detections: """ From 234f6fa43bccc95b25376477f7746e4b794acf4f Mon Sep 17 00:00:00 2001 From: Mayank Agarwal Date: Sat, 12 Aug 2023 17:37:00 +0530 Subject: [PATCH 04/12] change examples to classification models --- supervision/classification/core.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/supervision/classification/core.py b/supervision/classification/core.py index 076abc37..a6db2ef6 100644 --- a/supervision/classification/core.py +++ b/supervision/classification/core.py @@ -88,11 +88,8 @@ class Classifications: >>> import supervision as sv >>> image = cv2.imread(SOURCE_IMAGE_PATH) - >>> model = YOLO('yolov8s.pt') - >>> model = SAM('sam_b.pt') - >>> model = SAM('mobile_sam.pt') - >>> model = FastSAM('FastSAM-s.pt') - >>> model = RTDETR('rtdetr-l.pt') + >>> model = YOLO('yolov8n-cls.pt') + >>> model = YOLO('yolov8s-cls.pt') >>> result = model(image)[0] >>> classifications = sv.Classifications.from_ultralytics(result) From 5f314cf21f72271ccb4c45106570e30aa2cf5f5f Mon Sep 17 00:00:00 2001 From: Mayank Agarwal Date: Tue, 15 Aug 2023 00:48:12 +0530 Subject: [PATCH 05/12] remove redundant imports from comments --- supervision/classification/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/supervision/classification/core.py b/supervision/classification/core.py index 18680ef4..936b2398 100644 --- a/supervision/classification/core.py +++ b/supervision/classification/core.py @@ -86,7 +86,7 @@ class Classifications: Example: ```python >>> import cv2 - >>> from ultralytics import YOLO, FastSAM, SAM, RTDETR + >>> from ultralytics import YOLO >>> import supervision as sv >>> image = cv2.imread(SOURCE_IMAGE_PATH) From a5c6fe57f6d21853de1a242a6698fe1b8c3d00e9 Mon Sep 17 00:00:00 2001 From: Mayank Agarwal Date: Tue, 15 Aug 2023 10:47:16 +0530 Subject: [PATCH 06/12] embellish comment --- supervision/classification/core.py | 5 +++-- supervision/detection/core.py | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/supervision/classification/core.py b/supervision/classification/core.py index 936b2398..27e68d90 100644 --- a/supervision/classification/core.py +++ b/supervision/classification/core.py @@ -43,7 +43,8 @@ class Classifications: @classmethod @deprecated( - "This method is deprecated and removed in 0.16.0 release. Use sv.Classifications.from_ultralytics() instead." + "This method is deprecated and removed in 0.16.0 release. Use sv.Classifications.from_ultralytics() instead" + "as it is more generic and can be used for detections from any ultralytics.engine.results.Results Object " ) def from_yolov8(cls, yolov8_results) -> Classifications: """ @@ -78,7 +79,7 @@ class Classifications: Creates a Classifications instance from a (https://github.com/ultralytics/ultralytics) inference result. Args: - ultralytics_results (ultralytics.yolo.engine.results.Results): The output Results instance from ultralytics model + ultralytics_results (ultralytics.engine.results.Results): The output Results instance from ultralytics model Returns: Classifications: A new Classifications object. diff --git a/supervision/detection/core.py b/supervision/detection/core.py index d8b9738e..66a6cc99 100644 --- a/supervision/detection/core.py +++ b/supervision/detection/core.py @@ -179,7 +179,8 @@ class Detections: @classmethod @deprecated( - "This method is deprecated and removed in 0.16.0 release. Use sv.Detections.from_ultralytics() instead." + "This method is deprecated and removed in 0.16.0 release. Use sv.Detections.from_ultralytics() instead" + "as it is more generic and can be used for detections from any ultralytics.engine.results.Results Object " ) def from_yolov8(cls, yolov8_results) -> Detections: """ From dacce7aa5fd5f3c39196b0dd4226a8959dbc3d42 Mon Sep 17 00:00:00 2001 From: Mayank Agarwal Date: Tue, 15 Aug 2023 10:50:49 +0530 Subject: [PATCH 07/12] embellish comment --- supervision/classification/core.py | 7 +++++-- supervision/detection/core.py | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/supervision/classification/core.py b/supervision/classification/core.py index 27e68d90..e4535f98 100644 --- a/supervision/classification/core.py +++ b/supervision/classification/core.py @@ -43,8 +43,11 @@ class Classifications: @classmethod @deprecated( - "This method is deprecated and removed in 0.16.0 release. Use sv.Classifications.from_ultralytics() instead" - "as it is more generic and can be used for detections from any ultralytics.engine.results.Results Object " + """ + This method is deprecated and removed in 0.16.0 release. + Use sv.Classifications.from_ultralytics() instead as it is more generic and + can be used for detections from any ultralytics.engine.results.Results Object + """ ) def from_yolov8(cls, yolov8_results) -> Classifications: """ diff --git a/supervision/detection/core.py b/supervision/detection/core.py index 66a6cc99..9aa7d21d 100644 --- a/supervision/detection/core.py +++ b/supervision/detection/core.py @@ -179,8 +179,11 @@ class Detections: @classmethod @deprecated( - "This method is deprecated and removed in 0.16.0 release. Use sv.Detections.from_ultralytics() instead" - "as it is more generic and can be used for detections from any ultralytics.engine.results.Results Object " + """ + This method is deprecated and removed in 0.16.0 release. + Use sv.Classifications.from_ultralytics() instead as it is more generic and + can be used for detections from any ultralytics.engine.results.Results Object + """ ) def from_yolov8(cls, yolov8_results) -> Detections: """ From 735de7de7ed6b897feaef697880710198d992767 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 15 Aug 2023 05:21:03 +0000 Subject: [PATCH 08/12] =?UTF-8?q?fix(pre=5Fcommit):=20=F0=9F=8E=A8=20auto?= =?UTF-8?q?=20format=20pre-commit=20hooks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- supervision/classification/core.py | 2 +- supervision/detection/core.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/supervision/classification/core.py b/supervision/classification/core.py index e4535f98..d6087538 100644 --- a/supervision/classification/core.py +++ b/supervision/classification/core.py @@ -44,7 +44,7 @@ class Classifications: @classmethod @deprecated( """ - This method is deprecated and removed in 0.16.0 release. + This method is deprecated and removed in 0.16.0 release. Use sv.Classifications.from_ultralytics() instead as it is more generic and can be used for detections from any ultralytics.engine.results.Results Object """ diff --git a/supervision/detection/core.py b/supervision/detection/core.py index 9aa7d21d..f3395a1c 100644 --- a/supervision/detection/core.py +++ b/supervision/detection/core.py @@ -180,7 +180,7 @@ class Detections: @classmethod @deprecated( """ - This method is deprecated and removed in 0.16.0 release. + This method is deprecated and removed in 0.16.0 release. Use sv.Classifications.from_ultralytics() instead as it is more generic and can be used for detections from any ultralytics.engine.results.Results Object """ From 8c70197734d6e2d0836b0b92f5705f5020c2971b Mon Sep 17 00:00:00 2001 From: Mayank Agarwal Date: Tue, 15 Aug 2023 10:57:42 +0530 Subject: [PATCH 09/12] flake tests --- supervision/classification/core.py | 2 +- supervision/detection/core.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/supervision/classification/core.py b/supervision/classification/core.py index e4535f98..d6087538 100644 --- a/supervision/classification/core.py +++ b/supervision/classification/core.py @@ -44,7 +44,7 @@ class Classifications: @classmethod @deprecated( """ - This method is deprecated and removed in 0.16.0 release. + This method is deprecated and removed in 0.16.0 release. Use sv.Classifications.from_ultralytics() instead as it is more generic and can be used for detections from any ultralytics.engine.results.Results Object """ diff --git a/supervision/detection/core.py b/supervision/detection/core.py index 9aa7d21d..f3395a1c 100644 --- a/supervision/detection/core.py +++ b/supervision/detection/core.py @@ -180,7 +180,7 @@ class Detections: @classmethod @deprecated( """ - This method is deprecated and removed in 0.16.0 release. + This method is deprecated and removed in 0.16.0 release. Use sv.Classifications.from_ultralytics() instead as it is more generic and can be used for detections from any ultralytics.engine.results.Results Object """ From a71d8c254a78c0f2050409035360a8152308163c Mon Sep 17 00:00:00 2001 From: Mayank Agarwal Date: Tue, 15 Aug 2023 11:01:24 +0530 Subject: [PATCH 10/12] fix pre-commit-ci flake8 test --- supervision/classification/core.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/supervision/classification/core.py b/supervision/classification/core.py index d6087538..6834f3d8 100644 --- a/supervision/classification/core.py +++ b/supervision/classification/core.py @@ -79,10 +79,12 @@ class Classifications: @classmethod def from_ultralytics(cls, ultralytics_results) -> Classifications: """ - Creates a Classifications instance from a (https://github.com/ultralytics/ultralytics) inference result. + Creates a Classifications instance from a (https://github.com/ultralytics/ultralytics) + inference result. Args: - ultralytics_results (ultralytics.engine.results.Results): The output Results instance from ultralytics model + ultralytics_results (ultralytics.engine.results.Results): + The output Results instance from ultralytics model Returns: Classifications: A new Classifications object. From 7bd6a107ce0bd4907dc56d0590525fc2b0f388bb Mon Sep 17 00:00:00 2001 From: Mayank Agarwal Date: Tue, 15 Aug 2023 11:02:02 +0530 Subject: [PATCH 11/12] fix pre-commit-ci flake8 test --- supervision/classification/core.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/supervision/classification/core.py b/supervision/classification/core.py index 6834f3d8..e2d21eb3 100644 --- a/supervision/classification/core.py +++ b/supervision/classification/core.py @@ -79,8 +79,8 @@ class Classifications: @classmethod def from_ultralytics(cls, ultralytics_results) -> Classifications: """ - Creates a Classifications instance from a (https://github.com/ultralytics/ultralytics) - inference result. + Creates a Classifications instance from a + (https://github.com/ultralytics/ultralytics) inference result. Args: ultralytics_results (ultralytics.engine.results.Results): From 824b2f6dc2684fd3f108af52c8111b4dd87844ad Mon Sep 17 00:00:00 2001 From: SkalskiP Date: Tue, 15 Aug 2023 12:40:30 +0200 Subject: [PATCH 12/12] =?UTF-8?q?=F0=9F=9B=A0=EF=B8=8F=20small=20fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- supervision/classification/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/supervision/classification/core.py b/supervision/classification/core.py index e2d21eb3..8fcb6f62 100644 --- a/supervision/classification/core.py +++ b/supervision/classification/core.py @@ -103,7 +103,7 @@ class Classifications: >>> classifications = sv.Classifications.from_ultralytics(result) ``` """ - confidence = ultralytics_results.boxes.conf.cpu().numpy() + confidence = ultralytics_results.probs.data.cpu().numpy() return cls(class_id=np.arange(confidence.shape[0]), confidence=confidence) def get_top_k(self, k: int) -> Tuple[np.ndarray, np.ndarray]: