feat(ANSODEngine): run Darknet/YOLO exports ("darknet" family) in ONNXYOLO and RTYOLO

A Darknet/YOLO model exported by hank-ai's darknet_onnx_export (v5.1+) has
two outputs: confs [B,N,nc], already objectness x class probability, and
boxes [B,N,1,4], corners x1,y1,x2,y2 normalized to the input. It trains and
predicts on a stretched square and has no NMS in the graph. ONNXYOLO took
the 4-D boxes tensor for segmentation proto masks and letterboxed the input,
so such a model decoded as garbage; a sealed package named as YOLOV4 went to
YOLOOD, which cannot open an .ansmodel at all.

- ONNXYOLO / RTYOLO: recognise the layout once at load (package family
  "darknet", output names confs/boxes, or their shapes), before the seg
  check; stretch-resize the input (single, batch, and RTYOLO's NV12 path);
  new postprocessDarknet: best class per candidate, threshold, stretch map
  to the original image, clip, class-aware NMS.
- dllmain: a sealed package passed as modelType 1 (YOLOV4) is routed as
  detection (3), i.e. to RTYOLO on NVIDIA and ONNXYOLO elsewhere, in
  CreateANSODHandle, CreateANSODHandleEx and OptimizeModelStr.
- Every other model is unchanged: all new branches are gated on the layout.

Verified on macOS only: ANSONNXYOLO.cpp passes a syntax check, and the new
decode functions, extracted into a standalone harness running the model
through onnxruntime, reproduce Darknet's own detections on dog.jpg. NOT yet
built on Windows, and the TensorRT path has not run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-26 18:43:13 +10:00
co-authored by Claude Opus 5.5
parent cb964907f0
commit 0baca1b20d
6 changed files with 378 additions and 8 deletions
+13
View File
@@ -22,6 +22,7 @@ namespace ANSCENTER {
// - Segmentation: legacy [B, nc+36, N]+protos or end2end [B, 300, 38]+protos
// - Pose : legacy [B, nc+4+nk*3, N] or end2end [B, 300, 6+nk*3]
// - Classification: [B, nc]
// - Darknet detect: confs [B,N,nc] + boxes [B,N,1,4] (stretch resize)
//
// Uses Engine<float> with GPU preprocessing (cv::cuda::GpuMat),
// supports multi-GPU pool via SetMaxSlotsPerGpu.
@@ -124,6 +125,18 @@ namespace ANSCENTER {
std::vector<float>& featureVector,
const std::string& camera_id, const ImageMetadata& meta);
// ── Darknet postprocessor (confs + boxes, no NMS in the graph) ───
std::vector<Object> PostprocessDarknet(
std::vector<std::vector<float>>& featureVectors,
const std::string& camera_id, const ImageMetadata& meta);
// Darknet/YOLO layout (hank-ai darknet_onnx_export): package family
// "darknet", or outputs shaped confs [B,N,nc] + boxes [B,N,1,4].
// Decided once, after the engine is loaded; selects the stretch
// resize (no letterbox) and PostprocessDarknet.
bool _isDarknet{ false };
void DetectDarknetLayout();
// ── OBB NMS helpers (Prob-IoU based) ─────────────────────────────
struct OrientedBox {
float x, y, width, height, angle;