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>
- Recognizer: adafacerecognizer.onnx (AdaFace, new default) with automatic
fallback to ansfacerecognizer.onnx (ArcFace) for pre-v1.4 zips. AdaFace
consumes BGR: new AdaFace handler in ONNXEngine skips the BGR2RGB swap,
and the TensorRT paths gate their cvtColor on m_swapRB.
- New C API: SetANSRFRecognizerModel (0=AdaFace, 1=ArcFace),
GetANSRFRecognizerModel, GetANSRFModelInfo. A live switch reloads the
recognizer and regenerates all stored embeddings from the enrolled face
crops; the generating model is persisted in a new SETTINGS table
(EMBEDDING_MODEL) so upgrading an ArcFace database to the AdaFace
default migrates automatically on LoadEngine.
- Attributes: prefer agegender.onnx (ViT: gender_logits [male,female] +
age_pred in years; also handles the single-tensor research export) and
emotionsrecognition.onnx (YOLOv11-cls, classes from .names) behind new
IAgeGenderEstimator/IEmotionsClassifier interfaces, falling back to the
legacy OpenVINO IRs. EP follows hardware: NVIDIA uses TensorRT EP with
disk-cached engines, AMD DirectML, Intel OpenVINO.
- Emotion JSON mapping: handle the new Fear class and the never-matched
surprise label (both map to Attentive).
- ANSFR-UnitTest: TestModelSwitchV14 covers default model selection, ONNX
attribute backends, enrollment, and adaface<->arcface switching.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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>
The margin was a fixed 768 MiB — 3% of a 24 GiB compute card but 19% of
a 4 GiB card (RTX A400), where free VRAM never clears it, so CanLoad()
refused every engine and UnderPressure() skipped every frame. Now
total/8 clamped to [192, 768] MiB: cards >= 6 GiB keep exactly the old
margin, only small cards change. ANSCENTER_GPU_MARGIN_MB / SetMargin()
still override (0 = auto). Refusal log now reports total VRAM alongside
free, which is what made this diagnosable.
Verified on the A400 test PC: detector + recognizer load and match.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Two-pass slot acquisition in runInferenceFromPool: Pass A picks an idle
slot whose deviceIndex matches the input GpuMats' resident device
(zero-copy dispatch); Pass B falls back to plain round-robin, where
runInference migrates the inputs via the pinned-host two-hop copy.
Callers that prepare frames on GPU A no longer pay the ~1 ms/frame PCIe
migration when a same-GPU slot is idle, while spillover to the other GPU
under load still works. Input residency is queried outside the slot
mutex via cudaPointerGetAttributes (cheap driver lookup).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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>
Cleaned up verbose engine telemetry emitted to stdout/stderr and the
Windows Event Viewer. Removes logEngineEvent/logEvent calls (and their
diagnostic-only locals) across the TensorRT engine load, build, run,
multi-GPU, and pool-manager paths, plus the now-unused logEvent helper
in EnginePoolManager.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>