Fix AMD ALPR_OCR and custom model

This commit is contained in:
2026-05-01 07:53:18 +10:00
parent e1f37ec767
commit 91efbb9a8f
25 changed files with 2841 additions and 429 deletions
+31
View File
@@ -3,8 +3,26 @@
#pragma once
#include "ANSEngineCommon.h"
#include "engine.h"
#include <memory>
namespace ANSCENTER {
// Forward declaration: avoid pulling ANSONNXYOLO.h into every consumer of
// ANSONNXCL.h. Definition is included in ANSONNXCL.cpp.
class ANSONNXYOLO;
// ────────────────────────────────────────────────────────────────────────
// ANSONNXCL — verification facade over ANSONNXYOLO.
//
// ANSONNXYOLO already auto-detects classification models (single 2D
// output [B, nc]) and routes through its own classification postprocess.
// It also has the safe DML config (DisableMemPattern + ORT_SEQUENTIAL +
// EXTENDED) and the IsDmlFatalError catch-and-rebuild path.
//
// We delegate every public method here to an internal ANSONNXYOLO so we
// can A/B test whether ANSONNXCL's own session/postprocess code is the
// real cause of the AMD same-process DML races we saw with the custom
// helmet model. Public ABI is unchanged — external callers don't move.
// ────────────────────────────────────────────────────────────────────────
class ANSENGINE_API ANSONNXCL :public ANSODBase {
public:
virtual bool Initialize(std::string licenseKey, ModelConfig modelConfig, const std::string& modelZipFilePath, const std::string& modelZipPassword, std::string& labelMap) override;
@@ -15,10 +33,23 @@ namespace ANSCENTER {
std::vector<Object> RunInference(const cv::Mat& input, const std::string& camera_id);
bool Destroy();
~ANSONNXCL();
private:
// The wrapped engine. Lazy-initialised on first public call so we
// don't pay the cost (and pull in the dependency) for callers who
// never use this class.
std::unique_ptr<ANSONNXYOLO> _yoloDelegate;
private:
std::string _modelFilePath;
bool _modelLoadValid;
bool _fp16{ false };
// DML device-lost recovery: when DirectML fails fatally
// (HRESULT 887A0005 device-removed, 80004005 graph/command-recorder
// E_FAIL, etc. — see ANSCENTER::IsDmlFatalError) the Ort::Session
// is permanently broken. We detect once, recreate on CPU via
// Init(_modelFilePath, inputImageShape_, /*useGPU=*/false), and
// suppress further error-log flooding via this flag.
bool _dmlDeviceLost{ false };
size_t vectorProduct(const std::vector<int64_t>& vector);
bool preprocessImageToTensor(const cv::Mat& image, cv::Mat& outImage,
const cv::Size& targetShape,