Conformal object detection (bounding boxes)¶
Finite-sample containment guarantees for (N, 4) bounding boxes in [x1, y1, x2, y2] format — with NumPy as the only dependency.
| Use it when | You have predicted bounding boxes from any detector (YOLO, Faster R-CNN, DETR, RT-DETR) and want calibrated enclosing boxes that contain the ground-truth object with probability at least 1 - alpha. |
| Guarantee | Exact finite-sample containment P(B_true subset B_conf) >= 1 - alpha under exchangeability; per-category with groups=. |
| In the library | ConformalObjectDetector (additive, multiplicative, additive_coordinate, multiplicative_coordinate) |
| Source | De Grancey et al. (SAFECOMP 2022); Andéol, Fel, de Grancey and Herbin (COPA 2023) |
| Example needs | pyconformal |
Finite-sample containment guarantee
Across all four score modes (additive, multiplicative, additive_coordinate, multiplicative_coordinate), ConformalObjectDetector guarantees
$\(\mathbb{P}\!\left(B_{\text{true}} \subseteq \hat{B}_{\text{conf}}\right) \ge 1 - \alpha\)$
in finite samples under exchangeability, and within every object category when calibrated with groups=.
Minimal example¶
Copy, paste, run.
import numpy as np
from pyconformal import ConformalObjectDetector
rng = np.random.default_rng(0)
n = 1000
x1 = rng.uniform(20, 200, size=n)
y1 = rng.uniform(20, 200, size=n)
w = rng.uniform(20, 100, size=n)
h = rng.uniform(20, 100, size=n)
true_boxes = np.column_stack([x1, y1, x1 + w, y1 + h])
# Simulated detector outputs with size-proportional box error
dx = rng.normal(0.0, 4.0, size=(n, 2)) * (w[:, None] / 50.0)
dy = rng.normal(0.0, 4.0, size=(n, 2)) * (h[:, None] / 50.0)
pred_boxes = np.column_stack([
x1 + dx[:, 0],
y1 + dy[:, 0],
np.maximum(x1 + dx[:, 0] + 1.0, x1 + w + dx[:, 1]),
np.maximum(y1 + dy[:, 0] + 1.0, y1 + h + dy[:, 1]),
])
# Multiplicative (size-normalized) conformal boxes clipped to a 640x640 image
det = ConformalObjectDetector(alpha=0.1, method="multiplicative", clip_bounds=(0, 0, 640, 640))
det.calibrate(boxes_pred=pred_boxes[:500], boxes_true=true_boxes[:500])
conf_boxes = det.predict_boxes(boxes_pred=pred_boxes[500:])
containment = det.contains(conf_boxes, true_boxes[500:]).mean()
mean_iou = det.box_iou(conf_boxes, true_boxes[500:]).mean()
print(f"containment: {containment:.3f} mean IoU: {mean_iou:.3f}")
More¶
- Full argument list: API reference
- All methods: what's inside