Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Roboflow Rf detr Supervision Annotators

From Leeroopedia


Knowledge Sources
Domains Computer_Vision, Visualization
Last Updated 2026-02-08 15:00 GMT

Overview

Wrapper for Supervision library annotators used with RF-DETR detection results, combined with the COCO_CLASSES dictionary for class name lookups.

Description

The supervision library (imported as sv) provides BoxAnnotator and LabelAnnotator classes for drawing bounding boxes and labels on images. RF-DETR returns sv.Detections objects directly, making visualization seamless. The COCO_CLASSES dictionary in RF-DETR maps COCO class IDs to human-readable names.

Usage

Use these annotators after calling model.predict() to visualize detection results. For fine-tuned models, use model.class_names instead of COCO_CLASSES.

Code Reference

Source Location

  • Repository: rf-detr
  • File: rfdetr/util/coco_classes.py
  • Lines: L7-88 (COCO_CLASSES dict)
  • External: supervision library (BoxAnnotator, LabelAnnotator)

Signature

# External supervision library
sv.BoxAnnotator().annotate(scene: np.ndarray, detections: sv.Detections) -> np.ndarray
sv.LabelAnnotator().annotate(scene: np.ndarray, detections: sv.Detections, labels: List[str]) -> np.ndarray

# RF-DETR class mapping
COCO_CLASSES: Dict[int, str] = {
    1: "person", 2: "bicycle", 3: "car", ...  # 80 COCO classes
}

Import

import supervision as sv
from rfdetr.util.coco_classes import COCO_CLASSES

I/O Contract

Inputs

Name Type Required Description
scene np.ndarray Yes Image as numpy array (BGR or RGB)
detections sv.Detections Yes Detection results from RFDETR.predict()
labels List[str] No Human-readable labels for each detection
COCO_CLASSES Dict[int, str] No Maps class IDs to names (80 COCO categories)

Outputs

Name Type Description
annotated_image np.ndarray Image with bounding boxes and labels drawn

Usage Examples

Basic Visualization

import cv2
import supervision as sv
from rfdetr import RFDETRBase

model = RFDETRBase()
image = cv2.imread("image.jpg")
detections = model.predict("image.jpg")

# Create annotators
box_annotator = sv.BoxAnnotator()
label_annotator = sv.LabelAnnotator()

# Build labels from class names
class_names = model.class_names
labels = [
    f"{class_names[cid]} {conf:.2f}"
    for cid, conf in zip(detections.class_id, detections.confidence)
]

# Annotate image
annotated = box_annotator.annotate(scene=image.copy(), detections=detections)
annotated = label_annotator.annotate(scene=annotated, detections=detections, labels=labels)

cv2.imwrite("annotated.jpg", annotated)

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment