Class AnchorMatcher<T>
- Namespace
- AiDotNet.ComputerVision.Detection.Anchors
- Assembly
- AiDotNet.dll
Matches anchor boxes to ground truth boxes for training object detectors.
public class AnchorMatcher<T>
Type Parameters
TThe numeric type used for calculations.
- Inheritance
-
AnchorMatcher<T>
- Inherited Members
Remarks
For Beginners: During training, we need to assign each anchor box to either: - A ground truth box (positive sample): The anchor should predict this object - Background (negative sample): The anchor should predict "no object" - Ignore: The anchor is borderline and excluded from loss calculation
This matching process determines which anchors learn to detect which objects.
Constructors
AnchorMatcher()
Creates a new anchor matcher with default thresholds.
public AnchorMatcher()
AnchorMatcher(double, double, bool)
Creates a new anchor matcher with custom thresholds.
public AnchorMatcher(double positiveThreshold, double negativeThreshold, bool allowLowQualityMatches = true)
Parameters
positiveThresholddoubleIoU threshold for positive matches.
negativeThresholddoubleIoU threshold for negative matches.
allowLowQualityMatchesboolWhether to match best anchor per GT regardless of threshold.
Properties
AllowLowQualityMatches
Whether to allow low-quality matches (best anchor for each GT even if below threshold).
public bool AllowLowQualityMatches { get; }
Property Value
NegativeThreshold
IoU threshold below which an anchor is considered negative.
public double NegativeThreshold { get; }
Property Value
PositiveThreshold
IoU threshold above which an anchor is considered positive.
public double PositiveThreshold { get; }
Property Value
Methods
Match(List<BoundingBox<T>>, List<BoundingBox<T>>)
Matches anchors to ground truth boxes.
public AnchorMatchResult<T> Match(List<BoundingBox<T>> anchors, List<BoundingBox<T>> groundTruth)
Parameters
anchorsList<BoundingBox<T>>List of anchor boxes.
groundTruthList<BoundingBox<T>>List of ground truth boxes.
Returns
- AnchorMatchResult<T>
Match result containing assignments for each anchor.
Remarks
For Beginners: This method looks at each anchor and decides: - If it overlaps enough with a ground truth box → match to that box - If it doesn't overlap much with any box → mark as background - If it's in between → ignore during training
MatchCenterBased(List<(double X, double Y)>, List<BoundingBox<T>>, List<int>)
Matches anchors using center-based assignment (used in FCOS, YOLOX).
public AnchorMatchResult<T> MatchCenterBased(List<(double X, double Y)> anchorCenters, List<BoundingBox<T>> groundTruth, List<int> anchorStrides)
Parameters
anchorCentersList<(double X, double Y)>groundTruthList<BoundingBox<T>>List of ground truth boxes.
anchorStridesList<int>
Returns
- AnchorMatchResult<T>
Match result with center-based assignment.
Remarks
For Beginners: Center-based matching assigns an anchor to a GT box if the anchor's center point falls inside the GT box. This is used by anchor-free detectors like FCOS and YOLOX.
MatchSimOTA(List<BoundingBox<T>>, List<BoundingBox<T>>, List<BoundingBox<T>>, List<double>)
Matches anchors using SimOTA (used in YOLOX).
public AnchorMatchResult<T> MatchSimOTA(List<BoundingBox<T>> anchors, List<BoundingBox<T>> groundTruth, List<BoundingBox<T>> predictions, List<double> predScores)
Parameters
anchorsList<BoundingBox<T>>List of anchor boxes.
groundTruthList<BoundingBox<T>>List of ground truth boxes.
predictionsList<BoundingBox<T>>Predicted boxes for cost calculation.
predScoresList<double>Predicted scores for cost calculation.
Returns
- AnchorMatchResult<T>
Match result using optimal transport assignment.
Remarks
For Beginners: SimOTA (Simplified Optimal Transport Assignment) is an advanced matching strategy that considers both location and predicted confidence to make better assignments. It dynamically decides how many anchors each GT gets.