From 845c9cc2c238accd79961953c8b8ca391bcc9c44 Mon Sep 17 00:00:00 2001 From: raghav Date: Sat, 20 Jan 2024 14:19:06 +0530 Subject: [PATCH 01/14] docs: '>>>' and '...' are removed and indentation improvements --- docs/annotators.md | 284 ++++++++++++++++++++++----------------------- 1 file changed, 142 insertions(+), 142 deletions(-) diff --git a/docs/annotators.md b/docs/annotators.md index 316f37e0..112ba121 100644 --- a/docs/annotators.md +++ b/docs/annotators.md @@ -5,16 +5,16 @@ comments: true === "BoundingBox" ```python - >>> import supervision as sv + import supervision as sv - >>> image = ... - >>> detections = sv.Detections(...) + image = + detections = sv.Detections() - >>> bounding_box_annotator = sv.BoundingBoxAnnotator() - >>> annotated_frame = bounding_box_annotator.annotate( - ... scene=image.copy(), - ... detections=detections - ... ) + bounding_box_annotator = sv.BoundingBoxAnnotator() + annotated_frame = bounding_box_annotator.annotate( + scene=image.copy(), + detections=detections + ) ```
@@ -26,16 +26,16 @@ comments: true === "RoundBox" ```python - >>> import supervision as sv + import supervision as sv - >>> image = ... - >>> detections = sv.Detections(...) + image = + detections = sv.Detections() - >>> round_box_annotator = sv.RoundBoxAnnotator() - >>> annotated_frame = round_box_annotator.annotate( - ... scene=image.copy(), - ... detections=detections - ... ) + round_box_annotator = sv.RoundBoxAnnotator() + annotated_frame = round_box_annotator.annotate( + scene=image.copy(), + detections=detections + ) ```
@@ -47,16 +47,16 @@ comments: true === "BoxCorner" ```python - >>> import supervision as sv + import supervision as sv - >>> image = ... - >>> detections = sv.Detections(...) + image = + detections = sv.Detections() - >>> corner_annotator = sv.BoxCornerAnnotator() - >>> annotated_frame = corner_annotator.annotate( - ... scene=image.copy(), - ... detections=detections - ... ) + corner_annotator = sv.BoxCornerAnnotator() + annotated_frame = corner_annotator.annotate( + scene=image.copy(), + detections=detections + ) ```
@@ -68,16 +68,16 @@ comments: true === "Color" ```python - >>> import supervision as sv + import supervision as sv - >>> image = ... - >>> detections = sv.Detections(...) + image = + detections = sv.Detections() - >>> color_annotator = sv.ColorAnnotator() - >>> annotated_frame = color_annotator.annotate( - ... scene=image.copy(), - ... detections=detections - ... ) + color_annotator = sv.ColorAnnotator() + annotated_frame = color_annotator.annotate( + scene=image.copy(), + detections=detections + ) ```
@@ -89,16 +89,16 @@ comments: true === "Circle" ```python - >>> import supervision as sv + import supervision as sv - >>> image = ... - >>> detections = sv.Detections(...) + image = + detections = sv.Detections() - >>> circle_annotator = sv.CircleAnnotator() - >>> annotated_frame = circle_annotator.annotate( - ... scene=image.copy(), - ... detections=detections - ... ) + circle_annotator = sv.CircleAnnotator() + annotated_frame = circle_annotator.annotate( + scene=image.copy(), + detections=detections + ) ```
@@ -110,16 +110,16 @@ comments: true === "Dot" ```python - >>> import supervision as sv + import supervision as sv - >>> image = ... - >>> detections = sv.Detections(...) + image = + detections = sv.Detections() - >>> dot_annotator = sv.DotAnnotator() - >>> annotated_frame = dot_annotator.annotate( - ... scene=image.copy(), - ... detections=detections - ... ) + dot_annotator = sv.DotAnnotator() + annotated_frame = dot_annotator.annotate( + scene=image.copy(), + detections=detections + ) ```
@@ -131,16 +131,16 @@ comments: true === "Triangle" ```python - >>> import supervision as sv + import supervision as sv - >>> image = ... - >>> detections = sv.Detections(...) + image = + detections = sv.Detections() - >>> triangle_annotator = sv.TriangleAnnotator() - >>> annotated_frame = triangle_annotator.annotate( - ... scene=image.copy(), - ... detections=detections - ... ) + triangle_annotator = sv.TriangleAnnotator() + annotated_frame = triangle_annotator.annotate( + scene=image.copy(), + detections=detections + ) ```
@@ -152,16 +152,16 @@ comments: true === "Ellipse" ```python - >>> import supervision as sv + import supervision as sv - >>> image = ... - >>> detections = sv.Detections(...) + image = + detections = sv.Detections() - >>> ellipse_annotator = sv.EllipseAnnotator() - >>> annotated_frame = ellipse_annotator.annotate( - ... scene=image.copy(), - ... detections=detections - ... ) + ellipse_annotator = sv.EllipseAnnotator() + annotated_frame = ellipse_annotator.annotate( + scene=image.copy(), + detections=detections + ) ```
@@ -173,16 +173,16 @@ comments: true === "Halo" ```python - >>> import supervision as sv + import supervision as sv - >>> image = ... - >>> detections = sv.Detections(...) + image = + detections = sv.Detections() - >>> halo_annotator = sv.HaloAnnotator() - >>> annotated_frame = halo_annotator.annotate( - ... scene=image.copy(), - ... detections=detections - ... ) + halo_annotator = sv.HaloAnnotator() + annotated_frame = halo_annotator.annotate( + scene=image.copy(), + detections=detections + ) ```
@@ -194,16 +194,16 @@ comments: true === "Mask" ```python - >>> import supervision as sv + import supervision as sv - >>> image = ... - >>> detections = sv.Detections(...) + image = + detections = sv.Detectio - >>> mask_annotator = sv.MaskAnnotator() - >>> annotated_frame = mask_annotator.annotate( - ... scene=image.copy(), - ... detections=detections - ... ) + mask_annotator = sv.MaskAnnotator() + annotated_frame = mask_annotator.annotate( + scene=image.copy(), + detections=detections + ) ```
@@ -215,16 +215,16 @@ comments: true === "Polygon" ```python - >>> import supervision as sv + import supervision as sv - >>> image = ... - >>> detections = sv.Detections(...) + image = + detections = sv.Detections() - >>> polygon_annotator = sv.PolygonAnnotator() - >>> annotated_frame = polygon_annotator.annotate( - ... scene=image.copy(), - ... detections=detections - ... ) + polygon_annotator = sv.PolygonAnnotator() + annotated_frame = polygon_annotator.annotate( + scene=image.copy(), + detections=detections + ) ```
@@ -236,16 +236,16 @@ comments: true === "Label" ```python - >>> import supervision as sv + import supervision as sv - >>> image = ... - >>> detections = sv.Detections(...) + image = + detections = sv.Detections() - >>> label_annotator = sv.LabelAnnotator(text_position=sv.Position.CENTER) - >>> annotated_frame = label_annotator.annotate( - ... scene=image.copy(), - ... detections=detections - ... ) + label_annotator = sv.LabelAnnotator(text_position=sv.Position.CENTER) + annotated_frame = label_annotator.annotate( + scene=image.copy(), + detections=detections + ) ```
@@ -257,16 +257,16 @@ comments: true === "Blur" ```python - >>> import supervision as sv + import supervision as sv - >>> image = ... - >>> detections = sv.Detections(...) + image = + detections = sv.Detections() - >>> blur_annotator = sv.BlurAnnotator() - >>> annotated_frame = blur_annotator.annotate( - ... scene=image.copy(), - ... detections=detections - ... ) + blur_annotator = sv.BlurAnnotator() + annotated_frame = blur_annotator.annotate( + scene=image.copy(), + detections=detections + ) ```
@@ -278,16 +278,16 @@ comments: true === "Pixelate" ```python - >>> import supervision as sv + import supervision as sv - >>> image = ... - >>> detections = sv.Detections(...) + image = + detections = sv.Detections() - >>> pixelate_annotator = sv.PixelateAnnotator() - >>> annotated_frame = pixelate_annotator.annotate( - ... scene=image.copy(), - ... detections=detections - ... ) + pixelate_annotator = sv.PixelateAnnotator() + annotated_frame = pixelate_annotator.annotate( + scene=image.copy(), + detections=detections + ) ```
@@ -299,26 +299,26 @@ comments: true === "Trace" ```python - >>> import supervision as sv - >>> from ultralytics import YOLO + import supervision as sv + from ultralytics import YOLO - >>> model = YOLO('yolov8x.pt') + model = YOLO('yolov8x.pt') - >>> trace_annotator = sv.TraceAnnotator() + trace_annotator = sv.TraceAnnotator() - >>> video_info = sv.VideoInfo.from_video_path(video_path='...') - >>> frames_generator = get_video_frames_generator(source_path='...') - >>> tracker = sv.ByteTrack() + video_info = sv.VideoInfo.from_video_path(video_path='...') + frames_generator = get_video_frames_generator(source_path='...') + tracker = sv.ByteTrack() - >>> with sv.VideoSink(target_path='...', video_info=video_info) as sink: - ... for frame in frames_generator: - ... result = model(frame)[0] - ... detections = sv.Detections.from_ultralytics(result) - ... detections = tracker.update_with_detections(detections) - ... annotated_frame = trace_annotator.annotate( - ... scene=frame.copy(), - ... detections=detections) - ... sink.write_frame(frame=annotated_frame) + with sv.VideoSink(target_path='...', video_info=video_info) as sink: + for frame in frames_generator: + result = model(frame)[0] + detections = sv.Detections.from_ultralytics(result) + detections = tracker.update_with_detections(detections) + annotated_frame = trace_annotator.annotate( + scene=frame.copy(), + detections=detections) + sink.write_frame(frame=annotated_frame) ```
@@ -330,24 +330,24 @@ comments: true === "HeatMap" ```python - >>> import supervision as sv - >>> from ultralytics import YOLO + import supervision as sv + from ultralytics import YOLO - >>> model = YOLO('yolov8x.pt') + model = YOLO('yolov8x.pt') - >>> heat_map_annotator = sv.HeatMapAnnotator() + heat_map_annotator = sv.HeatMapAnnotator() - >>> video_info = sv.VideoInfo.from_video_path(video_path='...') - >>> frames_generator = get_video_frames_generator(source_path='...') + video_info = sv.VideoInfo.from_video_path(video_path='...') + frames_generator = get_video_frames_generator(source_path='...') - >>> with sv.VideoSink(target_path='...', video_info=video_info) as sink: - ... for frame in frames_generator: - ... result = model(frame)[0] - ... detections = sv.Detections.from_ultralytics(result) - ... annotated_frame = heat_map_annotator.annotate( - ... scene=frame.copy(), - ... detections=detections) - ... sink.write_frame(frame=annotated_frame) + with sv.VideoSink(target_path='...', video_info=video_info) as sink: + for frame in frames_generator: + result = model(frame)[0] + detections = sv.Detections.from_ultralytics(result) + annotated_frame = heat_map_annotator.annotate( + scene=frame.copy(), + detections=detections) + sink.write_frame(frame=annotated_frame) ```
From d961aa9eb4ad595bff94f5471f82889488e92b62 Mon Sep 17 00:00:00 2001 From: raghav Date: Sun, 21 Jan 2024 12:06:10 +0530 Subject: [PATCH 02/14] docs: example image = ... reverted and added annotators.md --- docs/annotators.md | 56 +++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/docs/annotators.md b/docs/annotators.md index 112ba121..3c2cc95f 100644 --- a/docs/annotators.md +++ b/docs/annotators.md @@ -7,8 +7,8 @@ comments: true ```python import supervision as sv - image = - detections = sv.Detections() + image = ... + detections = sv.Detections(...) bounding_box_annotator = sv.BoundingBoxAnnotator() annotated_frame = bounding_box_annotator.annotate( @@ -28,8 +28,8 @@ comments: true ```python import supervision as sv - image = - detections = sv.Detections() + image = ... + detections = sv.Detections(...) round_box_annotator = sv.RoundBoxAnnotator() annotated_frame = round_box_annotator.annotate( @@ -49,8 +49,8 @@ comments: true ```python import supervision as sv - image = - detections = sv.Detections() + image = ... + detections = sv.Detections(...) corner_annotator = sv.BoxCornerAnnotator() annotated_frame = corner_annotator.annotate( @@ -70,8 +70,8 @@ comments: true ```python import supervision as sv - image = - detections = sv.Detections() + image = ... + detections = sv.Detections(...) color_annotator = sv.ColorAnnotator() annotated_frame = color_annotator.annotate( @@ -91,8 +91,8 @@ comments: true ```python import supervision as sv - image = - detections = sv.Detections() + image = ... + detections = sv.Detections(...) circle_annotator = sv.CircleAnnotator() annotated_frame = circle_annotator.annotate( @@ -112,8 +112,8 @@ comments: true ```python import supervision as sv - image = - detections = sv.Detections() + image = ... + detections = sv.Detections(...) dot_annotator = sv.DotAnnotator() annotated_frame = dot_annotator.annotate( @@ -133,8 +133,8 @@ comments: true ```python import supervision as sv - image = - detections = sv.Detections() + image = ... + detections = sv.Detections(...) triangle_annotator = sv.TriangleAnnotator() annotated_frame = triangle_annotator.annotate( @@ -154,8 +154,8 @@ comments: true ```python import supervision as sv - image = - detections = sv.Detections() + image = ... + detections = sv.Detections(...) ellipse_annotator = sv.EllipseAnnotator() annotated_frame = ellipse_annotator.annotate( @@ -175,8 +175,8 @@ comments: true ```python import supervision as sv - image = - detections = sv.Detections() + image = ... + detections = sv.Detections(...) halo_annotator = sv.HaloAnnotator() annotated_frame = halo_annotator.annotate( @@ -196,8 +196,8 @@ comments: true ```python import supervision as sv - image = - detections = sv.Detectio + image = ... + detections = sv.Detections(...) mask_annotator = sv.MaskAnnotator() annotated_frame = mask_annotator.annotate( @@ -217,8 +217,8 @@ comments: true ```python import supervision as sv - image = - detections = sv.Detections() + image = ... + detections = sv.Detections(...) polygon_annotator = sv.PolygonAnnotator() annotated_frame = polygon_annotator.annotate( @@ -238,8 +238,8 @@ comments: true ```python import supervision as sv - image = - detections = sv.Detections() + image = ... + detections = sv.Detections(...) label_annotator = sv.LabelAnnotator(text_position=sv.Position.CENTER) annotated_frame = label_annotator.annotate( @@ -259,8 +259,8 @@ comments: true ```python import supervision as sv - image = - detections = sv.Detections() + image = ... + detections = sv.Detections(...) blur_annotator = sv.BlurAnnotator() annotated_frame = blur_annotator.annotate( @@ -280,8 +280,8 @@ comments: true ```python import supervision as sv - image = - detections = sv.Detections() + image = ... + detections = sv.Detections(...) pixelate_annotator = sv.PixelateAnnotator() annotated_frame = pixelate_annotator.annotate( From 8872151d0c98e91b1e4c7cbd766c8b5213ffbf6f Mon Sep 17 00:00:00 2001 From: Onuralp SEZER Date: Wed, 24 Jan 2024 12:28:45 +0300 Subject: [PATCH 03/14] =?UTF-8?q?docs:=20=F0=9F=93=9D=20core/detection/cor?= =?UTF-8?q?e.py=20>>>/...=20removed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Onuralp SEZER --- supervision/detection/core.py | 290 +++++++++++++++++----------------- 1 file changed, 143 insertions(+), 147 deletions(-) diff --git a/supervision/detection/core.py b/supervision/detection/core.py index 39e129e1..6ade4bbf 100644 --- a/supervision/detection/core.py +++ b/supervision/detection/core.py @@ -126,14 +126,14 @@ class Detections: Example: ```python - >>> import cv2 - >>> import torch - >>> import supervision as sv + import cv2 + import torch + import supervision as sv - >>> image = cv2.imread(SOURCE_IMAGE_PATH) - >>> model = torch.hub.load('ultralytics/yolov5', 'yolov5s') - >>> result = model(image) - >>> detections = sv.Detections.from_yolov5(result) + image = cv2.imread(SOURCE_IMAGE_PATH) + model = torch.hub.load('ultralytics/yolov5', 'yolov5s') + result = model(image) + detections = sv.Detections.from_yolov5(result) ``` """ yolov5_detections_predictions = yolov5_results.pred[0].cpu().cpu().numpy() @@ -159,14 +159,14 @@ class Detections: Example: ```python - >>> import cv2 - >>> import supervision as sv - >>> from ultralytics import YOLO + import cv2 + import supervision as sv + from ultralytics import YOLO - >>> image = cv2.imread(...) - >>> model = YOLO('yolov8s.pt') - >>> result = model(image)[0] - >>> detections = sv.Detections.from_ultralytics(result) + image = cv2.imread() + model = YOLO('yolov8s.pt') + result = model(image)[0] + detections = sv.Detections.from_ultralytics(result) ``` """ @@ -198,14 +198,14 @@ class Detections: Example: ```python - >>> import cv2 - >>> from super_gradients.training import models - >>> import supervision as sv + import cv2 + from super_gradients.training import models + import supervision as sv - >>> image = cv2.imread(SOURCE_IMAGE_PATH) - >>> model = models.get('yolo_nas_l', pretrained_weights="coco") - >>> result = list(model.predict(image, conf=0.35))[0] - >>> detections = sv.Detections.from_yolo_nas(result) + image = cv2.imread(SOURCE_IMAGE_PATH) + model = models.get('yolo_nas_l', pretrained_weights="coco") + result = list(model.predict(image, conf=0.35))[0] + detections = sv.Detections.from_yolo_nas(result) ``` """ if np.asarray(yolo_nas_results.prediction.bboxes_xyxy).shape[0] == 0: @@ -235,20 +235,16 @@ class Detections: Example: ```python - >>> import tensorflow as tf - >>> import tensorflow_hub as hub - >>> import numpy as np - >>> import cv2 + import tensorflow as tf + import tensorflow_hub as hub + import numpy as np + import cv2 - >>> module_handle = "https://tfhub.dev/tensorflow/centernet/hourglass_512x512_kpts/1" - - >>> model = hub.load(module_handle) - - >>> img = np.array(cv2.imread(SOURCE_IMAGE_PATH)) - - >>> result = model(img) - - >>> detections = sv.Detections.from_tensorflow(result) + module_handle = "https://tfhub.dev/tensorflow/centernet/hourglass_512x512_kpts/1" + model = hub.load(module_handle) + img = np.array(cv2.imread(SOURCE_IMAGE_PATH)) + result = model(img) + detections = sv.Detections.from_tensorflow(result) ``` """ # noqa: E501 // docs @@ -278,15 +274,15 @@ class Detections: Example: ```python - >>> import supervision as sv - >>> from deepsparse import Pipeline + import supervision as sv + from deepsparse import Pipeline - >>> yolo_pipeline = Pipeline.create( - ... task="yolo", - ... model_path = "zoo:cv/detection/yolov5-l/pytorch/ultralytics/coco/pruned80_quant-none" - ... ) - >>> result = yolo_pipeline() - >>> detections = sv.Detections.from_deepsparse(result) + yolo_pipeline = Pipeline.create( + task="yolo", + model_path = "zoo:cv/detection/yolov5-l/pytorch/ultralytics/coco/pruned80_quant-none" + ) + result = yolo_pipeline() + detections = sv.Detections.from_deepsparse(result) ``` """ # noqa: E501 // docs @@ -315,14 +311,14 @@ class Detections: Example: ```python - >>> import cv2 - >>> import supervision as sv - >>> from mmdet.apis import DetInferencer + import cv2 + import supervision as sv + from mmdet.apis import DetInferencer - >>> inferencer = DetInferencer(model_name, checkpoint, device) - >>> mmdet_result = inferencer(SOURCE_IMAGE_PATH, out_dir='./output', - ... return_datasamples=True)["predictions"][0] - >>> detections = sv.Detections.from_mmdetection(mmdet_result) + inferencer = DetInferencer(model_name, checkpoint, device) + mmdet_result = inferencer(SOURCE_IMAGE_PATH, out_dir='./output', + return_datasamples=True)["predictions"][0] + detections = sv.Detections.from_mmdetection(mmdet_result) ``` """ @@ -364,18 +360,18 @@ class Detections: Example: ```python - >>> import cv2 - >>> from detectron2.engine import DefaultPredictor - >>> from detectron2.config import get_cfg - >>> import supervision as sv + import cv2 + from detectron2.engine import DefaultPredictor + from detectron2.config import get_cfg + import supervision as sv - >>> image = cv2.imread(SOURCE_IMAGE_PATH) - >>> cfg = get_cfg() - >>> cfg.merge_from_file("path/to/config.yaml") - >>> cfg.MODEL.WEIGHTS = "path/to/model_weights.pth" - >>> predictor = DefaultPredictor(cfg) - >>> result = predictor(image) - >>> detections = sv.Detections.from_detectron2(result) + image = cv2.imread(SOURCE_IMAGE_PATH) + cfg = get_cfg() + cfg.merge_from_file("path/to/config.yaml") + cfg.MODEL.WEIGHTS = "path/to/model_weights.pth" + predictor = DefaultPredictor(cfg) + result = predictor(image) + detections = sv.Detections.from_detectron2(result) ``` """ @@ -412,14 +408,14 @@ class Detections: Example: ```python - >>> import cv2 - >>> import supervision as sv - >>> from inference.models.utils import get_roboflow_model + import cv2 + import supervision as sv + from inference.models.utils import get_roboflow_model - >>> image = cv2.imread(...) - >>> model = get_roboflow_model(model_id="yolov8s-640") - >>> result = model.infer(image)[0] - >>> detections = sv.Detections.from_inference(result) + image = cv2.imread() + model = get_roboflow_model(model_id="yolov8s-640") + result = model.infer(image)[0] + detections = sv.Detections.from_inference(result) ``` """ with suppress(AttributeError): @@ -461,14 +457,14 @@ class Detections: Example: ```python - >>> import cv2 - >>> import supervision as sv - >>> from inference.models.utils import get_roboflow_model + import cv2 + import supervision as sv + from inference.models.utils import get_roboflow_model - >>> image = cv2.imread(...) - >>> model = get_roboflow_model(model_id="yolov8s-640") - >>> result = model.infer(image)[0] - >>> detections = sv.Detections.from_roboflow(result) + image = cv2.imread() + model = get_roboflow_model(model_id="yolov8s-640") + result = model.infer(image)[0] + detections = sv.Detections.from_roboflow(result) ``` """ return cls.from_inference(roboflow_result) @@ -488,17 +484,17 @@ class Detections: Example: ```python - >>> import supervision as sv - >>> from segment_anything import ( - ... sam_model_registry, - ... SamAutomaticMaskGenerator - ... ) + import supervision as sv + from segment_anything import ( + sam_model_registry, + SamAutomaticMaskGenerator + ) - >>> sam_model_reg = sam_model_registry[MODEL_TYPE] - >>> sam = sam_model_reg(checkpoint=CHECKPOINT_PATH).to(device=DEVICE) - >>> mask_generator = SamAutomaticMaskGenerator(sam) - >>> sam_result = mask_generator.generate(IMAGE) - >>> detections = sv.Detections.from_sam(sam_result=sam_result) + sam_model_reg = sam_model_registry[MODEL_TYPE] + sam = sam_model_reg(checkpoint=CHECKPOINT_PATH).to(device=DEVICE) + mask_generator = SamAutomaticMaskGenerator(sam) + sam_result = mask_generator.generate(IMAGE) + detections = sv.Detections.from_sam(sam_result=sam_result) ``` """ @@ -535,25 +531,25 @@ class Detections: Example: ```python - >>> import requests - >>> import supervision as sv + import requests + import supervision as sv - >>> image = open(input, "rb").read() + image = open(input, "rb").read() - >>> endpoint = "https://.cognitiveservices.azure.com/" - >>> subscription_key = "..." + endpoint = "https://.cognitiveservices.azure.com/" + subscription_key = "" - >>> headers = { - ... "Content-Type": "application/octet-stream", - ... "Ocp-Apim-Subscription-Key": subscription_key - ... } + headers = { + "Content-Type": "application/octet-stream", + "Ocp-Apim-Subscription-Key": subscription_key + } - >>> response = requests.post(endpoint, - ... headers=self.headers, - ... data=image - ... ).json() + response = requests.post(endpoint, + headers=self.headers, + data=image + ).json() - >>> detections = sv.Detections.from_azure_analyze_image(response) + detections = sv.Detections.from_azure_analyze_image(response) ``` """ if "error" in azure_result: @@ -617,21 +613,21 @@ class Detections: Example: ```python - >>> import supervision as sv - >>> import paddle - >>> from ppdet.engine import Trainer - >>> from ppdet.core.workspace import load_config + import supervision as sv + import paddle + from ppdet.engine import Trainer + from ppdet.core.workspace import load_config - >>> weights = (...) - >>> config = (...) + weights = () + config = () - >>> cfg = load_config(config) - >>> trainer = Trainer(cfg, mode='test') - >>> trainer.load_weights(weights) + cfg = load_config(config) + trainer = Trainer(cfg, mode='test') + trainer.load_weights(weights) - >>> paddledet_result = trainer.predict([images])[0] + paddledet_result = trainer.predict([images])[0] - >>> detections = sv.Detections.from_paddledet(paddledet_result) + detections = sv.Detections.from_paddledet(paddledet_result) ``` """ @@ -655,9 +651,9 @@ class Detections: Example: ```python - >>> from supervision import Detections + from supervision import Detections - >>> empty_detections = Detections.empty() + empty_detections = Detections.empty() ``` """ return cls( @@ -689,29 +685,29 @@ class Detections: import numpy as np import supervision as sv - >>> detections_1 = sv.Detections( - ... xyxy=np.array([[15, 15, 100, 100], [200, 200, 300, 300]]), - ... class_id=np.array([1, 2]), - ... data={'feature_vector': np.array([0.1, 0.2)])} - ... ) + detections_1 = sv.Detections( + xyxy=np.array([[15, 15, 100, 100], [200, 200, 300, 300]]), + class_id=np.array([1, 2]), + data={'feature_vector': np.array([0.1, 0.2)])} + ) - >>> detections_2 = sv.Detections( - ... xyxy=np.array([[30, 30, 120, 120]]), - ... class_id=np.array([1]), - ... data={'feature_vector': [np.array([0.3])]} - ... ) + detections_2 = sv.Detections( + xyxy=np.array([[30, 30, 120, 120]]), + class_id=np.array([1]), + data={'feature_vector': [np.array([0.3])]} + ) - >>> merged_detections = Detections.merge([detections_1, detections_2]) + merged_detections = Detections.merge([detections_1, detections_2]) - >>> merged_detections.xyxy + merged_detections.xyxy array([[ 15, 15, 100, 100], [200, 200, 300, 300], [ 30, 30, 120, 120]]) - >>> merged_detections.class_id + merged_detections.class_id array([1, 2, 1]) - >>> merged_detections.data['feature_vector'] + merged_detections.data['feature_vector'] array([0.1, 0.2, 0.3]) ``` """ @@ -844,17 +840,17 @@ class Detections: Example: ```python - >>> import supervision as sv + import supervision as sv - >>> detections = sv.Detections(...) + detections = sv.Detections() - >>> first_detection = detections[0] - >>> first_10_detections = detections[0:10] - >>> some_detections = detections[[0, 2, 4]] - >>> class_0_detections = detections[detections.class_id == 0] - >>> high_confidence_detections = detections[detections.confidence > 0.5] + first_detection = detections[0] + first_10_detections = detections[0:10] + some_detections = detections[[0, 2, 4]] + class_0_detections = detections[detections.class_id == 0] + high_confidence_detections = detections[detections.confidence > 0.5] - >>> feature_vector = detections['feature_vector'] + feature_vector = detections['feature_vector'] ``` """ if isinstance(index, str): @@ -880,22 +876,22 @@ class Detections: Example: ```python - >>> import cv2 - >>> from ultralytics import YOLO - >>> import supervision as sv + import cv2 + from ultralytics import YOLO + import supervision as sv - >>> model = YOLO('yolov8s.pt') + model = YOLO('yolov8s.pt') - >>> image = cv2.imread(SOURCE_IMAGE_PATH) + image = cv2.imread(SOURCE_IMAGE_PATH) - >>> result = model(image)[0] - >>> detections = sv.Detections.from_ultralytics(result) + result = model(image)[0] + detections = sv.Detections.from_ultralytics(result) - >>> detections['names'] = [ - ... model.model.names[class_id] - ... for class_id - ... in detections.class_id - ... ] + detections['names'] = [ + model.model.names[class_id] + for class_id + in detections.class_id + ] ``` """ if not isinstance(value, (np.ndarray, list)): @@ -915,7 +911,7 @@ class Detections: Returns: np.ndarray: An array of floats containing the area of each detection - in the format of `(area_1, area_2, ..., area_n)`, + in the format of `(area_1, area_2, , area_n)`, where n is the number of detections. """ if self.mask is not None: @@ -930,7 +926,7 @@ class Detections: Returns: np.ndarray: An array of floats containing the area of each bounding - box in the format of `(area_1, area_2, ..., area_n)`, + box in the format of `(area_1, area_2, , area_n)`, where n is the number of detections. """ return (self.xyxy[:, 3] - self.xyxy[:, 1]) * (self.xyxy[:, 2] - self.xyxy[:, 0]) From 7af914bf564a6bb8980918bbc3a8bc5ebeee1b30 Mon Sep 17 00:00:00 2001 From: Onuralp SEZER Date: Wed, 24 Jan 2024 12:50:23 +0300 Subject: [PATCH 04/14] =?UTF-8?q?docs:=20=F0=9F=93=9D=20supervision/annota?= =?UTF-8?q?tors/core.py=20docs/annotators.md=20>>>/...=20removed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Onuralp SEZER --- docs/annotators.md | 34 ++-- supervision/annotators/core.py | 285 ++++++++++++++++----------------- 2 files changed, 159 insertions(+), 160 deletions(-) diff --git a/docs/annotators.md b/docs/annotators.md index 3c2cc95f..75482f50 100644 --- a/docs/annotators.md +++ b/docs/annotators.md @@ -5,16 +5,16 @@ comments: true === "BoundingBox" ```python - import supervision as sv + import supervision as sv - image = ... - detections = sv.Detections(...) + image = ... + detections = sv.Detections(...) - bounding_box_annotator = sv.BoundingBoxAnnotator() - annotated_frame = bounding_box_annotator.annotate( + bounding_box_annotator = sv.BoundingBoxAnnotator() + annotated_frame = bounding_box_annotator.annotate( scene=image.copy(), detections=detections - ) + ) ```
@@ -26,16 +26,16 @@ comments: true === "RoundBox" ```python - import supervision as sv + import supervision as sv - image = ... - detections = sv.Detections(...) + image = ... + detections = sv.Detections(...) - round_box_annotator = sv.RoundBoxAnnotator() - annotated_frame = round_box_annotator.annotate( - scene=image.copy(), - detections=detections - ) + round_box_annotator = sv.RoundBoxAnnotator() + annotated_frame = round_box_annotator.annotate( + scene=image.copy(), + detections=detections + ) ```
@@ -54,9 +54,9 @@ comments: true corner_annotator = sv.BoxCornerAnnotator() annotated_frame = corner_annotator.annotate( - scene=image.copy(), - detections=detections - ) + scene=image.copy(), + detections=detections + ) ```
diff --git a/supervision/annotators/core.py b/supervision/annotators/core.py index 9ae81c95..7960d7ec 100644 --- a/supervision/annotators/core.py +++ b/supervision/annotators/core.py @@ -57,16 +57,16 @@ class BoundingBoxAnnotator(BaseAnnotator): Example: ```python - >>> import supervision as sv + import supervision as sv - >>> image = ... - >>> detections = sv.Detections(...) + image = ... + detections = sv.Detections(...) - >>> bounding_box_annotator = sv.BoundingBoxAnnotator() - >>> annotated_frame = bounding_box_annotator.annotate( - ... scene=image.copy(), - ... detections=detections - ... ) + bounding_box_annotator = sv.BoundingBoxAnnotator() + annotated_frame = bounding_box_annotator.annotate( + scene=image.copy(), + detections=detections + ) ``` ![bounding-box-annotator-example](https://media.roboflow.com/ @@ -139,16 +139,16 @@ class MaskAnnotator(BaseAnnotator): Example: ```python - >>> import supervision as sv + import supervision as sv - >>> image = ... - >>> detections = sv.Detections(...) + image = ... + detections = sv.Detections(...) - >>> mask_annotator = sv.MaskAnnotator() - >>> annotated_frame = mask_annotator.annotate( - ... scene=image.copy(), - ... detections=detections - ... ) + mask_annotator = sv.MaskAnnotator() + annotated_frame = mask_annotator.annotate( + scene=image.copy(), + detections=detections + ) ``` ![mask-annotator-example](https://media.roboflow.com/ @@ -222,16 +222,16 @@ class PolygonAnnotator(BaseAnnotator): Example: ```python - >>> import supervision as sv + import supervision as sv - >>> image = ... - >>> detections = sv.Detections(...) + image = ... + detections = sv.Detections(...) - >>> polygon_annotator = sv.PolygonAnnotator() - >>> annotated_frame = polygon_annotator.annotate( - ... scene=image.copy(), - ... detections=detections - ... ) + polygon_annotator = sv.PolygonAnnotator() + annotated_frame = polygon_annotator.annotate( + scene=image.copy(), + detections=detections + ) ``` ![polygon-annotator-example](https://media.roboflow.com/ @@ -304,16 +304,16 @@ class ColorAnnotator(BaseAnnotator): Example: ```python - >>> import supervision as sv + import supervision as sv - >>> image = ... - >>> detections = sv.Detections(...) + image = ... + detections = sv.Detections(...) - >>> color_annotator = sv.ColorAnnotator() - >>> annotated_frame = color_annotator.annotate( - ... scene=image.copy(), - ... detections=detections - ... ) + color_annotator = sv.ColorAnnotator() + annotated_frame = color_annotator.annotate( + scene=image.copy(), + detections=detections + ) ``` ![box-mask-annotator-example](https://media.roboflow.com/ @@ -394,16 +394,16 @@ class HaloAnnotator(BaseAnnotator): Example: ```python - >>> import supervision as sv + import supervision as sv - >>> image = ... - >>> detections = sv.Detections(...) + image = ... + detections = sv.Detections(...) - >>> halo_annotator = sv.HaloAnnotator() - >>> annotated_frame = halo_annotator.annotate( - ... scene=image.copy(), - ... detections=detections - ... ) + halo_annotator = sv.HaloAnnotator() + annotated_frame = halo_annotator.annotate( + scene=image.copy(), + detections=detections + ) ``` ![halo-annotator-example](https://media.roboflow.com/ @@ -488,16 +488,16 @@ class EllipseAnnotator(BaseAnnotator): Example: ```python - >>> import supervision as sv + import supervision as sv - >>> image = ... - >>> detections = sv.Detections(...) + image = ... + detections = sv.Detections(...) - >>> ellipse_annotator = sv.EllipseAnnotator() - >>> annotated_frame = ellipse_annotator.annotate( - ... scene=image.copy(), - ... detections=detections - ... ) + ellipse_annotator = sv.EllipseAnnotator() + annotated_frame = ellipse_annotator.annotate( + scene=image.copy(), + detections=detections + ) ``` ![ellipse-annotator-example](https://media.roboflow.com/ @@ -575,16 +575,16 @@ class BoxCornerAnnotator(BaseAnnotator): Example: ```python - >>> import supervision as sv + import supervision as sv - >>> image = ... - >>> detections = sv.Detections(...) + image = ... + detections = sv.Detections(...) - >>> corner_annotator = sv.BoxCornerAnnotator() - >>> annotated_frame = corner_annotator.annotate( - ... scene=image.copy(), - ... detections=detections - ... ) + corner_annotator = sv.BoxCornerAnnotator() + annotated_frame = corner_annotator.annotate( + scene=image.copy(), + detections=detections + ) ``` ![box-corner-annotator-example](https://media.roboflow.com/ @@ -659,16 +659,16 @@ class CircleAnnotator(BaseAnnotator): Example: ```python - >>> import supervision as sv + import supervision as sv - >>> image = ... - >>> detections = sv.Detections(...) + image = ... + detections = sv.Detections(...) - >>> circle_annotator = sv.CircleAnnotator() - >>> annotated_frame = circle_annotator.annotate( - ... scene=image.copy(), - ... detections=detections - ... ) + circle_annotator = sv.CircleAnnotator() + annotated_frame = circle_annotator.annotate( + scene=image.copy(), + detections=detections + ) ``` @@ -745,16 +745,16 @@ class DotAnnotator(BaseAnnotator): Example: ```python - >>> import supervision as sv + import supervision as sv - >>> image = ... - >>> detections = sv.Detections(...) + image = ... + detections = sv.Detections(...) - >>> dot_annotator = sv.DotAnnotator() - >>> annotated_frame = dot_annotator.annotate( - ... scene=image.copy(), - ... detections=detections - ... ) + dot_annotator = sv.DotAnnotator() + annotated_frame = dot_annotator.annotate( + scene=image.copy(), + detections=detections + ) ``` ![dot-annotator-example](https://media.roboflow.com/ @@ -872,16 +872,16 @@ class LabelAnnotator: Example: ```python - >>> import supervision as sv + import supervision as sv - >>> image = ... - >>> detections = sv.Detections(...) + image = ... + detections = sv.Detections(...) - >>> label_annotator = sv.LabelAnnotator(text_position=sv.Position.CENTER) - >>> annotated_frame = label_annotator.annotate( - ... scene=image.copy(), - ... detections=detections - ... ) + label_annotator = sv.LabelAnnotator(text_position=sv.Position.CENTER) + annotated_frame = label_annotator.annotate( + scene=image.copy(), + detections=detections + ) ``` ![label-annotator-example](https://media.roboflow.com/ @@ -986,16 +986,16 @@ class BlurAnnotator(BaseAnnotator): Example: ```python - >>> import supervision as sv + import supervision as sv - >>> image = ... - >>> detections = sv.Detections(...) + image = ... + detections = sv.Detections(...) - >>> blur_annotator = sv.BlurAnnotator() - >>> annotated_frame = circle_annotator.annotate( - ... scene=image.copy(), - ... detections=detections - ... ) + blur_annotator = sv.BlurAnnotator() + annotated_frame = circle_annotator.annotate( + scene=image.copy(), + detections=detections + ) ``` ![blur-annotator-example](https://media.roboflow.com/ @@ -1071,26 +1071,25 @@ class TraceAnnotator: Example: ```python - >>> import supervision as sv - >>> from ultralytics import YOLO + import supervision as sv + from ultralytics import YOLO - >>> model = YOLO('yolov8x.pt') + model = YOLO('yolov8x.pt') + trace_annotator = sv.TraceAnnotator() - >>> trace_annotator = sv.TraceAnnotator() + video_info = sv.VideoInfo.from_video_path(video_path='...') + frames_generator = sv.get_video_frames_generator(source_path='...') + tracker = sv.ByteTrack() - >>> video_info = sv.VideoInfo.from_video_path(video_path='...') - >>> frames_generator = sv.get_video_frames_generator(source_path='...') - >>> tracker = sv.ByteTrack() - - >>> with sv.VideoSink(target_path='...', video_info=video_info) as sink: - ... for frame in frames_generator: - ... result = model(frame)[0] - ... detections = sv.Detections.from_ultralytics(result) - ... detections = tracker.update_with_detections(detections) - ... annotated_frame = trace_annotator.annotate( - ... scene=frame.copy(), - ... detections=detections) - ... sink.write_frame(frame=annotated_frame) + with sv.VideoSink(target_path='...', video_info=video_info) as sink: + for frame in frames_generator: + result = model(frame)[0] + detections = sv.Detections.from_ultralytics(result) + detections = tracker.update_with_detections(detections) + annotated_frame = trace_annotator.annotate( + scene=frame.copy(), + detections=detections) + sink.write_frame(frame=annotated_frame) ``` ![trace-annotator-example](https://media.roboflow.com/ @@ -1167,24 +1166,24 @@ class HeatMapAnnotator: Example: ```python - >>> import supervision as sv - >>> from ultralytics import YOLO + import supervision as sv + from ultralytics import YOLO - >>> model = YOLO('yolov8x.pt') + model = YOLO('yolov8x.pt') - >>> heat_map_annotator = sv.HeatMapAnnotator() + heat_map_annotator = sv.HeatMapAnnotator() - >>> video_info = sv.VideoInfo.from_video_path(video_path='...') - >>> frames_generator = get_video_frames_generator(source_path='...') + video_info = sv.VideoInfo.from_video_path(video_path='...') + frames_generator = get_video_frames_generator(source_path='...') - >>> with sv.VideoSink(target_path='...', video_info=video_info) as sink: - ... for frame in frames_generator: - ... result = model(frame)[0] - ... detections = sv.Detections.from_ultralytics(result) - ... annotated_frame = heat_map_annotator.annotate( - ... scene=frame.copy(), - ... detections=detections) - ... sink.write_frame(frame=annotated_frame) + with sv.VideoSink(target_path='...', video_info=video_info) as sink: + for frame in frames_generator: + result = model(frame)[0] + detections = sv.Detections.from_ultralytics(result) + annotated_frame = heat_map_annotator.annotate( + scene=frame.copy(), + detections=detections) + sink.write_frame(frame=annotated_frame) ``` ![heatmap-annotator-example](https://media.roboflow.com/ @@ -1244,16 +1243,16 @@ class PixelateAnnotator(BaseAnnotator): Example: ```python - >>> import supervision as sv + import supervision as sv - >>> image = ... - >>> detections = sv.Detections(...) + image = ... + detections = sv.Detections(...) - >>> pixelate_annotator = sv.PixelateAnnotator() - >>> annotated_frame = pixelate_annotator.annotate( - ... scene=image.copy(), - ... detections=detections - ... ) + pixelate_annotator = sv.PixelateAnnotator() + annotated_frame = pixelate_annotator.annotate( + scene=image.copy(), + detections=detections + ) ``` ![pixelate-annotator-example](https://media.roboflow.com/ @@ -1330,16 +1329,16 @@ class TriangleAnnotator(BaseAnnotator): Example: ```python - >>> import supervision as sv + import supervision as sv - >>> image = ... - >>> detections = sv.Detections(...) + image = ... + detections = sv.Detections(...) - >>> triangle_annotator = sv.TriangleAnnotator() - >>> annotated_frame = triangle_annotator.annotate( - ... scene=image.copy(), - ... detections=detections - ... ) + triangle_annotator = sv.TriangleAnnotator() + annotated_frame = triangle_annotator.annotate( + scene=image.copy(), + detections=detections + ) ``` ![triangle-annotator-example](https://media.roboflow.com/ @@ -1423,16 +1422,16 @@ class RoundBoxAnnotator(BaseAnnotator): Example: ```python - >>> import supervision as sv + import supervision as sv - >>> image = ... - >>> detections = sv.Detections(...) + image = ... + detections = sv.Detections(...) - >>> round_box_annotator = sv.RoundBoxAnnotator() - >>> annotated_frame = round_box_annotator.annotate( - ... scene=image.copy(), - ... detections=detections - ... ) + round_box_annotator = sv.RoundBoxAnnotator() + annotated_frame = round_box_annotator.annotate( + scene=image.copy(), + detections=detections + ) ``` ![round-box-annotator-example](https://media.roboflow.com/ From 2d1aa3b996762f53e12e5bcf101a58a04cbfe307 Mon Sep 17 00:00:00 2001 From: Onuralp SEZER Date: Wed, 24 Jan 2024 12:52:34 +0300 Subject: [PATCH 05/14] =?UTF-8?q?docs:=20=F0=9F=93=9D=20supervision/detect?= =?UTF-8?q?ion/tools/inference=5Fslicer.py=20>>>/...=20removed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Onuralp SEZER --- .../detection/tools/inference_slicer.py | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/supervision/detection/tools/inference_slicer.py b/supervision/detection/tools/inference_slicer.py index 2c0c48a6..7157723f 100644 --- a/supervision/detection/tools/inference_slicer.py +++ b/supervision/detection/tools/inference_slicer.py @@ -77,20 +77,20 @@ class InferenceSlicer: Example: ```python - >>> import cv2 - >>> import supervision as sv - >>> from ultralytics import YOLO + import cv2 + import supervision as sv + from ultralytics import YOLO - >>> image = cv2.imread(SOURCE_IMAGE_PATH) - >>> model = YOLO(...) + image = cv2.imread(SOURCE_IMAGE_PATH) + model = YOLO(...) - >>> def callback(image_slice: np.ndarray) -> sv.Detections: - ... result = model(image_slice)[0] - ... return sv.Detections.from_ultralytics(result) + def callback(image_slice: np.ndarray) -> sv.Detections: + result = model(image_slice)[0] + return sv.Detections.from_ultralytics(result) - >>> slicer = sv.InferenceSlicer(callback = callback) + slicer = sv.InferenceSlicer(callback = callback) - >>> detections = slicer(image) + detections = slicer(image) ``` """ detections_list = [] From f03be21a9fe981b6e5016fd38607f987eeed29ce Mon Sep 17 00:00:00 2001 From: Onuralp SEZER Date: Wed, 24 Jan 2024 13:01:55 +0300 Subject: [PATCH 06/14] =?UTF-8?q?docs:=20=F0=9F=93=9D=20supervision/datase?= =?UTF-8?q?t/core.py=20>>>/...=20removed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Onuralp SEZER --- supervision/dataset/core.py | 159 ++++++++++++++++++------------------ 1 file changed, 78 insertions(+), 81 deletions(-) diff --git a/supervision/dataset/core.py b/supervision/dataset/core.py index 48043dbb..551e96da 100644 --- a/supervision/dataset/core.py +++ b/supervision/dataset/core.py @@ -118,13 +118,13 @@ class DetectionDataset(BaseDataset): Example: ```python - >>> import supervision as sv + import supervision as sv - >>> ds = sv.DetectionDataset(...) - >>> train_ds, test_ds = ds.split(split_ratio=0.7, - ... random_state=42, shuffle=True) - >>> len(train_ds), len(test_ds) - (700, 300) + ds = sv.DetectionDataset(...) + train_ds, test_ds = ds.split(split_ratio=0.7, + random_state=42, shuffle=True) + len(train_ds), len(test_ds) + # (700, 300) ``` """ @@ -231,24 +231,24 @@ class DetectionDataset(BaseDataset): Example: ```python - >>> import roboflow - >>> from roboflow import Roboflow - >>> import supervision as sv + import roboflow + from roboflow import Roboflow + import supervision as sv - >>> roboflow.login() + roboflow.login() - >>> rf = Roboflow() + rf = Roboflow() - >>> project = rf.workspace(WORKSPACE_ID).project(PROJECT_ID) - >>> dataset = project.version(PROJECT_VERSION).download("voc") + project = rf.workspace(WORKSPACE_ID).project(PROJECT_ID) + dataset = project.version(PROJECT_VERSION).download("voc") - >>> ds = sv.DetectionDataset.from_pascal_voc( - ... images_directory_path=f"{dataset.location}/train/images", - ... annotations_directory_path=f"{dataset.location}/train/labels" - ... ) + ds = sv.DetectionDataset.from_pascal_voc( + images_directory_path=f"{dataset.location}/train/images", + annotations_directory_path=f"{dataset.location}/train/labels" + ) - >>> ds.classes - ['dog', 'person'] + ds.classes + # ['dog', 'person'] ``` """ @@ -288,25 +288,24 @@ class DetectionDataset(BaseDataset): Example: ```python - >>> import roboflow - >>> from roboflow import Roboflow - >>> import supervision as sv + import roboflow + from roboflow import Roboflow + import supervision as sv - >>> roboflow.login() + roboflow.login() + rf = Roboflow() - >>> rf = Roboflow() + project = rf.workspace(WORKSPACE_ID).project(PROJECT_ID) + dataset = project.version(PROJECT_VERSION).download("yolov5") - >>> project = rf.workspace(WORKSPACE_ID).project(PROJECT_ID) - >>> dataset = project.version(PROJECT_VERSION).download("yolov5") + ds = sv.DetectionDataset.from_yolo( + images_directory_path=f"{dataset.location}/train/images", + annotations_directory_path=f"{dataset.location}/train/labels", + data_yaml_path=f"{dataset.location}/data.yaml" + ) - >>> ds = sv.DetectionDataset.from_yolo( - ... images_directory_path=f"{dataset.location}/train/images", - ... annotations_directory_path=f"{dataset.location}/train/labels", - ... data_yaml_path=f"{dataset.location}/data.yaml" - ... ) - - >>> ds.classes - ['dog', 'person'] + ds.classes + # ['dog', 'person'] ``` """ classes, images, annotations = load_yolo_annotations( @@ -394,24 +393,23 @@ class DetectionDataset(BaseDataset): Example: ```python - >>> import roboflow - >>> from roboflow import Roboflow - >>> import supervision as sv + import roboflow + from roboflow import Roboflow + import supervision as sv - >>> roboflow.login() + roboflow.login() + rf = Roboflow() - >>> rf = Roboflow() + project = rf.workspace(WORKSPACE_ID).project(PROJECT_ID) + dataset = project.version(PROJECT_VERSION).download("coco") - >>> project = rf.workspace(WORKSPACE_ID).project(PROJECT_ID) - >>> dataset = project.version(PROJECT_VERSION).download("coco") + ds = sv.DetectionDataset.from_coco( + images_directory_path=f"{dataset.location}/train", + annotations_path=f"{dataset.location}/train/_annotations.coco.json", + ) - >>> ds = sv.DetectionDataset.from_coco( - ... images_directory_path=f"{dataset.location}/train", - ... annotations_path=f"{dataset.location}/train/_annotations.coco.json", - ... ) - - >>> ds.classes - ['dog', 'person'] + ds.classes + # ['dog', 'person'] ``` """ classes, images, annotations = load_coco_annotations( @@ -486,25 +484,25 @@ class DetectionDataset(BaseDataset): Example: ```python - >>> import supervision as sv + import supervision as sv - >>> ds_1 = sv.DetectionDataset(...) - >>> len(ds_1) - 100 - >>> ds_1.classes - ['dog', 'person'] + ds_1 = sv.DetectionDataset(...) + len(ds_1) + # 100 + ds_1.classes + # ['dog', 'person'] - >>> ds_2 = sv.DetectionDataset(...) - >>> len(ds_2) - 200 - >>> ds_2.classes - ['cat'] + ds_2 = sv.DetectionDataset(...) + len(ds_2) + # 200 + ds_2.classes + # ['cat'] - >>> ds_merged = sv.DetectionDataset.merge([ds_1, ds_2]) - >>> len(ds_merged) - 300 - >>> ds_merged.classes - ['cat', 'dog', 'person'] + ds_merged = sv.DetectionDataset.merge([ds_1, ds_2]) + len(ds_merged) + # 300 + ds_merged.classes + # ['cat', 'dog', 'person'] ``` """ merged_images, merged_annotations = {}, {} @@ -571,13 +569,13 @@ class ClassificationDataset(BaseDataset): Example: ```python - >>> import supervision as sv + import supervision as sv - >>> cd = sv.ClassificationDataset(...) - >>> train_cd,test_cd = cd.split(split_ratio=0.7, - ... random_state=42,shuffle=True) - >>> len(train_cd), len(test_cd) - (700, 300) + cd = sv.ClassificationDataset(...) + train_cd,test_cd = cd.split(split_ratio=0.7, + random_state=42,shuffle=True) + len(train_cd), len(test_cd) + # (700, 300) ``` """ image_names = list(self.images.keys()) @@ -639,20 +637,19 @@ class ClassificationDataset(BaseDataset): Example: ```python - >>> import roboflow - >>> from roboflow import Roboflow - >>> import supervision as sv + import roboflow + from roboflow import Roboflow + import supervision as sv - >>> roboflow.login() + roboflow.login() + rf = Roboflow() - >>> rf = Roboflow() + project = rf.workspace(WORKSPACE_ID).project(PROJECT_ID) + dataset = project.version(PROJECT_VERSION).download("folder") - >>> project = rf.workspace(WORKSPACE_ID).project(PROJECT_ID) - >>> dataset = project.version(PROJECT_VERSION).download("folder") - - >>> cd = sv.ClassificationDataset.from_folder_structure( - ... root_directory_path=f"{dataset.location}/train" - ... ) + cd = sv.ClassificationDataset.from_folder_structure( + root_directory_path=f"{dataset.location}/train" + ) ``` """ classes = os.listdir(root_directory_path) From 4df21ded6a96135afd21f58e9ee6c55f092da2f2 Mon Sep 17 00:00:00 2001 From: Onuralp SEZER Date: Wed, 24 Jan 2024 13:03:34 +0300 Subject: [PATCH 07/14] =?UTF-8?q?docs:=20=F0=9F=93=9D=20supervision/detect?= =?UTF-8?q?ion/annotate.py=20>>>/...=20removed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Onuralp SEZER --- supervision/detection/annotate.py | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/supervision/detection/annotate.py b/supervision/detection/annotate.py index 1ab1bdc2..b891b55e 100644 --- a/supervision/detection/annotate.py +++ b/supervision/detection/annotate.py @@ -63,23 +63,22 @@ class BoxAnnotator: Example: ```python - >>> import supervision as sv + import supervision as sv - >>> classes = ['person', ...] - >>> image = ... - >>> detections = sv.Detections(...) + classes = ['person', ...] + image = ... + detections = sv.Detections(...) - >>> box_annotator = sv.BoxAnnotator() - >>> labels = [ - ... f"{classes[class_id]} {confidence:0.2f}" - ... for _, _, confidence, class_id, _ - ... in detections - ... ] - >>> annotated_frame = box_annotator.annotate( - ... scene=image.copy(), - ... detections=detections, - ... labels=labels - ... ) + box_annotator = sv.BoxAnnotator() + labels = [ + f"{classes[class_id]} {confidence:0.2f}" + for _, _, confidence, class_id, _ in detections + ] + annotated_frame = box_annotator.annotate( + scene=image.copy(), + detections=detections, + labels=labels + ) ``` """ font = cv2.FONT_HERSHEY_SIMPLEX From 833edc95ade69f5dbd3678e054fe69401515919d Mon Sep 17 00:00:00 2001 From: Onuralp SEZER Date: Wed, 24 Jan 2024 13:10:48 +0300 Subject: [PATCH 08/14] =?UTF-8?q?docs:=20=F0=9F=93=9D=20supervision/detect?= =?UTF-8?q?ion/utils.py=20>>>/...=20removed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Onuralp SEZER --- supervision/detection/utils.py | 38 ++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/supervision/detection/utils.py b/supervision/detection/utils.py index f7af7797..e8db4627 100644 --- a/supervision/detection/utils.py +++ b/supervision/detection/utils.py @@ -415,16 +415,17 @@ def move_boxes(xyxy: np.ndarray, offset: np.ndarray) -> np.ndarray: Example: ```python - >>> import numpy as np - >>> import supervision as sv + import numpy as np + import supervision as sv - >>> boxes = np.array([[10, 10, 20, 20], [30, 30, 40, 40]]) - >>> offset = np.array([5, 5]) - >>> sv.move_boxes(boxes, offset) - ... array([ - ... [15, 15, 25, 25], - ... [35, 35, 45, 45] - ... ]) + boxes = np.array([[10, 10, 20, 20], [30, 30, 40, 40]]) + offset = np.array([5, 5]) + moved_box = sv.move_boxes(boxes, offset) + print(moved_box) + # np.array([ + # [15, 15, 25, 25], + # [35, 35, 45, 45] + # ]) ``` """ return xyxy + np.hstack([offset, offset]) @@ -446,16 +447,17 @@ def scale_boxes(xyxy: np.ndarray, factor: float) -> np.ndarray: Example: ```python - >>> import numpy as np - >>> import supervision as sv + import numpy as np + import supervision as sv - >>> boxes = np.array([[10, 10, 20, 20], [30, 30, 40, 40]]) - >>> factor = 1.5 - >>> sv.scale_boxes(boxes, factor) - ... array([ - ... [ 7.5, 7.5, 22.5, 22.5], - ... [27.5, 27.5, 42.5, 42.5] - ... ]) + boxes = np.array([[10, 10, 20, 20], [30, 30, 40, 40]]) + factor = 1.5 + scaled_bb = sv.scale_boxes(boxes, factor) + print(scaled_bb) + # np.array([ + # [ 7.5, 7.5, 22.5, 22.5], + # [27.5, 27.5, 42.5, 42.5] + # ]) ``` """ centers = (xyxy[:, :2] + xyxy[:, 2:]) / 2 From 955a6d67fbc4ab2aac9d900698bbb636250e5afe Mon Sep 17 00:00:00 2001 From: Onuralp SEZER Date: Wed, 24 Jan 2024 13:13:56 +0300 Subject: [PATCH 09/14] =?UTF-8?q?docs:=20=F0=9F=93=9D=20supervision/tracke?= =?UTF-8?q?r/byte=5Ftracker/core.py=20>>>/...=20removed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Onuralp SEZER --- supervision/tracker/byte_tracker/core.py | 41 ++++++++++++------------ 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/supervision/tracker/byte_tracker/core.py b/supervision/tracker/byte_tracker/core.py index 34a90138..bf831daa 100644 --- a/supervision/tracker/byte_tracker/core.py +++ b/supervision/tracker/byte_tracker/core.py @@ -205,30 +205,29 @@ class ByteTrack: Detection: The updated detection results that now include tracking IDs. Example: ```python - >>> import supervision as sv - >>> from ultralytics import YOLO + import supervision as sv + from ultralytics import YOLO - >>> model = YOLO(...) - >>> byte_tracker = sv.ByteTrack() - >>> annotator = sv.BoxAnnotator() + model = YOLO(...) + byte_tracker = sv.ByteTrack() + annotator = sv.BoxAnnotator() - >>> def callback(frame: np.ndarray, index: int) -> np.ndarray: - ... results = model(frame)[0] - ... detections = sv.Detections.from_ultralytics(results) - ... detections = byte_tracker.update_with_detections(detections) - ... labels = [ - ... f"#{tracker_id} {model.model.names[class_id]} {confidence:0.2f}" - ... for _, _, confidence, class_id, tracker_id - ... in detections - ... ] - ... return annotator.annotate(scene=frame.copy(), - ... detections=detections, labels=labels) + def callback(frame: np.ndarray, index: int) -> np.ndarray: + results = model(frame)[0] + detections = sv.Detections.from_ultralytics(results) + detections = byte_tracker.update_with_detections(detections) + labels = [ + f"#{tracker_id} {model.model.names[class_id]} {confidence:0.2f}" + for _, _, confidence, class_id, tracker_id in detections + ] + return annotator.annotate(scene=frame.copy(), + detections=detections, labels=labels) - >>> sv.process_video( - ... source_path='...', - ... target_path='...', - ... callback=callback - ... ) + sv.process_video( + source_path='...', + target_path='...', + callback=callback + ) ``` """ From e29e960c5f0ea6d822b64d9c43f06d7f09e8ba9b Mon Sep 17 00:00:00 2001 From: Onuralp SEZER Date: Wed, 24 Jan 2024 15:14:18 +0300 Subject: [PATCH 10/14] =?UTF-8?q?docs:=20=F0=9F=93=9D=20supervision/metric?= =?UTF-8?q?s/detection.py=20>>>/...=20removed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Onuralp SEZER --- supervision/metrics/detection.py | 268 ++++++++++++++++--------------- 1 file changed, 135 insertions(+), 133 deletions(-) diff --git a/supervision/metrics/detection.py b/supervision/metrics/detection.py index c332ce9a..71007d71 100644 --- a/supervision/metrics/detection.py +++ b/supervision/metrics/detection.py @@ -116,31 +116,31 @@ class ConfusionMatrix: Example: ```python - >>> import supervision as sv + import supervision as sv - >>> targets = [ - ... sv.Detections(...), - ... sv.Detections(...) - ... ] + targets = [ + sv.Detections(...), + sv.Detections(...) + ] - >>> predictions = [ - ... sv.Detections(...), - ... sv.Detections(...) - ... ] + predictions = [ + sv.Detections(...), + sv.Detections(...) + ] - >>> confusion_matrix = sv.ConfusionMatrix.from_detections( - ... predictions=predictions, - ... targets=target, - ... classes=['person', ...] - ... ) + confusion_matrix = sv.ConfusionMatrix.from_detections( + predictions=predictions, + targets=target, + classes=['person', ...] + ) - >>> confusion_matrix.matrix - array([ - [0., 0., 0., 0.], - [0., 1., 0., 1.], - [0., 1., 1., 0.], - [1., 1., 0., 0.] - ]) + print(confusion_matrix.matrix) + # np.array([ + # [0., 0., 0., 0.], + # [0., 1., 0., 1.], + # [0., 1., 1., 0.], + # [1., 1., 0., 0.] + # ]) ``` """ @@ -191,46 +191,47 @@ class ConfusionMatrix: Example: ```python - >>> import supervision as sv + import supervision as sv + import numpy as np - >>> targets = ( - ... [ - ... array( - ... [ - ... [0.0, 0.0, 3.0, 3.0, 1], - ... [2.0, 2.0, 5.0, 5.0, 1], - ... [6.0, 1.0, 8.0, 3.0, 2], - ... ] - ... ), - ... array([1.0, 1.0, 2.0, 2.0, 2]), - ... ] - ... ) + targets = ( + [ + np.array( + [ + [0.0, 0.0, 3.0, 3.0, 1], + [2.0, 2.0, 5.0, 5.0, 1], + [6.0, 1.0, 8.0, 3.0, 2], + ] + ), + np.array([1.0, 1.0, 2.0, 2.0, 2]), + ] + ) - >>> predictions = [ - ... array( - ... [ - ... [0.0, 0.0, 3.0, 3.0, 1, 0.9], - ... [0.1, 0.1, 3.0, 3.0, 0, 0.9], - ... [6.0, 1.0, 8.0, 3.0, 1, 0.8], - ... [1.0, 6.0, 2.0, 7.0, 1, 0.8], - ... ] - ... ), - ... array([[1.0, 1.0, 2.0, 2.0, 2, 0.8]]) - ... ] + predictions = [ + np.array( + [ + [0.0, 0.0, 3.0, 3.0, 1, 0.9], + [0.1, 0.1, 3.0, 3.0, 0, 0.9], + [6.0, 1.0, 8.0, 3.0, 1, 0.8], + [1.0, 6.0, 2.0, 7.0, 1, 0.8], + ] + ), + np.array([[1.0, 1.0, 2.0, 2.0, 2, 0.8]]) + ] - >>> confusion_matrix = sv.ConfusionMatrix.from_tensors( - ... predictions=predictions, - ... targets=targets, - ... classes=['person', ...] - ... ) + confusion_matrix = sv.ConfusionMatrix.from_tensors( + predictions=predictions, + targets=targets, + classes=['person', ...] + ) - >>> confusion_matrix.matrix - array([ - [0., 0., 0., 0.], - [0., 1., 0., 1.], - [0., 1., 1., 0.], - [1., 1., 0., 0.] - ]) + print(confusion_matrix.matrix) + # np.array([ + # [0., 0., 0., 0.], + # [0., 1., 0., 1.], + # [0., 1., 1., 0.], + # [1., 1., 0., 0.] + # ]) ``` """ validate_input_tensors(predictions, targets) @@ -365,28 +366,28 @@ class ConfusionMatrix: Example: ```python - >>> import supervision as sv - >>> from ultralytics import YOLO + import supervision as sv + from ultralytics import YOLO - >>> dataset = sv.DetectionDataset.from_yolo(...) + dataset = sv.DetectionDataset.from_yolo(...) - >>> model = YOLO(...) - >>> def callback(image: np.ndarray) -> sv.Detections: - ... result = model(image)[0] - ... return sv.Detections.from_ultralytics(result) + model = YOLO(...) + def callback(image: np.ndarray) -> sv.Detections: + result = model(image)[0] + return sv.Detections.from_ultralytics(result) - >>> confusion_matrix = sv.ConfusionMatrix.benchmark( - ... dataset = dataset, - ... callback = callback - ... ) + confusion_matrix = sv.ConfusionMatrix.benchmark( + dataset = dataset, + callback = callback + ) - >>> confusion_matrix.matrix - array([ - [0., 0., 0., 0.], - [0., 1., 0., 1.], - [0., 1., 1., 0.], - [1., 1., 0., 0.] - ]) + print(confusion_matrix.matrix) + # np.array([ + # [0., 0., 0., 0.], + # [0., 1., 0., 1.], + # [0., 1., 1., 0.], + # [1., 1., 0., 0.] + # ]) ``` """ predictions, targets = [], [] @@ -532,25 +533,25 @@ class MeanAveragePrecision: Example: ```python - >>> import supervision as sv + import supervision as sv - >>> targets = [ - ... sv.Detections(...), - ... sv.Detections(...) - ... ] + targets = [ + sv.Detections(...), + sv.Detections(...) + ] - >>> predictions = [ - ... sv.Detections(...), - ... sv.Detections(...) - ... ] + predictions = [ + sv.Detections(...), + sv.Detections(...) + ] - >>> mean_average_precision = sv.MeanAveragePrecision.from_detections( - ... predictions=predictions, - ... targets=target, - ... ) + mean_average_precision = sv.MeanAveragePrecision.from_detections( + predictions=predictions, + targets=target, + ) - >>> mean_average_precison.map50_95 - 0.2899 + print(mean_average_precison.map50_95) + # 0.2899 ``` """ prediction_tensors = [] @@ -583,23 +584,23 @@ class MeanAveragePrecision: Example: ```python - >>> import supervision as sv - >>> from ultralytics import YOLO + import supervision as sv + from ultralytics import YOLO - >>> dataset = sv.DetectionDataset.from_yolo(...) + dataset = sv.DetectionDataset.from_yolo(...) - >>> model = YOLO(...) - >>> def callback(image: np.ndarray) -> sv.Detections: - ... result = model(image)[0] - ... return sv.Detections.from_ultralytics(result) + model = YOLO(...) + def callback(image: np.ndarray) -> sv.Detections: + result = model(image)[0] + return sv.Detections.from_ultralytics(result) - >>> mean_average_precision = sv.MeanAveragePrecision.benchmark( - ... dataset = dataset, - ... callback = callback - ... ) + mean_average_precision = sv.MeanAveragePrecision.benchmark( + dataset = dataset, + callback = callback + ) - >>> mean_average_precision.map50_95 - 0.433 + print(mean_average_precision.map50_95) + # 0.433 ``` """ predictions, targets = [], [] @@ -637,40 +638,41 @@ class MeanAveragePrecision: Example: ```python - >>> import supervision as sv + import supervision as sv + import numpy as np - >>> targets = ( - ... [ - ... array( - ... [ - ... [0.0, 0.0, 3.0, 3.0, 1], - ... [2.0, 2.0, 5.0, 5.0, 1], - ... [6.0, 1.0, 8.0, 3.0, 2], - ... ] - ... ), - ... array([1.0, 1.0, 2.0, 2.0, 2]), - ... ] - ... ) + targets = ( + [ + np.array( + [ + [0.0, 0.0, 3.0, 3.0, 1], + [2.0, 2.0, 5.0, 5.0, 1], + [6.0, 1.0, 8.0, 3.0, 2], + ] + ), + np.array([[1.0, 1.0, 2.0, 2.0, 2]]), + ] + ) - >>> predictions = [ - ... array( - ... [ - ... [0.0, 0.0, 3.0, 3.0, 1, 0.9], - ... [0.1, 0.1, 3.0, 3.0, 0, 0.9], - ... [6.0, 1.0, 8.0, 3.0, 1, 0.8], - ... [1.0, 6.0, 2.0, 7.0, 1, 0.8], - ... ] - ... ), - ... array([[1.0, 1.0, 2.0, 2.0, 2, 0.8]]) - ... ] + predictions = [ + np.array( + [ + [0.0, 0.0, 3.0, 3.0, 1, 0.9], + [0.1, 0.1, 3.0, 3.0, 0, 0.9], + [6.0, 1.0, 8.0, 3.0, 1, 0.8], + [1.0, 6.0, 2.0, 7.0, 1, 0.8], + ] + ), + np.array([[1.0, 1.0, 2.0, 2.0, 2, 0.8]]) + ] - >>> mean_average_precison = sv.MeanAveragePrecision.from_tensors( - ... predictions=predictions, - ... targets=targets, - ... ) + mean_average_precison = sv.MeanAveragePrecision.from_tensors( + predictions=predictions, + targets=targets, + ) - >>> mean_average_precison.map50_95 - 0.2899 + print(mean_average_precison.map50_95) + # 0.6649 ``` """ validate_input_tensors(predictions, targets) From 8a5cd1bc3e5800335525dfd4be31ec3ee646873b Mon Sep 17 00:00:00 2001 From: Onuralp SEZER Date: Wed, 24 Jan 2024 15:17:29 +0300 Subject: [PATCH 11/14] =?UTF-8?q?docs:=20=F0=9F=93=9D=20supervision/utils/?= =?UTF-8?q?video.py=20>>>/...=20removed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Onuralp SEZER --- supervision/utils/video.py | 60 +++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/supervision/utils/video.py b/supervision/utils/video.py index 1687c453..6be3bffe 100644 --- a/supervision/utils/video.py +++ b/supervision/utils/video.py @@ -24,15 +24,15 @@ class VideoInfo: Examples: ```python - >>> import supervision as sv + import supervision as sv - >>> video_info = sv.VideoInfo.from_video_path(video_path='video.mp4') + video_info = sv.VideoInfo.from_video_path(video_path='video.mp4') - >>> video_info - VideoInfo(width=3840, height=2160, fps=25, total_frames=538) + video_info + # VideoInfo(width=3840, height=2160, fps=25, total_frames=538) - >>> video_info.resolution_wh - (3840, 2160) + video_info.resolution_wh + # (3840, 2160) ``` """ @@ -71,14 +71,14 @@ class VideoSink: Example: ```python - >>> import supervision as sv + import supervision as sv - >>> video_info = sv.VideoInfo.from_video_path('source.mp4') - >>> frames_generator = sv.get_video_frames_generator('source.mp4') + video_info = sv.VideoInfo.from_video_path('source.mp4') + frames_generator = sv.get_video_frames_generator('source.mp4') - >>> with sv.VideoSink(target_path='target.mp4', video_info=video_info) as sink: - ... for frame in frames_generator: - ... sink.write_frame(frame=frame) + with sv.VideoSink(target_path='target.mp4', video_info=video_info) as sink: + for frame in frames_generator: + sink.write_frame(frame=frame) ``` """ @@ -143,10 +143,10 @@ def get_video_frames_generator( Examples: ```python - >>> import supervision as sv + import supervision as sv - >>> for frame in sv.get_video_frames_generator(source_path='source_video.mp4'): - ... ... + for frame in sv.get_video_frames_generator(source_path='source_video.mp4'): + ... ``` """ video, start, end = _validate_and_setup_video(source_path, start, end) @@ -183,16 +183,16 @@ def process_video( Examples: ```python - >>> import supervision as sv + import supervision as sv - >>> def callback(scene: np.ndarray, index: int) -> np.ndarray: - ... ... + def callback(scene: np.ndarray, index: int) -> np.ndarray: + ... - >>> process_video( - ... source_path='...', - ... target_path='...', - ... callback=callback - ... ) + process_video( + source_path='...', + target_path='...', + callback=callback + ) ``` """ source_video_info = VideoInfo.from_video_path(video_path=source_path) @@ -217,15 +217,15 @@ class FPSMonitor: Examples: ```python - >>> import supervision as sv + import supervision as sv - >>> frames_generator = sv.get_video_frames_generator('source.mp4') - >>> fps_monitor = sv.FPSMonitor() + frames_generator = sv.get_video_frames_generator('source.mp4') + fps_monitor = sv.FPSMonitor() - >>> for frame in frames_generator: - ... # your processing code here - ... fps_monitor.tick() - ... fps = fps_monitor() + for frame in frames_generator: + # your processing code here + fps_monitor.tick() + fps = fps_monitor() ``` """ self.all_timestamps = deque(maxlen=sample_size) From 12b42f80dea7886ea8a542081f4e376bdeacb94b Mon Sep 17 00:00:00 2001 From: Onuralp SEZER Date: Wed, 24 Jan 2024 15:17:49 +0300 Subject: [PATCH 12/14] =?UTF-8?q?docs:=20=F0=9F=93=9D=20supervision/utils/?= =?UTF-8?q?notebook.py=20>>>/...=20removed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Onuralp SEZER --- supervision/utils/notebook.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/supervision/utils/notebook.py b/supervision/utils/notebook.py index 97b6659c..e8a0c7aa 100644 --- a/supervision/utils/notebook.py +++ b/supervision/utils/notebook.py @@ -18,13 +18,13 @@ def plot_image( Examples: ```python - >>> import cv2 - >>> import supervision as sv + import cv2 + import supervision as sv - >>> image = cv2.imread("path/to/image.jpg") + image = cv2.imread("path/to/image.jpg") %matplotlib inline - >>> sv.plot_image(image=image, size=(16, 16)) + sv.plot_image(image=image, size=(16, 16)) ``` """ plt.figure(figsize=size) @@ -63,18 +63,18 @@ def plot_images_grid( Examples: ```python - >>> import cv2 - >>> import supervision as sv + import cv2 + import supervision as sv - >>> image1 = cv2.imread("path/to/image1.jpg") - >>> image2 = cv2.imread("path/to/image2.jpg") - >>> image3 = cv2.imread("path/to/image3.jpg") + image1 = cv2.imread("path/to/image1.jpg") + image2 = cv2.imread("path/to/image2.jpg") + image3 = cv2.imread("path/to/image3.jpg") - >>> images = [image1, image2, image3] - >>> titles = ["Image 1", "Image 2", "Image 3"] + images = [image1, image2, image3] + titles = ["Image 1", "Image 2", "Image 3"] %matplotlib inline - >>> plot_images_grid(images, grid_size=(2, 2), titles=titles, size=(16, 16)) + plot_images_grid(images, grid_size=(2, 2), titles=titles, size=(16, 16)) ``` """ nrows, ncols = grid_size From ab5a86596f5bd0649fa78626204eca64e3722019 Mon Sep 17 00:00:00 2001 From: Onuralp SEZER Date: Wed, 24 Jan 2024 15:26:43 +0300 Subject: [PATCH 13/14] =?UTF-8?q?docs:=20=F0=9F=93=9D=20supervision=20down?= =?UTF-8?q?loader=20classfication=20draw=20geometry=20and=20utils=20>>>/..?= =?UTF-8?q?.=20removed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Onuralp SEZER --- supervision/assets/downloader.py | 4 +- supervision/classification/core.py | 66 +++++++++++++++--------------- supervision/draw/color.py | 24 ++++++----- supervision/draw/utils.py | 8 ++-- supervision/geometry/utils.py | 9 ++-- supervision/utils/file.py | 12 +++--- supervision/utils/image.py | 24 +++++------ 7 files changed, 76 insertions(+), 71 deletions(-) diff --git a/supervision/assets/downloader.py b/supervision/assets/downloader.py index e37aca40..8e86359a 100644 --- a/supervision/assets/downloader.py +++ b/supervision/assets/downloader.py @@ -54,9 +54,9 @@ def download_assets(asset_name: Union[VideoAssets, str]) -> str: Example: ```python - >>> from supervision.assets import download_assets, VideoAssets + from supervision.assets import download_assets, VideoAssets - >>> download_assets(VideoAssets.VEHICLES) + download_assets(VideoAssets.VEHICLES) "vehicles.mp4" ``` """ diff --git a/supervision/classification/core.py b/supervision/classification/core.py index 279d358a..34df85e3 100644 --- a/supervision/classification/core.py +++ b/supervision/classification/core.py @@ -59,18 +59,18 @@ class Classifications: Example: ```python - >>> from PIL import Image - >>> import clip - >>> import supervision as sv + from PIL import Image + import clip + import supervision as sv - >>> model, preprocess = clip.load('ViT-B/32') + model, preprocess = clip.load('ViT-B/32') - >>> image = cv2.imread(SOURCE_IMAGE_PATH) - >>> image = preprocess(image).unsqueeze(0) + image = cv2.imread(SOURCE_IMAGE_PATH) + image = preprocess(image).unsqueeze(0) - >>> text = clip.tokenize(["a diagram", "a dog", "a cat"]) - >>> output, _ = model(image, text) - >>> classifications = sv.Classifications.from_clip(output) + text = clip.tokenize(["a diagram", "a dog", "a cat"]) + output, _ = model(image, text) + classifications = sv.Classifications.from_clip(output) ``` """ @@ -97,15 +97,15 @@ class Classifications: Example: ```python - >>> import cv2 - >>> from ultralytics import YOLO - >>> import supervision as sv + import cv2 + from ultralytics import YOLO + import supervision as sv - >>> image = cv2.imread(SOURCE_IMAGE_PATH) - >>> model = YOLO('yolov8n-cls.pt') + image = cv2.imread(SOURCE_IMAGE_PATH) + model = YOLO('yolov8n-cls.pt') - >>> output = model(image)[0] - >>> classifications = sv.Classifications.from_ultralytics(output) + output = model(image)[0] + classifications = sv.Classifications.from_ultralytics(output) ``` """ confidence = ultralytics_results.probs.data.cpu().numpy() @@ -125,25 +125,25 @@ class Classifications: Example: ```python - >>> from PIL import Image - >>> import timm - >>> from timm.data import resolve_data_config, create_transform - >>> import supervision as sv + from PIL import Image + import timm + from timm.data import resolve_data_config, create_transform + import supervision as sv - >>> model = timm.create_model( - ... model_name='hf-hub:nateraw/resnet50-oxford-iiit-pet', - ... pretrained=True - ... ).eval() + model = timm.create_model( + model_name='hf-hub:nateraw/resnet50-oxford-iiit-pet', + pretrained=True + ).eval() - >>> config = resolve_data_config({}, model=model) - >>> transform = create_transform(**config) + config = resolve_data_config({}, model=model) + transform = create_transform(**config) - >>> image = Image.open(SOURCE_IMAGE_PATH).convert('RGB') - >>> x = transform(image).unsqueeze(0) + image = Image.open(SOURCE_IMAGE_PATH).convert('RGB') + x = transform(image).unsqueeze(0) - >>> output = model(x) + output = model(x) - >>> classifications = sv.Classifications.from_timm(output) + classifications = sv.Classifications.from_timm(output) ``` """ confidence = timm_results.cpu().detach().numpy()[0] @@ -168,11 +168,11 @@ class Classifications: Example: ```python - >>> import supervision as sv + import supervision as sv - >>> classifications = sv.Classifications(...) + classifications = sv.Classifications(...) - >>> classifications.get_top_k(1) + classifications.get_top_k(1) (array([1]), array([0.9])) ``` diff --git a/supervision/draw/color.py b/supervision/draw/color.py index fe55b25c..7c26fb30 100644 --- a/supervision/draw/color.py +++ b/supervision/draw/color.py @@ -62,7 +62,7 @@ class Color: Example: ``` - >>> Color.from_hex('#ff00ff') + Color.from_hex('#ff00ff') Color(r=255, g=0, b=255) ``` """ @@ -82,8 +82,8 @@ class Color: Example: ``` - >>> Color(r=255, g=0, b=255).as_hex() - '#ff00ff' + Color(r=255, g=0, b=255).as_hex() + # '#ff00ff' ``` """ return f"#{self.r:02x}{self.g:02x}{self.b:02x}" @@ -97,8 +97,8 @@ class Color: Example: ``` - >>> color.as_rgb() - (255, 0, 255) + color.as_rgb() + # (255, 0, 255) ``` """ return self.r, self.g, self.b @@ -112,8 +112,8 @@ class Color: Example: ``` - >>> color.as_bgr() - (255, 0, 255) + color.as_bgr() + # (255, 0, 255) ``` """ return self.b, self.g, self.r @@ -193,7 +193,7 @@ class ColorPalette: Example: ``` - >>> ColorPalette.default() + ColorPalette.default() ColorPalette(colors=[Color(r=255, g=0, b=0), Color(r=0, g=255, b=0), ...]) ``` """ @@ -212,7 +212,7 @@ class ColorPalette: Example: ``` - >>> ColorPalette.from_hex(['#ff0000', '#00ff00', '#0000ff']) + ColorPalette.from_hex(['#ff0000', '#00ff00', '#0000ff']) ColorPalette(colors=[Color(r=255, g=0, b=0), Color(r=0, g=255, b=0), ...]) ``` """ @@ -231,8 +231,10 @@ class ColorPalette: Example: ``` - >>> color_palette.by_idx(1) - Color(r=0, g=255, b=0) + import supervision as sv + + color_palette.by_idx(1) + # Color(r=0, g=255, b=0) ``` """ if idx < 0: diff --git a/supervision/draw/utils.py b/supervision/draw/utils.py index 10f5c932..a6e600e3 100644 --- a/supervision/draw/utils.py +++ b/supervision/draw/utils.py @@ -135,9 +135,11 @@ def draw_text( Examples: ```python - >>> scene = np.zeros((100, 100, 3), dtype=np.uint8) - >>> text_anchor = Point(x=50, y=50) - >>> scene = draw_text(scene=scene, text="Hello, world!",text_anchor=text_anchor) + import numpy as np + + scene = np.zeros((100, 100, 3), dtype=np.uint8) + text_anchor = Point(x=50, y=50) + scene = draw_text(scene=scene, text="Hello, world!",text_anchor=text_anchor) ``` """ text_width, text_height = cv2.getTextSize( diff --git a/supervision/geometry/utils.py b/supervision/geometry/utils.py index f1b66db2..6069ca7f 100644 --- a/supervision/geometry/utils.py +++ b/supervision/geometry/utils.py @@ -22,10 +22,11 @@ def get_polygon_center(polygon: np.ndarray) -> Point: Examples: ```python - >>> from supervision.geometry.utils import get_polygon_center - - >>> vertices = np.array([[0, 0], [0, 1], [1, 1], [1, 0]]) - >>> get_center(vertices) + from supervision.geometry.utils import get_polygon_center + import numpy as np + + vertices = np.array([[0, 0], [0, 1], [1, 1], [1, 0]]) + get_center(vertices) Point(x=0.5, y=0.5) ``` """ diff --git a/supervision/utils/file.py b/supervision/utils/file.py index c0521236..dfce7eb0 100644 --- a/supervision/utils/file.py +++ b/supervision/utils/file.py @@ -34,14 +34,14 @@ def list_files_with_extensions( Examples: ```python - >>> import supervision as sv + import supervision as sv - >>> # List all files in the directory - >>> files = sv.list_files_with_extensions(directory='my_directory') + # List all files in the directory + files = sv.list_files_with_extensions(directory='my_directory') - >>> # List only files with '.txt' and '.md' extensions - >>> files = sv.list_files_with_extensions( - ... directory='my_directory', extensions=['txt', 'md']) + # List only files with '.txt' and '.md' extensions + files = sv.list_files_with_extensions( + directory='my_directory', extensions=['txt', 'md']) ``` """ diff --git a/supervision/utils/image.py b/supervision/utils/image.py index 8abfbba9..442e9b6a 100644 --- a/supervision/utils/image.py +++ b/supervision/utils/image.py @@ -20,13 +20,13 @@ def crop_image(image: np.ndarray, xyxy: np.ndarray) -> np.ndarray: Examples: ```python - >>> import supervision as sv + import supervision as sv - >>> detection = sv.Detections(...) - >>> with sv.ImageSink(target_dir_path='target/directory/path') as sink: - ... for xyxy in detection.xyxy: - ... cropped_image = sv.crop_image(image=image, xyxy=xyxy) - ... sink.save_image(image=image) + detection = sv.Detections(...) + with sv.ImageSink(target_dir_path='target/directory/path') as sink: + for xyxy in detection.xyxy: + cropped_image = sv.crop_image(image=image, xyxy=xyxy) + sink.save_image(image=image) ``` """ @@ -55,13 +55,13 @@ class ImageSink: Examples: ```python - >>> import supervision as sv + import supervision as sv - >>> with sv.ImageSink(target_dir_path='target/directory/path', - ... overwrite=True) as sink: - ... for image in sv.get_video_frames_generator( - ... source_path='source_video.mp4', stride=2): - ... sink.save_image(image=image) + with sv.ImageSink(target_dir_path='target/directory/path', + overwrite=True) as sink: + for image in sv.get_video_frames_generator( + source_path='source_video.mp4', stride=2): + sink.save_image(image=image) ``` """ From d4e0d8d46d1c7ce08e40c508333f1bc44a1462b2 Mon Sep 17 00:00:00 2001 From: Onuralp SEZER Date: Wed, 24 Jan 2024 15:40:08 +0300 Subject: [PATCH 14/14] =?UTF-8?q?docs:=20=F0=9F=93=9D=20supervision/annota?= =?UTF-8?q?tors/core.py=20PercentageBarAnnotator=20>>>/...=20removed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Onuralp SEZER --- docs/annotators.md | 16 ++++++++-------- supervision/annotators/core.py | 16 ++++++++-------- supervision/geometry/utils.py | 2 +- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/docs/annotators.md b/docs/annotators.md index 75a01802..3731b63c 100644 --- a/docs/annotators.md +++ b/docs/annotators.md @@ -194,16 +194,16 @@ comments: true === "PercentageBar" ```python - >>> import supervision as sv + import supervision as sv - >>> image = ... - >>> detections = sv.Detections(...) + image = ... + detections = sv.Detections(...) - >>> percentage_bar_annotator = sv.PercentageBarAnnotator() - >>> annotated_frame = percentage_bar_annotator.annotate( - ... scene=image.copy(), - ... detections=detections - ... ) + percentage_bar_annotator = sv.PercentageBarAnnotator() + annotated_frame = percentage_bar_annotator.annotate( + scene=image.copy(), + detections=detections + ) ```
diff --git a/supervision/annotators/core.py b/supervision/annotators/core.py index f128631c..4e8b634b 100644 --- a/supervision/annotators/core.py +++ b/supervision/annotators/core.py @@ -1562,16 +1562,16 @@ class PercentageBarAnnotator(BaseAnnotator): Example: ```python - >>> import supervision as sv + import supervision as sv - >>> image = ... - >>> detections = sv.Detections(...) + image = ... + detections = sv.Detections(...) - >>> percentage_bar_annotator = sv.BoundingBoxAnnotator() - >>> annotated_frame = percentage_bar_annotator.annotate( - ... scene=image.copy(), - ... detections=detections - ... ) + percentage_bar_annotator = sv.BoundingBoxAnnotator() + annotated_frame = percentage_bar_annotator.annotate( + scene=image.copy(), + detections=detections + ) ``` ![percentage-bar-example](https://media.roboflow.com/ diff --git a/supervision/geometry/utils.py b/supervision/geometry/utils.py index 6069ca7f..dd4e64db 100644 --- a/supervision/geometry/utils.py +++ b/supervision/geometry/utils.py @@ -24,7 +24,7 @@ def get_polygon_center(polygon: np.ndarray) -> Point: ```python from supervision.geometry.utils import get_polygon_center import numpy as np - + vertices = np.array([[0, 0], [0, 1], [1, 1], [1, 0]]) get_center(vertices) Point(x=0.5, y=0.5)