+
+ { align=center width="800" }
+
+
+
=== "Crop"
```python
@@ -492,6 +522,12 @@ status: new
:::supervision.annotators.core.LabelAnnotator
+
diff --git a/docs/detection/tools/save_detections.md b/docs/detection/tools/save_detections.md
index a82ce5df..a24cee57 100644
--- a/docs/detection/tools/save_detections.md
+++ b/docs/detection/tools/save_detections.md
@@ -1,6 +1,5 @@
---
comments: true
-status: new
---
# Save Detections
diff --git a/docs/detection/utils.md b/docs/detection/utils.md
index abacdc21..ea98c868 100644
--- a/docs/detection/utils.md
+++ b/docs/detection/utils.md
@@ -1,6 +1,5 @@
---
comments: true
-status: new
---
# Detection Utils
@@ -17,18 +16,6 @@ status: new
:::supervision.detection.utils.mask_iou_batch
-
-
-:::supervision.detection.utils.box_non_max_suppression
-
-
-
-:::supervision.detection.utils.mask_non_max_suppression
-
@@ -65,8 +52,38 @@ status: new
:::supervision.detection.utils.move_boxes
+
+
+:::supervision.detection.utils.move_masks
+
:::supervision.detection.utils.scale_boxes
+
+
+
+:::supervision.detection.utils.clip_boxes
+
+
+
+:::supervision.detection.utils.pad_boxes
+
+
+
+:::supervision.detection.utils.contains_holes
+
+
+
+:::supervision.detection.utils.contains_multiple_segments
diff --git a/docs/how_to/detect_and_annotate.md b/docs/how_to/detect_and_annotate.md
index a9a4405e..52e3174b 100644
--- a/docs/how_to/detect_and_annotate.md
+++ b/docs/how_to/detect_and_annotate.md
@@ -1,6 +1,5 @@
---
comments: true
-status: new
---
# Detect and Annotate
diff --git a/docs/how_to/detect_small_objects.md b/docs/how_to/detect_small_objects.md
index e2d02328..175b4f36 100644
--- a/docs/how_to/detect_small_objects.md
+++ b/docs/how_to/detect_small_objects.md
@@ -6,7 +6,7 @@ status: new
# Detect Small Objects
This guide shows how to detect small objects
-with the [Inference](https://github.com/roboflow/inference),
+with the [Inference](https://github.com/roboflow/inference),
[Ultralytics](https://github.com/ultralytics/ultralytics) or
[Transformers](https://github.com/huggingface/transformers) packages using
[`InferenceSlicer`](/latest/detection/tools/inference_slicer/#supervision.detection.tools.inference_slicer.InferenceSlicer).
@@ -68,10 +68,10 @@ size relative to the image resolution.
import torch
import supervision as sv
from PIL import Image
- from transformers import DetrImageProcessor, DetrForObjectDetection
+ from transformers import DetrImageProcessor, DetrForSegmentation
processor = DetrImageProcessor.from_pretrained("facebook/detr-resnet-50")
- model = DetrForObjectDetection.from_pretrained("facebook/detr-resnet-50")
+ model = DetrForSegmentation.from_pretrained("facebook/detr-resnet-50")
image = Image.open(
)
inputs = processor(images=image, return_tensors="pt")
@@ -79,8 +79,8 @@ size relative to the image resolution.
with torch.no_grad():
outputs = model(**inputs)
- width, height = image.size
- target_size = torch.tensor([[height, width]])
+ width, height = image_slice.size
+ target_size = torch.tensor([[width, height]])
results = processor.post_process_object_detection(
outputs=outputs, target_sizes=target_size)[0]
detections = sv.Detections.from_transformers(results)
@@ -175,7 +175,7 @@ objects within each, and aggregating the results.
def callback(image_slice: np.ndarray) -> sv.Detections:
results = model.infer(image_slice)[0]
- detections = sv.Detections.from_inference(results)
+ return sv.Detections.from_inference(results)
slicer = sv.InferenceSlicer(callback = callback)
detections = slicer(image)
@@ -239,8 +239,8 @@ objects within each, and aggregating the results.
with torch.no_grad():
outputs = model(**inputs)
- width, height = image.size
- target_size = torch.tensor([[height, width]])
+ width, height = image_slice.size
+ target_size = torch.tensor([[width, height]])
results = processor.post_process_object_detection(
outputs=outputs, target_sizes=target_size)[0]
return sv.Detections.from_transformers(results)
@@ -264,3 +264,63 @@ objects within each, and aggregating the results.
```

