diff --git a/core/ANSLicensingSystem/ANSLicense.h b/core/ANSLicensingSystem/ANSLicense.h index 03763bf..d12a783 100644 --- a/core/ANSLicensingSystem/ANSLicense.h +++ b/core/ANSLicensingSystem/ANSLicense.h @@ -266,18 +266,28 @@ namespace ANSCENTER UNLICENSE = 3 }; struct ModelConfig { - DetectionType detectionType; - ModelType modelType; - PrecisionType precisionType; - int inpWidth; - int inpHeight; - float modelConfThreshold; - float modelMNSThreshold; - float detectionScoreThreshold; - int numKPS; // Number of pose keypoint - float kpsThreshold; - bool autoGPUDetection; - float unknownPersonThreshold; + // All POD members default-initialized. Several callers (notably + // CreateANSODHandle in ANSODEngine/dllmain.cpp) declare a local + // ModelConfig and only set a subset of fields before passing it + // to ANSODBase::Initialize. Without these defaults inpWidth / + // inpHeight enter Initialize() as indeterminate stack values; the + // existing `<=0 → 640` guard in ANSONNXYOLO::Initialize only + // catches non-positive garbage, so a small positive stack value + // (e.g. 80) would slip through and end up driving the ORT + // session at 80x80 — which crashes YOLOv11 in /model.12/Concat + // because 2*ceil(80/32) ≠ ceil(80/16) in the FPN. + DetectionType detectionType{}; + ModelType modelType{}; + PrecisionType precisionType{}; + int inpWidth = 0; + int inpHeight = 0; + float modelConfThreshold = 0.0f; + float modelMNSThreshold = 0.0f; + float detectionScoreThreshold = 0.0f; + int numKPS = 0; // Number of pose keypoint + float kpsThreshold = 0.0f; + bool autoGPUDetection = false; + float unknownPersonThreshold = 0.0f; int gpuOptBatchSize = 1; // The batch size which should be optimized for. int gpuMaxBatchSize = 1; // Maximum allowable batch size int gpuDeviceIndex = 0; // GPU device index diff --git a/modules/ANSODEngine/ANSONNXYOLO.cpp b/modules/ANSODEngine/ANSONNXYOLO.cpp index 5171a82..77adb64 100644 --- a/modules/ANSODEngine/ANSONNXYOLO.cpp +++ b/modules/ANSODEngine/ANSONNXYOLO.cpp @@ -116,6 +116,20 @@ namespace ANSCENTER { const int width = canvas.cols; const size_t imageSize = static_cast(height) * width; + // Diagnostics — log the very first transform() per ONNXYOLO so a + // future ORT shape-mismatch failure (e.g. /model.12/Concat for + // non-stride-32 inputs) points at the offending HxW directly. + // One line per session — does not flood DebugView. + static thread_local const ONNXYOLO* s_loggedFirst = nullptr; + if (s_loggedFirst != this) { + s_loggedFirst = this; + ANS_DBG("ONNXYOLO", + "transform[first]: inputImageShape=(%dx%d) canvas=%dx%d cls=%d src=%dx%d dyn=%d", + inputImageShape.width, inputImageShape.height, width, height, + isClassification ? 1 : 0, mat.cols, mat.rows, + isDynamicInputShape ? 1 : 0); + } + input_node_dims = { 1, 3, height, width }; input_tensor_size = 1 * 3 * imageSize; input_values_handler.resize(input_tensor_size); @@ -1702,13 +1716,26 @@ namespace ANSCENTER { const int w = std::clamp(rawW, kMinDim, kMaxDim); const int h = std::clamp(rawH, kMinDim, kMaxDim); + // Stride alignment guard — YOLOv8/v11/v12 FPN concats only line + // up when H,W are multiples of 32. A non-aligned warm-up size + // would crash inside /model.12/Concat with a 5-vs-6 shape error + // and the warning would mask any real engine load failure. + if ((w % 32) != 0 || (h % 32) != 0) { + _logger.LogWarn("ANSONNXYOLO::WarmUpEngine", + "Warm-up skipped — dims not multiple of stride 32 (" + + std::to_string(w) + "x" + std::to_string(h) + ")", + __FILE__, __LINE__); + return; + } + try { // Mid-gray BGR image matches the letterbox fill colour used in // preprocessing (114,114,114 ~ 128) and avoids degenerate inputs. cv::Mat dummy(h, w, CV_8UC3, cv::Scalar(128, 128, 128)); - ANS_DBG("ONNXYOLO", "Warm-up: running 1 dummy %s inference (%dx%d)", - (et == EngineType::NVIDIA_GPU) ? "CUDA" : "DirectML", w, h); + ANS_DBG("ONNXYOLO", "Warm-up: running 1 dummy %s inference (%dx%d) cfg=(%dx%d) raw=(%dx%d)", + (et == EngineType::NVIDIA_GPU) ? "CUDA" : "DirectML", + w, h, _modelConfig.inpWidth, _modelConfig.inpHeight, rawW, rawH); auto t0 = std::chrono::steady_clock::now(); (void)m_ortEngine->detect(dummy, _classes, diff --git a/modules/ANSODEngine/ANSONNXYOLO.h b/modules/ANSODEngine/ANSONNXYOLO.h index 52794ae..3c51b6f 100644 --- a/modules/ANSODEngine/ANSONNXYOLO.h +++ b/modules/ANSODEngine/ANSONNXYOLO.h @@ -62,8 +62,24 @@ namespace ANSCENTER { /// Override the input image shape for dynamic-input models. /// Call after construction when the model config specifies a /// different resolution than the default 640x640. + /// + /// Width/height are snapped UP to the nearest multiple of 32 + /// (with a 64-pixel floor). Ultralytics YOLO necks (v8/v11/v12) + /// concat upsampled stride-32 features with backbone stride-16 + /// features in /model.12/Concat — that op requires + /// 2*ceil(H/32) == ceil(H/16), which only holds when H is a + /// multiple of 32. Feeding e.g. H=80 fails at runtime with + /// "Axis 2 has mismatched dimensions of 5 and 6". The 64-pixel + /// floor avoids degenerate sub-stride-32 inputs that would + /// produce 1x1 P5 maps. void setInputShape(int width, int height) { - inputImageShape = cv::Size(width, height); + constexpr int kStride = 32; + constexpr int kMinDim = 64; + auto snap = [](int v) { + if (v < kMinDim) v = kMinDim; + return ((v + kStride - 1) / kStride) * kStride; + }; + inputImageShape = cv::Size(snap(width), snap(height)); } /// True if the ONNX model has dynamic spatial dimensions. diff --git a/tests/ANSODEngine-UnitTest/ANSODEngine-UnitTest.cpp b/tests/ANSODEngine-UnitTest/ANSODEngine-UnitTest.cpp index 26bb714..f6c2c21 100644 --- a/tests/ANSODEngine-UnitTest/ANSODEngine-UnitTest.cpp +++ b/tests/ANSODEngine-UnitTest/ANSODEngine-UnitTest.cpp @@ -1858,8 +1858,19 @@ int FireNSmokeTest() { return 0; } + + +int ALPROD_Test() { + int modelType = 30; // ONNX YOLO (30) RT YOLO (31) + std::string onnmodelFilePath = "E:\\Programs\\DemoAssets\\ALPR_Test\\ANS_ALPR_2204(GPU)_1.zip"; + std::string imageFile = "E:\\Programs\\DemoAssets\\ALPR_Test\\Data Test\\pl_ocr_3264.jpg"; + ImageDetectionEngine(onnmodelFilePath, imageFile, modelType);//yolov8 + return 0; +} int main() { + + ALPROD_Test(); //FireNSmokeTest(); //ElasticGPUTest(); @@ -1872,7 +1883,7 @@ int main() //YOLO26OBBYolo11Test(); //SAM3ONNX_ImageTest(); // ORT reference — runs first, prints decoder input stats //SAM3TRT_ImageTest(); // TRT under test — compare decoder input stats with above - CustomModel_StressTest_FilePlayer(); // Multi-task stress test (LabVIEW flow) + //CustomModel_StressTest_FilePlayer(); // Multi-task stress test (LabVIEW flow) // CustomModel_SingleStream_FilePlayer(); // 1 cam + 1 task — isolates concurrency from per-instance bugs //SAM3TRT_UnitTest(); // TensorRT SAM3 test (in ANSSAM3-UnitTest.cpp) //TensorRT10Test();