[Bug]: oriented-box IoU exactly on 0.55/0.6/0.8/0.85 misses that threshold in MeanAverageRecall, Precision, Recall and F1Score
Search before asking
- [x] I have searched the issues and discussions and found no similar bug report.
Bug
With metric_target=MetricTarget.ORIENTED_BOUNDING_BOXES, a prediction whose IoU is exactly 0.55, 0.6, 0.8 or 0.85 is counted as a miss at that threshold by MeanAverageRecall, Precision, Recall and F1Score. The same geometry as BOXES counts as a match, and so does MeanAveragePrecision.
The thresholds are np.linspace(0.5, 0.95, 10, dtype=np.float32) (mean_average_recall.py and _confusion_matrix_metric.py). In float32, 0.55, 0.6, 0.8 and 0.85 round up, so 0.6 becomes 0.6000000238. box_iou_batch and mask_iou_batch return float32, so an exact 0.6 IoU equals the float32 threshold. oriented_box_iou_batch returns float64, so the same 0.6 falls just below it. #2638 fixed this kind of float32/float64 mismatch for MeanAveragePrecision and listed these four metrics as out of scope.
Environment
- supervision
develop@ 927dfeb05 (0.31.0) - macOS arm64, Python 3.12.13, NumPy 2.3.1
Minimal Reproducible Example
Target [0, 0, 10, 10], prediction [0, 1, 14, 11]: overlap 90, union 150, IoU 0.6.
import numpy as np
import supervision as sv
from supervision.config import ORIENTED_BOX_COORDINATES
from supervision.metrics import MetricTarget, Recall
def detections(xyxy, confidence=None):
x0, y0, x1, y1 = xyxy
return sv.Detections(
xyxy=np.array([xyxy], dtype=np.float64),
class_id=np.array([0]),
confidence=None if confidence is None else np.array([confidence]),
data={ORIENTED_BOX_COORDINATES: np.array([[[x0, y0], [x1, y0], [x1, y1], [x0, y1]]], dtype=np.float64)},
)
predictions, targets = detections([0, 1, 14, 11], 0.9), detections([0, 0, 10, 10])
for target in (MetricTarget.BOXES, MetricTarget.ORIENTED_BOUNDING_BOXES):
print(target, Recall(metric_target=target).update(predictions, targets).compute().recall_scores[:3])
# MetricTarget.BOXES [1. 1. 1.]
# MetricTarget.ORIENTED_BOUNDING_BOXES [1. 1. 0.] <- the 0.6 threshold misses
Are you willing to submit a PR?
- [x] Yes I'd like to help by submitting a PR!