Fix ANSONNXYOLO:
1. core/ANSLicensingSystem/ANSLicense.h:268 — added default initializers to ModelConfig POD members (inpWidth = 0, inpHeight = 0, etc.). This was the actual bug: CreateANSODHandle declares a local ModelConfig and only sets a few fields, leaving inpWidth/inpHeight as indeterminate stack memory. On your machine that memory consistently held ~80, slipping past the <=0 → 640 guard and driving the ORT session at 80×80 — which crashes YOLOv11's /model.12/Concat because 2·ceil(80/32)=6 ≠ ceil(80/16)=5. 2. modules/ANSODEngine/ANSONNXYOLO.h:75 — ONNXYOLO::setInputShape() now snaps width/height up to the next multiple of 32 (with a 64-pixel floor). Defense in depth: even if a future caller hands in a non-stride-32 size, the FPN concat alignment is preserved. 3. modules/ANSODEngine/ANSONNXYOLO.cpp — two diagnostic additions: WarmUpEngine bails with a clear log line if the warm-up dims aren't a multiple of 32, instead of letting the model.12 error fire and mask the real cause. transform() logs the input shape, canvas shape, source size, and dynamic flag once per session in DebugView — so any future shape-mismatch crash points at the offending HxW directly.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -116,6 +116,20 @@ namespace ANSCENTER {
|
||||
const int width = canvas.cols;
|
||||
const size_t imageSize = static_cast<size_t>(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,
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user