RF-DETR

1.6.4 · active · verified Fri Apr 17

RF-DETR is a PyTorch-based library for object detection and instance segmentation, implementing the DETR architecture with enhancements. It provides tools for training, inference, and deployment, integrating with PyTorch Lightning for composable training workflows. The library is actively maintained, with version 1.6.4 released recently, and receives frequent updates.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to load a pre-trained RF-DETR model, perform inference on an image URL, and inspect the returned detections object. It highlights recently added data fields like class names and source image/shape, which are useful for post-processing and visualization with libraries like `supervision`.

import supervision as sv
from rfdetr import RFDETRSmall

# Initialize model with pre-trained weights. Use "rfdetr-small" for the default.
# For a custom fine-tuned model: pretrain_weights="path/to/your/model.pth"
model = RFDETRSmall(pretrain_weights="rfdetr-small")

# Example image URL for prediction
image_url = "https://media.roboflow.com/dog.jpg"

# Perform inference with a confidence threshold
detections = model.predict(image_url, threshold=0.5)

print(f"Detected {len(detections)} objects.")

# Access new data points introduced in recent versions:
if "class_name" in detections.data:
    print(f"Class names: {detections.data['class_name']}")
if "source_image" in detections.data:
    print(f"Source image shape: {detections.data['source_shape']}")

# Visualize results (requires 'supervision' to be installed)
# image_bgr = detections.data.get("source_image")
# if image_bgr is not None:
#     box_annotator = sv.BoxAnnotator()
#     annotated_image = box_annotator.annotate(scene=image_bgr.copy(), detections=detections)
#     sv.plot_image(annotated_image, size=(8, 8))

view raw JSON →