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 Save GT Predictions Visualization

From Leeroopedia


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

Overview

Utility function that generates annotated visualization images showing ground truth and predicted bounding boxes side-by-side for detection result inspection.

Description

The save_gt_predictions_visualization function creates a diagnostic image comparing ground truth annotations with model predictions. It builds a blank canvas with 60px top padding, converts xywh bounding boxes to xyxy format using supervision's converter, and creates separate sv.Detections objects for GT and predictions. GT boxes are drawn in green/cyan tones at the top-left position; prediction boxes in orange/pink at top-right. Prediction labels include class ID, confidence score, and optionally IoU value when available. The annotated image is saved as PNG to the specified directory. Both empty GT and empty prediction cases are handled gracefully.

Usage

Use this function during model development and testing to visually inspect how predictions compare against ground truth annotations. The IoU display helps diagnose localization quality. This is primarily used by test utilities and debugging workflows, not for production inference.

Code Reference

Source Location

Signature

def save_gt_predictions_visualization(
    scenario_name: str,
    image_width: int,
    image_height: int,
    gt_boxes: list[list[float]],
    gt_class_ids: list[int],
    pred_boxes: list[list[float]],
    pred_class_ids: list[int],
    pred_confidences: list[float],
    pred_ious: list[float | None],
    save_dir: Path,
) -> None:
    """
    Save a visualization image showing both GT and prediction boxes.

    Boxes are labeled with class ID and confidence (for predictions).
    For predictions with known IoU, the IoU value is also shown.
    """
    ...

Import

from rfdetr.util.visualize import save_gt_predictions_visualization

I/O Contract

Inputs

Name Type Required Description
scenario_name str Yes Name used for the output PNG filename
image_width int Yes Width of the blank canvas in pixels
image_height int Yes Height of the blank canvas in pixels
gt_boxes list[list[float]] Yes Ground truth boxes in xywh format
gt_class_ids list[int] Yes Class IDs for each ground truth box
pred_boxes list[list[float]] Yes Predicted boxes in xywh format
pred_class_ids list[int] Yes Class IDs for each prediction
pred_confidences list[float] Yes Confidence scores for each prediction
pred_ious list[float or None] Yes IoU with matched GT box (None if unmatched)
save_dir Path Yes Directory to save the output PNG image

Outputs

Name Type Description
PNG file File Annotated image saved as {save_dir}/{scenario_name}.png

Usage Examples

Basic Visualization

from pathlib import Path
from rfdetr.util.visualize import save_gt_predictions_visualization

save_gt_predictions_visualization(
    scenario_name="test_case_001",
    image_width=640,
    image_height=480,
    gt_boxes=[[100, 100, 50, 60], [300, 200, 80, 90]],
    gt_class_ids=[1, 2],
    pred_boxes=[[102, 98, 52, 62], [305, 195, 78, 88]],
    pred_class_ids=[1, 2],
    pred_confidences=[0.95, 0.87],
    pred_ious=[0.85, 0.78],
    save_dir=Path("debug_output"),
)
# Saves: debug_output/test_case_001.png

Visualization with Unmatched Predictions

from pathlib import Path
from rfdetr.util.visualize import save_gt_predictions_visualization

# Some predictions may not match any GT box (IoU=None)
save_gt_predictions_visualization(
    scenario_name="false_positives",
    image_width=640,
    image_height=480,
    gt_boxes=[[100, 100, 50, 60]],
    gt_class_ids=[1],
    pred_boxes=[[102, 98, 52, 62], [500, 400, 30, 30]],
    pred_class_ids=[1, 1],
    pred_confidences=[0.95, 0.42],
    pred_ious=[0.85, None],  # Second prediction is a false positive
    save_dir=Path("debug_output"),
)

Related Pages

Page Connections

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