ObjectDetectionMetrics<T>

Models & Types · AiDotNet.Metrics

COCO-style evaluation metrics for object detection: Average Precision (AP), mean Average Precision (mAP) and the underlying precision-recall curve.

For Beginners

IoU (intersection over union) measures how much a predicted box overlaps a real one: 1.0 means identical, 0.0 means no overlap at all. An IoU threshold of 0.5 says a prediction counts as correct if it covers at least half the union of itself and the real box. Average Precision then rolls the whole precision/recall trade-off into a single number between 0 and 1, where higher is better. Reporting mAP@[.50:.95] rather than mAP@0.5 is the stricter, modern convention because it also asks the box to be tightly placed, not merely in roughly the right spot.

How It Works

These are the metrics the object-detection literature reports. A detector emits a set of detections per image, each carrying a box, a class and a confidence score. Evaluation matches those predictions against ground-truth detections and summarises the quality of the ranking. Ground truth is expressed with the same Detection type, of which only Box and ClassId are read - its confidence is ignored.

The matching rule (COCO / Pascal VOC): predictions for one class are sorted by confidence, highest first. Each prediction is matched greedily to the highest-IoU ground-truth box of the same class in the same image that has not already been claimed. A match with IoU at or above the threshold is a true positive; anything else is a false positive. Ground-truth boxes that end up unmatched are false negatives. This one-to-one, highest-confidence-wins rule is what stops a detector from inflating its score by emitting many overlapping boxes for the same object.

Interpolation: AP is the area under the precision-recall curve. COCO computes it by sampling the curve at 101 evenly spaced recall levels (0.00, 0.01, … 1.00) and, at each level, taking the highest precision observed at that recall or beyond. That highest-precision-at-or-beyond step removes the small downward wiggles the raw curve has, which would otherwise make the score depend on ties in the confidence ordering.

Which number to report:

widely quoted number.

COCO metric: mAP averaged over ten IoU thresholds from 0.50 to 0.95. It rewards precise localisation, so it is always lower than mAP@0.5.

Constructors

Constructor Summary
ObjectDetectionMetrics() Initializes a new instance of the ObjectDetectionMetrics class.

Methods

Method Summary
ValueTuple<double[], double[]> PrecisionRecallCurve(IReadOnlyList<IReadOnlyList<Detection<T>>> predictions, IReadOnlyList<IReadOnlyList<Detection<T>>> groundTruth, int classIndex, double iouThreshold) Computes the raw (uninterpolated) precision-recall curve for one class, in descending confidence order.
double AveragePrecision(IReadOnlyList<IReadOnlyList<Detection<T>>> predictions, IReadOnlyList<IReadOnlyList<Detection<T>>> groundTruth, int classIndex, double iouThreshold) Computes Average Precision for a single class at one IoU threshold.
double MeanAveragePrecision(IReadOnlyList<IReadOnlyList<Detection<T>>> predictions, IReadOnlyList<IReadOnlyList<Detection<T>>> groundTruth, double iouThreshold) Computes mean Average Precision at one IoU threshold: the mean of the per-class AveragePrecision over every class that has at least one ground-truth box.
double MeanAveragePrecisionRange(IReadOnlyList<IReadOnlyList<Detection<T>>> predictions, IReadOnlyList<IReadOnlyList<Detection<T>>> groundTruth, double minIoU, double maxIoU, double step) Computes COCO mAP@[.50:.95]: MeanAveragePrecision averaged over a range of IoU thresholds.