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 RFDETR Predict

From Leeroopedia


Knowledge Sources
Domains Object_Detection, Inference
Last Updated 2026-02-08 15:00 GMT

Overview

Concrete tool for running object detection inference on images provided by the RF-DETR library.

Description

RFDETR.predict() is the primary user-facing inference method. It handles the complete pipeline: accepting diverse input formats (file paths, PIL Images, numpy arrays, tensors), preprocessing, model forward pass, post-processing via PostProcess, confidence thresholding, and returning supervision.Detections objects. It supports both standard and JIT-optimized inference modes.

Usage

Call this method on any initialized RFDETR model instance to detect objects in one or more images.

Code Reference

Source Location

  • Repository: rf-detr
  • File: rfdetr/detr.py
  • Lines: L266-403

Signature

def predict(
    self,
    images: Union[
        str, Image.Image, np.ndarray, torch.Tensor,
        List[Union[str, np.ndarray, Image.Image, torch.Tensor]]
    ],
    threshold: float = 0.5,
    **kwargs,
) -> Union[sv.Detections, List[sv.Detections]]:
    """
    Performs object detection on the input images.

    Args:
        images: A single image or list of images (file paths,
                PIL Images, NumPy arrays, or torch Tensors in RGB).
        threshold: Minimum confidence score (default: 0.5).

    Returns:
        sv.Detections or List[sv.Detections] with xyxy boxes,
        confidence scores, and class IDs.
    """

Import

from rfdetr import RFDETRBase  # or any size variant

I/O Contract

Inputs

Name Type Required Description
images Union[str, Image, ndarray, Tensor, List[...]] Yes Single image or list of images in RGB order
threshold float No Minimum confidence score (default: 0.5)

Outputs

Name Type Description
detections sv.Detections or List[sv.Detections] Bounding boxes (xyxy), confidence scores, class IDs; optionally masks for segmentation models

Usage Examples

Single Image Prediction

from rfdetr import RFDETRBase

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

print(detections.xyxy)        # Bounding boxes [[x1, y1, x2, y2], ...]
print(detections.confidence)  # Confidence scores [0.95, 0.87, ...]
print(detections.class_id)    # Class IDs [0, 1, ...]

Batch Prediction

from rfdetr import RFDETRBase

model = RFDETRBase()
results = model.predict(["img1.jpg", "img2.jpg", "img3.jpg"], threshold=0.3)

for det in results:
    print(f"Found {len(det)} objects")

Optimized Inference

from rfdetr import RFDETRBase

model = RFDETRBase()
model.optimize_for_inference(compile=True, batch_size=1)

# Subsequent predictions use the optimized (JIT-traced) model
detections = model.predict("image.jpg")

Related Pages

Implements Principle

Requires Environment

Page Connections

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