Implementation:Roboflow Rf detr Evaluate
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Object_Detection, Evaluation |
| Last Updated | 2026-02-08 15:00 GMT |
Overview
Concrete tool for evaluating RF-DETR model performance using COCO metrics and extended precision/recall/F1 analysis.
Description
evaluate() runs the model over a validation DataLoader, computes losses, collects predictions via PostProcess, and passes them to CocoEvaluator for standard COCO metric computation. coco_extended_metrics() then analyzes the raw COCO evaluation data to produce per-class precision, recall, and F1 scores at the optimal confidence threshold.
Usage
Called automatically at the end of each training epoch. Also used for standalone evaluation when resuming from a checkpoint.
Code Reference
Source Location
- Repository: rf-detr
- File: rfdetr/engine.py
- Lines: L363-453 (evaluate), L239-361 (coco_extended_metrics)
- File: rfdetr/datasets/coco_eval.py
- Lines: L37-50 (CocoEvaluator.__init__)
Signature
def evaluate(
model: torch.nn.Module,
criterion: torch.nn.Module,
postprocess: PostProcess,
data_loader: DataLoader,
base_ds: COCO,
device: torch.device,
args=None,
) -> Tuple[Dict, CocoEvaluator]:
"""
Evaluate model on validation set.
Returns:
test_stats: Dict with coco_eval_bbox (12-element stats),
results_json (per-class metrics)
coco_evaluator: CocoEvaluator instance
"""
def coco_extended_metrics(coco_eval: COCOeval) -> Dict:
"""
Compute per-class precision/recall/F1 by sweeping confidence thresholds.
Returns:
Dict with class_map, map, precision, recall, f1_score
"""
Import
from rfdetr.engine import evaluate, coco_extended_metrics
from rfdetr.datasets.coco_eval import CocoEvaluator
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| model | torch.nn.Module | Yes | Model to evaluate |
| criterion | torch.nn.Module | Yes | Loss function (SetCriterion) |
| postprocess | PostProcess | Yes | Post-processing for converting outputs to detections |
| data_loader | DataLoader | Yes | Validation data loader |
| base_ds | COCO | Yes | Ground truth COCO API object |
| args.fp16_eval | bool | No | Half-precision evaluation (default: False) |
| args.eval_max_dets | int | No | Max detections for evaluation (default: 500) |
Outputs
| Name | Type | Description |
|---|---|---|
| test_stats | Dict | Contains coco_eval_bbox (12 COCO stats), results_json (per-class metrics) |
| coco_evaluator | CocoEvaluator | Full evaluation results object |
Usage Examples
Evaluation During Training
# Called automatically within Model.train() each epoch:
test_stats, coco_evaluator = evaluate(
model, criterion, postprocess, data_loader_val, base_ds, device, args=args
)
# Access mAP
map_50_95 = test_stats["coco_eval_bbox"][0]
map_50 = test_stats["coco_eval_bbox"][1]
# Access per-class metrics
per_class = test_stats["results_json"]["class_map"]
Related Pages
Implements Principle
Requires Environment
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment