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
+17
View File
@@ -434,6 +434,13 @@ extern "C" ANSODENGINE_API std::string CreateANSODHandle(ANSCENTER::ANSODBase**
// handler. Unlisted modelType values are left untouched for the switch below.
// See CreateANSODHandleEx for the full rationale — three correctness bugs
// were fixed in that dispatcher and must be kept in sync across copies.
// A sealed package is an ONNX model whatever legacy type the caller names.
// YOLOV4 = 1 goes to YOLOOD, which opens only a zip of .cfg/.weights and
// cannot read an .ansmodel; a Darknet/YOLO package (family "darknet") runs
// in the YOLO engines, which recognise its confs/boxes head. Routed as
// detection so the switch below picks TensorRT or ONNX for the hardware.
if (modelType == 1 && ANSCENTER::modelpkg::IsPackagePath(modelFilePath ? modelFilePath : ""))
modelType = 3;
const bool onNvidia = (engineType == ANSCENTER::EngineType::NVIDIA_GPU);
switch (modelType) {
// ── Detection family: YOLOv8 / V11 / V12 / generic TRT / V10-RTOD ──
@@ -816,6 +823,13 @@ extern "C" ANSODENGINE_API int CreateANSODHandleEx(ANSCENTER::ANSODBase** Handl
// passing modelType=20 for classification ended up with a YOLO head.
// (3) modelType == 22 / 24 (TRT pose / TRT seg) on a non-NVIDIA box fell
// back to ONNXYOLO instead of the correct ONNXPOSE / ONNXSEG handler.
// A sealed package is an ONNX model whatever legacy type the caller names.
// YOLOV4 = 1 goes to YOLOOD, which opens only a zip of .cfg/.weights and
// cannot read an .ansmodel; a Darknet/YOLO package (family "darknet") runs
// in the YOLO engines, which recognise its confs/boxes head. Routed as
// detection so the switch below picks TensorRT or ONNX for the hardware.
if (modelType == 1 && ANSCENTER::modelpkg::IsPackagePath(modelFilePath ? modelFilePath : ""))
modelType = 3;
const bool onNvidia = (engineType == ANSCENTER::EngineType::NVIDIA_GPU);
switch (modelType) {
// ── Detection family: YOLOv8 / V11 / V12 / generic TRT / V10-RTOD ──
@@ -1589,6 +1603,9 @@ ANSODENGINE_API int OptimizeModelStr(const char* modelFilePath, const char* mode
// inference tasks. The global mutex was blocking ALL running tasks'
// result delivery for the entire duration of TRT engine building.
ANSCENTER::EngineType engineType = ANSCENTER::ANSLicenseHelper::CheckHardwareInformation();
// Same rule as CreateANSODHandleEx: a sealed Darknet/YOLO package named
// as YOLOV4 = 1 is built in the YOLO engines, not YOLOOD.
if (modelType == 1 && sealedPackage) modelType = 3;
// Route detection / pose / segmentation / OBB / classification to the best