53 Commits
Author SHA1 Message Date
nghianguyenandClaude Opus 5 cd99fcf6d9 feat(ANSODEngine): run a sealed model on TensorRT without unsealing it
A .ansmodel reaching the GPU path went to ModelOptimizer, which knows one
way to open a model — unzip it — and failed on the first byte. Even past
that, the TensorRT engine only ever parsed an ONNX file, so the one thing
the format exists to prevent, a decrypted model on disk, was the only way
it could have run.

The builder now takes its bytes from memory when it has them. The path it
is given still names the plan that gets cached beside it, because a plan
is a built artefact and carries no model: the second run loads it and
never needs the ONNX at all. For a package the plan lands in the folder
the zip flow used, so a model converted from a zip reuses the plan that
zip already built.

OptimizeModelStr recognises a package and skips the unzip-and-optimise
leg entirely: the handle below it opens the package in memory and builds
the plan from the decrypted bytes, which is the same work by a shorter
road.

Still on the file path: the other TensorRT handlers (segmentation, pose,
classification). Only the YOLO detector reads a package today.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-13 09:38:45 +10:00
nghianguyenandClaude Opus 5 3798e3513b fix(YOLO12OD): decode an end-to-end head instead of reading it as a grid
This engine took the feature count from outputShape[1] unconditionally.
For a yolo26 export with end2end on — [1, 300, 6], rows of
(x1 y1 x2 y2 score class) with the suppression already inside the graph
— that means 296 classes, coordinates read as class scores, and boxes
covering the frame. No error, just nonsense, which is exactly what the
Labelling Tool produced from the same model before its decoder was
fixed.

Its sibling ANSONNXYOLO has recognised that head from the tensor shape
for a while; this one had not, and the backend marker cannot tell them
apart because it names the runtime rather than the head.

The branch fires only where the tensor cannot be a grid: the 6 must be
the last axis with a detection count before it, hundreds rather than the
thousands of anchors a two-class [1, 6, 8400] export carries.

The decoder reuses this engine's own scaleCoords rather than repeating
the letterbox arithmetic, so both heads undo the padding the same way
and agree about where a box is, and the rounding into the integral box
type is spelled out instead of left to a narrowing conversion.

NOT COMPILED. The engine layer needs CUDA and the ANSLibs tree, neither
of which exists on this machine, so this is verified by reading: the
shape rule matches the one the other three products now share, every
symbol it uses is declared in this translation unit, and the arithmetic
is delegated to the function the grid path already trusts.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-13 06:55:45 +10:00
nghianguyenandClaude Opus 5 080910c8ac feat(ODEngine): open a model package and run it without unpacking it
An engine's model has always been a path to a password-protected zip:
ANSODBase inflates it into a folder, and every engine then picks out
train_last.onnx, classes.names and model_config.json. A .ansmodel
package replaces all four with one sealed file, and this is the part
that turns it back into what the engines already understand.

ANSODBase::LoadModel and ::Initialize now recognise a .ansmodel path and
take a second route: the package is opened with the process keyring, the
model is decrypted into memory, and the classes, task and input geometry
come out of the manifest instead of loose files. Nothing is extracted,
so the unprotected model never touches the disk — which is the reason
the format exists, and it is one function's job to keep.

The engines follow it down. BasicOrtHandler gains a constructor that
takes the bytes rather than a path; it keeps a view of them, not a copy,
because the weights are in RAM either way once a session exists and a
copy would only double what every loaded model costs. The owner of the
plaintext is ANSODBase, which holds it for as long as the engine object
lives — that is what lets the DirectML recovery path rebuild a session
after a driver fault — and wipes it on teardown.

Wired through ANSONNXYOLO (and so the classification facade), ANSONNXOBB,
ANSONNXPOSE, ANSONNXSEG and YOLO12OD. YOLOOD is left alone: it loads
darknet weights and OpenCV DNN graphs, neither of which the writer
produces. A zip still loads exactly as before, on every engine.

Keys come from SetProcessModelKeys, as in ANSMINDCORE, with the same
development fallback from the environment. With none set, a package is
refused with a sentence saying so and every zip still works, so a build
made before the key ceremony runs everything except packages.

The engine layer needs CUDA to compile, so the contract it depends on is
checked where it can be: ANSModelPackage-UnitTest now opens the fixture
ANSMINDCORE wrote through the same glue ANSODBase uses, and covers the
refusal a keyless build gives. 32 checks, no failures.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-12 22:21:39 +10:00
nghianguyenandClaude Opus 5 5820a5e61b feat(ODEngine): load a model from memory, not only from a path
Every engine built its session from a file path, which is why opening an
encrypted model package means inflating it to a directory first: the
unprotected model lands on disk, is optimised, and is zipped back into a
cache. The new package format cannot avoid that from the outside — the
engines have to be able to take bytes.

