Uncertainty Quantification in Detection Transformers: Object-Level Calibration and Image-Level Reliability
Project description
Uncertainty Quantification in Detection Transformers
A lightweight Python toolkit for object-level calibration and image-level reliability evaluation
Documentation | Paper (TPAMI 2026) | GitHub | Issues
Young-Jin Park, Carson Sobolewski, and Navid Azizan (MIT)
Installation
Requirements: Python >= 3.9
pip install uq-detr
Core dependencies: numpy >= 1.20, scipy >= 1.7 only. No PyTorch required.
To run the tutorials (HuggingFace DETR inference on COCO), install the optional tutorial dependencies:
pip install uq-detr[tutorials]
This additionally installs torch >= 1.10, transformers >= 4.30, datasets >= 2.14, timm >= 0.9, and matplotlib >= 3.5.
Quick Start
import uq_detr
from uq_detr import Detections, GroundTruth
# Collect predictions and ground truths across the dataset
all_detections = []
all_ground_truths = []
for image, annotation in dataset: # your dataset loop
pred_boxes, pred_scores = model(image) # your model inference
all_detections.append(Detections(
boxes=pred_boxes, # (N, 4) xyxy absolute pixels
scores=pred_scores, # (N, C) class probabilities
))
all_ground_truths.append(GroundTruth(
boxes=annotation["boxes"], # (M, 4) xyxy absolute pixels
labels=annotation["labels"], # (M,)
))
# Evaluate calibration over the entire dataset
print("OCE: ", uq_detr.oce(all_detections, all_ground_truths).score)
print("D-ECE: ", uq_detr.dece(all_detections, all_ground_truths, tp_criterion="greedy").score)
print("LA-ECE:", uq_detr.laece(all_detections, all_ground_truths, tp_criterion="greedy").score)
print("LRP: ", uq_detr.lrp(all_detections, all_ground_truths).score)
Metrics
| Metric | Function | What it measures |
|---|---|---|
| OCE | uq_detr.oce() |
Object-level Calibration Error --- Brier score per GT object. Evaluates model + post-processing jointly. |
| D-ECE | uq_detr.dece() |
Detection ECE --- gap between confidence and precision. |
| LA-ECE | uq_detr.laece() |
Label-Aware ECE --- per-class ECE with IoU-weighted accuracy. |
| LRP | uq_detr.lrp() |
Localization Recall Precision --- combines FP, FN, and localization error. |
| ContrastiveConf | uq_detr.contrastive_conf() |
Image-level reliability via positive/negative confidence contrast. |
Working with DETR Outputs
For DETR models, pass all queries (before post-processing) and use select() to choose a post-processing strategy. This enables OCE's key feature: evaluating how well post-processing recovers the calibrated predictions.
from uq_detr import select
# all_queries: Detections with all 900 DETR queries for one image
# Try different post-processing strategies
for thr in [0.1, 0.3, 0.5, 0.7]:
filtered = select(all_queries, method="threshold", param=thr)
score = uq_detr.oce([filtered], [gt]).score
print(f" threshold={thr} -> OCE={score:.4f}")
Box Formats
Detections and GroundTruth expect xyxy boxes in absolute pixel coordinates. Use the built-in constructors for other formats:
# From DETR output (normalized cxcywh)
det = Detections.from_cxcywh(pred_boxes, scores, image_size=(H, W))
gt = GroundTruth.from_cxcywh(gt_boxes, gt_labels, image_size=(H, W))
# From COCO-format annotations (absolute xywh)
gt = GroundTruth.from_xywh(coco_boxes, labels)
# Or convert manually
from uq_detr import box_convert
boxes_xyxy = box_convert(pred_boxes, "cxcywh", "xyxy", image_size=(H, W))
Supported formats: "xyxy", "xywh", "cxcywh". Pass image_size=(H, W) to denormalize [0, 1] coordinates.
Hungarian Matching
The package includes a numpy reimplementation of the Hungarian matcher used in DETR variants (e.g., Deformable-DETR):
from uq_detr import hungarian_match
pred_idx, gt_idx = hungarian_match(
pred_logits, # (Q, C) raw logits
pred_boxes, # (Q, 4) cxcywh normalized
gt_labels, # (N,)
gt_boxes, # (N, 4) cxcywh normalized
)
Flexible Input: Three Ways to Create Detections
Detections accepts different combinations of scores and labels:
from uq_detr import Detections
# 1. Full class distributions (N, C) --- labels inferred via argmax
det = Detections(boxes=boxes, scores=class_probs) # labels auto-computed
# 2. Full class distributions + explicit labels
det = Detections(boxes=boxes, scores=class_probs, labels=pred_labels)
# 3. Max-confidence (N,) + labels --- e.g., from supervision or COCO JSON
det = Detections(boxes=boxes, scores=max_confidences, labels=pred_labels)
Mode 1 and 2 give exact OCE (multi-class Brier score). Mode 3 uses a binary Brier approximation for OCE --- useful for outputs from frameworks like supervision where only max-confidence is available. D-ECE, LA-ECE, and LRP work identically in all modes.
Citation
@article{park2024uqdetr,
title={Uncertainty Quantification in Detection Transformers: Object-Level Calibration and Image-Level Reliability},
author={Park, Young-Jin and Sobolewski, Carson and Azizan, Navid},
journal={IEEE Transactions on Pattern Analysis and Machine Intelligence},
year={2026}
}
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file uq_detr-0.1.1.tar.gz.
File metadata
- Download URL: uq_detr-0.1.1.tar.gz
- Upload date:
- Size: 22.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
34c0f38ea66a176485cb14c76fa1e28e2422be60bd03e397bdc9da8d55f47d55
|
|
| MD5 |
df48d184265b8ac0959bad3768819c4b
|
|
| BLAKE2b-256 |
6040dd28858f56d75b86e18d4e2cea0ee133ad1ed2c7a9188dd3b8d58edc221d
|
File details
Details for the file uq_detr-0.1.1-py3-none-any.whl.
File metadata
- Download URL: uq_detr-0.1.1-py3-none-any.whl
- Upload date:
- Size: 20.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b17affc4132c6e6f6d216c84a0702d4252ba457fcb2d272e3e91a5bc0bdf5ee6
|
|
| MD5 |
572a2cf4bcd3cd1f5a95cb5890aa507a
|
|
| BLAKE2b-256 |
11edf2ce6e101bd2b88c623676639bb821ac2a6935b4df66756dce80c9651a06
|