+
+## Small Object Segmentation
+
+[`InferenceSlicer`](/latest/detection/tools/inference_slicer/#supervision.detection.tools.inference_slicer.InferenceSlicer) can perform segmentation tasks too.
+
+=== "Inference"
+
+ ```{ .py hl_lines="6 16 19-20" }
+ import cv2
+ import numpy as np
+ import supervision as sv
+ from inference import get_model
+
+ model = get_model(model_id="yolov8x-seg-640")
+ image = cv2.imread()
+
+ def callback(image_slice: np.ndarray) -> sv.Detections:
+ results = model.infer(image_slice)[0]
+ return sv.Detections.from_inference(results)
+
+ slicer = sv.InferenceSlicer(callback = callback)
+ detections = slicer(image)
+
+ mask_annotator = sv.MaskAnnotator()
+ label_annotator = sv.LabelAnnotator()
+
+ annotated_image = mask_annotator.annotate(
+ scene=image, detections=detections)
+ annotated_image = label_annotator.annotate(
+ scene=annotated_image, detections=detections)
+ ```
+
+=== "Ultralytics"
+
+ ```{ .py hl_lines="6 16 19-20" }
+ import cv2
+ import numpy as np
+ import supervision as sv
+ from ultralytics import YOLO
+
+ model = YOLO("yolov8x-seg.pt")
+ image = cv2.imread()
+
+ def callback(image_slice: np.ndarray) -> sv.Detections:
+ result = model(image_slice)[0]
+ return sv.Detections.from_ultralytics(result)
+
+ slicer = sv.InferenceSlicer(callback = callback)
+ detections = slicer(image)
+
+ mask_annotator = sv.MaskAnnotator()
+ label_annotator = sv.LabelAnnotator()
+
+ annotated_image = mask_annotator.annotate(
+ scene=image, detections=detections)
+ annotated_image = label_annotator.annotate(
+ scene=annotated_image, detections=detections)
+ ```
+
+
diff --git a/docs/how_to/save_detections.md b/docs/how_to/save_detections.md
index 94de6c61..05d5faad 100644
--- a/docs/how_to/save_detections.md
+++ b/docs/how_to/save_detections.md
@@ -1,6 +1,5 @@
---
comments: true
-status: new
---
# Save Detections
diff --git a/docs/keypoint/annotators.md b/docs/keypoint/annotators.md
index b5f998bc..30a970ec 100644
--- a/docs/keypoint/annotators.md
+++ b/docs/keypoint/annotators.md
@@ -13,7 +13,10 @@ status: new
image = ...
key_points = sv.KeyPoints(...)
- vertex_annotator = sv.VertexAnnotator(color=sv.Color.GREEN, radius=10)
+ vertex_annotator = sv.VertexAnnotator(
+ color=sv.Color.GREEN,
+ radius=10
+ )
annotated_frame = vertex_annotator.annotate(
scene=image.copy(),
key_points=key_points
@@ -34,7 +37,10 @@ status: new
image = ...
key_points = sv.KeyPoints(...)
- edge_annotator = sv.EdgeAnnotator(color=sv.Color.GREEN, thickness=5)
+ edge_annotator = sv.EdgeAnnotator(
+ color=sv.Color.GREEN,
+ thickness=5
+ )
annotated_frame = edge_annotator.annotate(
scene=image.copy(),
key_points=key_points
@@ -47,6 +53,31 @@ status: new
+=== "VertexLabelAnnotator"
+
+ ```python
+ import supervision as sv
+
+ image = ...
+ key_points = sv.KeyPoints(...)
+
+ vertex_label_annotator = sv.VertexLabelAnnotator(
+ color=sv.Color.GREEN,
+ text_color=sv.Color.BLACK,
+ border_radius=5
+ )
+ annotated_frame = vertex_label_annotator.annotate(
+ scene=image.copy(),
+ key_points=key_points
+ )
+ ```
+
+
+
+ { align=center width="800" }
+
+
+