TextDetectionMetrics<T>
Models & Types · AiDotNet.Metrics
ICDAR-style evaluation metrics for text detection: polygon IoU, and the precision, recall and H-mean triple that the ICDAR Robust Reading competitions report.
For Beginners
Precision asks “of the regions the model reported, how many were real text?” Recall asks “of the real text, how much did the model find?” A model can score perfectly on one by sacrificing the other - report everything for perfect recall, report only the single most obvious word for perfect precision. H-mean combines them so that a model has to do well at both: it is close to the smaller of the two, so one bad number drags it down.
How It Works
Text detectors localise words or lines as quadrilaterals or polygons rather than axis-aligned boxes, because printed and scene text is frequently rotated or curved. Evaluation therefore works on polygon overlap, not box overlap.
The ICDAR 2015 IoU protocol. Within each image, predictions are considered in descending confidence order and matched one-to-one against ground-truth regions: a prediction claims the unmatched ground-truth region it overlaps most, provided that overlap reaches the IoU threshold (0.5 by convention). Then precision is matched / predicted, recall is matched / ground-truth, and H-mean is their harmonic mean. H-mean is the number competitions rank on.
Convexity.PolygonIoU computes the intersection by Sutherland-Hodgman clipping, which is
exact when the second polygon is convex. Detector output for word- and line-level text is
quadrilateral or near-convex, which is the case the ICDAR protocol is defined over. For a
strongly concave polygon (a curved-text detector emitting a banana-shaped region) the
intersection can be over-estimated, so treat such scores as approximate.
Constructors
| Constructor | Summary |
|---|---|
TextDetectionMetrics() |
Initializes a new instance of the TextDetectionMetrics class. |
Methods
| Method | Summary |
|---|---|
T PolygonArea(IReadOnlyList<ValueTuple<T, T>> polygon) |
Computes the area of a simple polygon using the shoelace formula. |
T PolygonIoU(IReadOnlyList<ValueTuple<T, T>> first, IReadOnlyList<ValueTuple<T, T>> second) |
Computes intersection-over-union between two polygons. |
ValueTuple<T, T, T> Evaluate(IReadOnlyList<IReadOnlyList<TextRegion<T>>> predictions, IReadOnlyList<IReadOnlyList<TextRegion<T>>> groundTruth, double iouThreshold) |
Evaluates detected text regions against ground truth using the ICDAR IoU protocol. |