ANSModelSource.h introduces a ModelSource (a path, or bytes with a name
for logs) and one MakeSession that builds from either. The six ONNX
engines — classification, OBB, pose, segmentation, YOLO12 and YOLO —
each gain a load overload taking it, with the existing string form
delegating so no caller changes. The Windows wide-path conversion and
the from-memory call now live in one place instead of the eleven copies
they were spread across; YOLOOD, which had only the Windows branch,
becomes portable as a side effect.

The factories are named rather than implicit, so a call with a plain
string literal still resolves to the path overload without ambiguity.

Not compiled here: this layer builds only where CUDA is present, so
verification on this machine was the new header compiled and run, plus a
structural check that every engine declares and defines both overloads,
calls MakeSession exactly once, and has no raw session construction
left. It needs a build on a CUDA box before it ships.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-12 20:29:59 +10:00
nghianguyenandClaude Opus 4.8 fda0f6f86f ANSFR: name the real cause when enrollment cannot compute embeddings
Enrolling a face while the recognizer engine is down used to store the
user row and silently drop the embedding: InsertUser is a pure DB write,
Feature() returns empty when uninitialized, and InsertFace's size check
misreported that as "Invalid embedding generated" — blaming the face.
The result surfaces hours later as every match returning Unknown/2.0
with nothing in the log saying why (seen on the A400: 45 users, zero
embeddings).

- ANSFRBase gains a public IsInitialized() accessor (flag existed but
  was protected).
- InsertFace / InsertMultipleFaces gate on it before computing the
  embedding and log the true cause: recognizer not initialized, face
  NOT enrolled, fix engine errors then re-enroll.
- The residual invalid-embedding message now reports actual vs expected
  size and the remaining causes (unusable crop / recognizer reloading).
- Reload() warns when the database has users but zero embeddings — the
  one line that identifies stale half-enrolled databases at startup.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-21 11:36:22 +10:00
nghianguyenandClaude Opus 4.8 799f755d5a ANSFR: purge stale ServerOptimised zip when engine rebuilds from ONNX
A ServerOptimised zip is a per-GPU cache of a previous engine build. When
the engine profile changes (batch gate, TRT/CUDA upgrade), the cached
engine inside it goes stale: every re-extract (e.g. after Temp cleanup)
restores the old engine and costs a full ONNX rebuild, forever, because
the server only regenerates the zip when the file is missing.

