AnchorGenerator<T>
Models & Types · AiDotNet.ComputerVision.Detection.Anchors
Generates anchor boxes for object detection models.
For Beginners
Anchor boxes (also called prior boxes) are pre-defined boxes of various sizes and aspect ratios placed at each location in the feature map. The detector predicts how to adjust these anchors to fit actual objects. Using anchors helps the model handle objects of different sizes and shapes.
How It Works
For example, a feature map of 80x80 with 3 anchors per location generates 80 x 80 x 3 = 19,200 anchor boxes, each representing a potential object location.
Constructors
| Constructor | Summary |
|---|---|
AnchorGenerator() |
Creates a new anchor generator with default YOLO-style anchors. |
AnchorGenerator(double[] baseSizes, double[] aspectRatios, double[] scales, int[] strides) |
Creates a new anchor generator with custom settings. |
Properties
| Property | Summary |
|---|---|
double[] AspectRatios { get; } |
Aspect ratios for anchors (height/width). |
double[] BaseSizes { get; } |
Base sizes for anchors at each feature level. |
double[] Scales { get; } |
Scales to apply to base sizes. |
int NumAnchorsPerLocation { get; } |
Gets the number of anchors per feature map location. |
int[] Strides { get; } |
Strides (downsampling factors) at each feature level. |
Methods
| Method | Summary |
|---|---|
AnchorGenerator<T> CreateFasterRCNNAnchors() |
Creates an anchor generator with Faster R-CNN style anchors. |
AnchorGenerator<T> CreateRetinaNetAnchors() |
Creates an anchor generator with RetinaNet style anchors. |
AnchorGenerator<T> CreateYOLOAnchors(double[] anchors, int[] strides) |
Creates an anchor generator with YOLO-style anchors. |
List<BoundingBox<T>> GenerateAnchorsForImage(int imageHeight, int imageWidth) |
Generates anchors for an image of specified size. |
List<BoundingBox<T>> GenerateAnchorsForLevel(int featureHeight, int featureWidth, int stride, double baseSize) |
Generates anchors for a single feature map level. |
List<List<BoundingBox<T>>> GenerateAnchors(List<ValueTuple<int, int>> featureSizes) |
Generates anchors for all feature levels. |
int GetTotalAnchorCount(int imageHeight, int imageWidth) |
Gets the total number of anchors for an image. |