generateEfficientDetAnchors function

List<List<double>> generateEfficientDetAnchors({
  1. required int imageSize,
  2. int minLevel = 3,
  3. int maxLevel = 7,
  4. int numScales = 3,
  5. List<double> aspectRatios = const [1.0, 2.0, 0.5],
  6. double anchorScale = 4.0,
})

Generates EfficientDet RetinaNet-style multi-scale anchors.

EfficientDet uses 5 feature pyramid levels (P3-P7) with numScales (3) × aspectRatios.length (3) = 9 anchors per spatial location. Anchors are returned in normalized image coordinates as [cx, cy, w, h].

For Lite0 with imageSize=320, total anchors = 19 206. For Lite2 with imageSize=448, total anchors = 37 629.

The detector itself uses generateEfficientDetAnchorsFlat; this nested-list view is kept for callers that want to inspect anchors one at a time.

Implementation

List<List<double>> generateEfficientDetAnchors({
  required int imageSize,
  int minLevel = 3,
  int maxLevel = 7,
  int numScales = 3,
  List<double> aspectRatios = const [1.0, 2.0, 0.5],
  double anchorScale = 4.0,
}) {
  final Float32List flat = generateEfficientDetAnchorsFlat(
    imageSize: imageSize,
    minLevel: minLevel,
    maxLevel: maxLevel,
    numScales: numScales,
    aspectRatios: aspectRatios,
    anchorScale: anchorScale,
  );
  return List<List<double>>.generate(
    flat.length ~/ 4,
    (i) => <double>[
      flat[i * 4],
      flat[i * 4 + 1],
      flat[i * 4 + 2],
      flat[i * 4 + 3],
    ],
    growable: false,
  );
}