Engine now records rebuiltFromOnnx() + engineFilePath() in
buildLoadNetwork (set only on the generate-from-ONNX branch; cache hits
and alternative-precision loads don't raise it). After a rebuild,
ANSFaceRecognizer::Initialize deletes the stale same-GPU engine variants
from the model folder and the supplied optimised zip, so the server's
next optimize pass recreates it with the fresh engine.

Safety: only zips whose parent folder is ServerOptimised/-ized qualify —
base model zips can never match. Engine purge is scoped to the
"<model>.engine.<GPU>." prefix, leaving other GPUs' engines intact on
multi-GPU machines. All deletes are best-effort (error_code); multi-GPU
pool paths never set the flag, so the purge is a no-op there.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-21 11:21:48 +10:00
nghianguyenandClaude Fable 5 a4ea532f36 Fix multi-GPU inference on Blackwell (dual RTX 5080): four stacked fixes
Verified on dual RTX 5080: 355/355 detections, both GPUs in round-robin,
zero CUDA errors. Requires TensorRT >= 10.16.1 in SharedCore (10.15.1 has
a Myelin l2cm crash when creating a context on a second Blackwell device).

1. blobFromGpuMats: thread_local GpuMat caches (tl_blob/tl_floatImg) were
   device-blind — a pool thread warming GPU[1] then GPU[0] reused device-1
   memory with a device-0 stream, causing an async illegal memory access
   that poisoned every CUDA context (sticky 700). Track owning device and
   rebuild the cache on device switch.

2. runInference: pool round-robin can dispatch to a slot on a different
   GPU than the one the caller prepared inputs on. Detect foreign input
   GpuMats via cudaPointerGetAttributes and migrate them through a pinned
   host staging buffer (two-hop D2H+H2D; direct cross-device cudaMemcpy2D
   is unsupported and GeForce has no P2P).

3. warmUp: now pins its own CUDA device before uploading dummy inputs and
   returns success/failure; loadNetwork rejects engines whose warmup fails
   so broken slots can never join the pool silently.

4. Blackwell builder workaround: setMaxAuxStreams(0) on SM 12.x plus an
   .aux0 engine-cache suffix so pre-workaround caches rebuild.

Also: ANSFR-UnitTest gains --gpu N flag (sets CUDA_VISIBLE_DEVICES) for
single-GPU bisection, and rich diagnostics on input-copy failures.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-06 20:00:19 +10:00
nghianguyen b3436a61ee Prevent OOM 2026-06-18 05:55:31 +10:00
nghianguyen 26f9b07ac1 Add adaptive padding to improve tracking 2026-05-14 22:01:07 +10:00
nghianguyen a43a99834a Complete RTMPOSE 2026-05-14 21:16:35 +10:00
nghianguyen 71404affb7 Correct logic in RTMPOSE when using generic model to detect person 2026-05-14 19:33:31 +10:00
nghianguyen 52ec13a8e3 improve pose 2026-05-14 19:17:09 +10:00
nghianguyen 8e4d9a9e5d Add person model into RTMPOSE 2026-05-14 19:05:20 +10:00
nghianguyen ee8f0d1163 Suppot RTMPOSE classes 2026-05-14 17:48:09 +10:00
nghianguyen 66c67dff26 Fix onnx runtime loader for custom model 2026-05-05 16:23:01 +10:00
nghianguyen 91d81cbd88 fix onnx yolo race condition 2026-05-04 23:45:05 +10:00
nghianguyen 03a63142ec Disable stabilized feature by default. Need ,more time to test 2026-05-04 09:39:07 +10:00
nghianguyen fc9cf9671b 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.
2026-05-01 20:24:08 +10:00
nghianguyen 91efbb9a8f Fix AMD ALPR_OCR and custom model 2026-05-01 07:53:18 +10:00
nghianguyen dcf974c35c Fix AMD by changing from GetTensorData<T>() to GetTensorMutableData<T>() 2026-04-28 13:25:02 +10:00
nghianguyen bab94bf9bc Add log and change logger policy 2026-04-25 20:29:58 +10:00
nghianguyen ef2a122fec Add logs to custom models and model optimisation 2026-04-25 13:17:36 +10:00
nghianguyen 3a527d2dad Remove locks 2026-04-24 17:10:29 +10:00
nghianguyen e2bf17289d Fix model extract race issue to all classes 2026-04-24 12:19:54 +10:00
nghianguyen baa88bcc48 Fix Concurrent extract + open race on train_last.onnx 2026-04-24 11:29:28 +10:00
nghianguyen 57cc8e0a56 Fix double stop in ANSVideoPlayer 2026-04-22 10:10:16 +10:00
nghianguyen 97d814936d Enable log information. Disable NPU in U9 2026-04-21 15:48:27 +10:00
nghianguyen 7e772f76bc Improve ANSCV 2026-04-21 09:26:02 +10:00
nghianguyen 3418090042 - Remove ALPR_OD Tracker and voting system.
- Disable debugview
2026-04-19 23:15:50 +10:00
nghianguyen 51fe507dfd Fix unregister issue 2026-04-19 14:47:29 +10:00
nghianguyen 8e60126c4c Fix mutex lock issues (OCR and FR) 2026-04-13 20:38:40 +10:00
nghianguyen 844d7396b2 Fix mutex lock issues 2026-04-13 19:48:32 +10:00
nghianguyen 0a8aaed215 Add CPU/GPU gate and support new ANSALPR using OCR 2026-04-12 17:16:16 +10:00
nghianguyen 27083a6530 Remove unused files 2026-04-12 05:39:36 +10:00
nghianguyen 257145c429 Fix Intel ONNX runtime 2026-04-10 17:13:47 +10:00
nghianguyen eb863bf510 Support getEngine 2026-04-09 11:00:34 +10:00
nghianguyen eeb205779a Fix model optimisation 2026-04-09 08:09:02 +10:00
nghianguyen 69787b0ff0 Fix AMD and OpenVINO 2026-04-08 13:45:52 +10:00
nghianguyen a4a8caaa86 Fix mixed UTF16 issue (LabVIEW) and fix ANSFR for Intel 2026-04-08 08:47:10 +10:00
nghianguyen 091a61d2be Fix Window search path for ANSLIB 2026-04-06 08:31:26 +10:00
nghianguyen f7cef5015a Fix ALPR pipeline. Ready for production 2026-04-05 11:55:37 +10:00
nghianguyen 98681f4da6 Use CPU resize before upload to GPU to remove PCIe bottleneck 2026-04-04 22:29:08 +11:00
nghianguyen e134ebdf15 Use software decoder by default 2026-04-04 20:19:54 +11:00
nghianguyen 3a21026790 Disable NV12 path for ANSCV by default. Currenly use cv::Mat** directly 2026-04-04 10:09:47 +11:00
nghianguyen bd2d3292ca Add log info to see if NV12 fast path is active 2026-04-03 15:23:20 +11:00
nghianguyen 6fb09830c5 Fix NV12 crash issue when recreate camera object
(new structure) does not work
2026-04-03 14:51:52 +11:00
nghianguyen 958cab6ae3 Fix NV12 crash issue when recreate camera object 2026-04-02 22:07:27 +11:00
nghianguyen ccfc5964d4 Support UTF8 to UTF16 LE.
Support Unicode helper
Fix ANSFR to show 2 same faces in 1 image
2026-03-31 21:52:47 +11:00
nghianguyen 70be68d0fc Support UTF8 to UTF16 LE 2026-03-31 14:10:21 +11:00
nghianguyen 0c24096c80 Support return Unicode escapes 2026-03-30 22:50:07 +11:00