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:
@@ -19,6 +19,7 @@ namespace ANSCENTER {
|
||||
// - Segmentation: [B,300,38]+protos or [B, nc+36, N]+protos
|
||||
// - Pose : [B,300,6+nk*3] or [B, nc+4+nk*3, N] legacy
|
||||
// - Classification: [B, nc]
|
||||
// - Darknet detect: confs [B,N,nc] + boxes [B,N,1,4] (stretch resize)
|
||||
//
|
||||
// Preprocessing follows the exact Ultralytics LetterBox transform:
|
||||
// - center=True, stride=32, pad_value=114
|
||||
@@ -95,6 +96,14 @@ namespace ANSCENTER {
|
||||
/// True if the ONNX model has dynamic spatial dimensions.
|
||||
bool hasDynamicInputShape() const { return isDynamicInputShape; }
|
||||
|
||||
/// Darknet/YOLO layout (hank-ai darknet_onnx_export): outputs
|
||||
/// confs [B,N,nc] + boxes [B,N,1,4], stretch resize, no letterbox.
|
||||
/// Detected from the output names/shapes at construction; the
|
||||
/// wrapper also forces it when an .ansmodel package says its
|
||||
/// family is "darknet".
|
||||
void setDarknetLayout(bool darknet) { isDarknetLayout = darknet; }
|
||||
bool hasDarknetLayout() const { return isDarknetLayout; }
|
||||
|
||||
private:
|
||||
Ort::Value transform(const cv::Mat& mat) override;
|
||||
Ort::Value transformBatch(const std::vector<cv::Mat>& images) override;
|
||||
@@ -155,6 +164,13 @@ namespace ANSCENTER {
|
||||
const std::vector<std::string>& classNames,
|
||||
float confThreshold, float iouThreshold, int numKPS, int maxDet = 300);
|
||||
|
||||
// ── Darknet postprocess (confs + boxes, no NMS in the graph) ────
|
||||
std::vector<Object> postprocessDarknet(
|
||||
const cv::Size& originalImageSize,
|
||||
std::vector<Ort::Value>& outputTensors,
|
||||
const std::vector<std::string>& classNames,
|
||||
float confThreshold, float iouThreshold, int maxDet = 300);
|
||||
|
||||
// ── Classification postprocess ──────────────────────────────────
|
||||
std::vector<Object> postprocessClassify(
|
||||
std::vector<Ort::Value>& outputTensors,
|
||||
@@ -189,6 +205,12 @@ namespace ANSCENTER {
|
||||
cv::Size inputImageShape;
|
||||
bool isDynamicInputShape{ false };
|
||||
|
||||
// Darknet layout: decided once at load time (see setDarknetLayout).
|
||||
// Selects the stretch resize in transformInto / transformBatchInto
|
||||
// and postprocessDarknet in detect / detectBatch.
|
||||
bool isDarknetLayout{ false };
|
||||
void detectDarknetLayout();
|
||||
|
||||
// Per-call preprocess that writes into caller-provided buffer + dims
|
||||
// instead of the BasicOrtHandler members (input_values_handler /
|
||||
// input_node_dims). detect() / detectBatch() use these so multiple
|
||||
|
||||
Reference in New Issue
Block a user