Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 28 additions & 15 deletions docs/how_to/detect_and_annotate.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ date_modified: 2026-04-22

# Detect and Annotate

!!! tip "Sample Image"

Don't have an image? Download the one used in this tutorial:

```bash
wget https://media.roboflow.com/notebooks/examples/dog.jpeg
```

```
Then replace `<SOURCE_IMAGE_PATH>` with `"dog.jpeg"`.
```

Supervision provides a seamless process for annotating predictions generated by various
object detection and segmentation models. This guide shows how to perform inference
with the [Inference](https://github.com/roboflow/inference),
Expand All @@ -37,7 +49,7 @@ To run inference, initialize your chosen model and pass the source image to its
from inference import get_model

model = get_model(model_id="yolov8n-640")
image = cv2.imread("<SOURCE_IMAGE_PATH>")
image = cv2.imread("dog.jpeg")
results = model.infer(image)[0]
```

Expand All @@ -48,7 +60,7 @@ To run inference, initialize your chosen model and pass the source image to its
from ultralytics import YOLO

model = YOLO("yolov8n.pt")
image = cv2.imread("<SOURCE_IMAGE_PATH>")
image = cv2.imread("dog.jpeg")
results = model(image)[0]
```

Expand All @@ -62,7 +74,7 @@ To run inference, initialize your chosen model and pass the source image to its
processor = DetrImageProcessor.from_pretrained("facebook/detr-resnet-50")
model = DetrForObjectDetection.from_pretrained("facebook/detr-resnet-50")

image = Image.open("<SOURCE_IMAGE_PATH>")
image = Image.open("dog.jpeg")
inputs = processor(images=image, return_tensors="pt")

with torch.no_grad():
Expand Down Expand Up @@ -91,7 +103,7 @@ Each supported framework has a dedicated class method on `sv.Detections` that co
from inference import get_model

model = get_model(model_id="yolov8n-640")
image = cv2.imread("<SOURCE_IMAGE_PATH>")
image = cv2.imread("dog.jpeg")
results = model.infer(image)[0]
detections = sv.Detections.from_inference(results)
```
Expand All @@ -106,7 +118,7 @@ Each supported framework has a dedicated class method on `sv.Detections` that co
from ultralytics import YOLO

model = YOLO("yolov8n.pt")
image = cv2.imread("<SOURCE_IMAGE_PATH>")
image = cv2.imread("dog.jpeg")
results = model(image)[0]
detections = sv.Detections.from_ultralytics(results)
```
Expand All @@ -124,7 +136,7 @@ Each supported framework has a dedicated class method on `sv.Detections` that co
processor = DetrImageProcessor.from_pretrained("facebook/detr-resnet-50")
model = DetrForObjectDetection.from_pretrained("facebook/detr-resnet-50")

image = Image.open("<SOURCE_IMAGE_PATH>")
image = Image.open("dog.jpeg")
inputs = processor(images=image, return_tensors="pt")

with torch.no_grad():
Expand Down Expand Up @@ -161,7 +173,7 @@ To draw bounding boxes and class labels on your image, create a `BoxAnnotator` a
from inference import get_model

model = get_model(model_id="yolov8n-640")
image = cv2.imread("<SOURCE_IMAGE_PATH>")
image = cv2.imread("dog.jpeg")
results = model.infer(image)[0]
detections = sv.Detections.from_inference(results)

Expand All @@ -182,7 +194,7 @@ To draw bounding boxes and class labels on your image, create a `BoxAnnotator` a
from ultralytics import YOLO

model = YOLO("yolov8n.pt")
image = cv2.imread("<SOURCE_IMAGE_PATH>")
image = cv2.imread("dog.jpeg")
results = model(image)[0]
detections = sv.Detections.from_ultralytics(results)

Expand All @@ -206,7 +218,7 @@ To draw bounding boxes and class labels on your image, create a `BoxAnnotator` a
processor = DetrImageProcessor.from_pretrained("facebook/detr-resnet-50")
model = DetrForObjectDetection.from_pretrained("facebook/detr-resnet-50")

image = Image.open("<SOURCE_IMAGE_PATH>")
image = Image.open("dog.jpeg")
inputs = processor(images=image, return_tensors="pt")

with torch.no_grad():
Expand Down Expand Up @@ -245,7 +257,7 @@ override this behavior by passing a list of custom `labels` to the `annotate` me
from inference import get_model

model = get_model(model_id="yolov8n-640")
image = cv2.imread("<SOURCE_IMAGE_PATH>")
image = cv2.imread("dog.jpeg")
results = model.infer(image)[0]
detections = sv.Detections.from_inference(results)

Expand All @@ -272,7 +284,7 @@ override this behavior by passing a list of custom `labels` to the `annotate` me
from ultralytics import YOLO

model = YOLO("yolov8n.pt")
image = cv2.imread("<SOURCE_IMAGE_PATH>")
image = cv2.imread("dog.jpeg")
results = model(image)[0]
detections = sv.Detections.from_ultralytics(results)

Expand Down Expand Up @@ -302,7 +314,7 @@ override this behavior by passing a list of custom `labels` to the `annotate` me
processor = DetrImageProcessor.from_pretrained("facebook/detr-resnet-50")
model = DetrForObjectDetection.from_pretrained("facebook/detr-resnet-50")

image = Image.open("<SOURCE_IMAGE_PATH>")
image = Image.open("dog.jpeg")
inputs = processor(images=image, return_tensors="pt")

with torch.no_grad():
Expand Down Expand Up @@ -349,7 +361,7 @@ that will allow you to draw masks instead of boxes.
from inference import get_model

model = get_model(model_id="yolov8n-seg-640")
image = cv2.imread("<SOURCE_IMAGE_PATH>")
image = cv2.imread("dog.jpeg")
results = model.infer(image)[0]
detections = sv.Detections.from_inference(results)

Expand All @@ -364,6 +376,7 @@ that will allow you to draw masks instead of boxes.
scene=annotated_image,
detections=detections,
)
sv.plot_image(annotated_image)
```

=== "Ultralytics"
Expand All @@ -374,7 +387,7 @@ that will allow you to draw masks instead of boxes.
from ultralytics import YOLO

model = YOLO("yolov8n-seg.pt")
image = cv2.imread("<SOURCE_IMAGE_PATH>")
image = cv2.imread("dog.jpeg")
results = model(image)[0]
detections = sv.Detections.from_ultralytics(results)

Expand Down Expand Up @@ -402,7 +415,7 @@ that will allow you to draw masks instead of boxes.
processor = DetrImageProcessor.from_pretrained("facebook/detr-resnet-50-panoptic")
model = DetrForSegmentation.from_pretrained("facebook/detr-resnet-50-panoptic")

image = Image.open("<SOURCE_IMAGE_PATH>")
image = Image.open("dog.jpeg")
inputs = processor(images=image, return_tensors="pt")

with torch.no_grad():
Expand Down
Loading