ANSFR: support ANS_FaceRecognizer v1.4 models (AdaFace + ONNX attributes)

- 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>
This commit is contained in:
2026-08-26 11:06:10 +10:00
co-authored by Claude Fable 5
parent 881d783fa3
commit ac4369302a
15 changed files with 1111 additions and 51 deletions
+36
View File
@@ -1294,6 +1294,42 @@ extern "C" ANSFR_API int GetFaceQueue(ANSCENTER::ANSFacialRecognition** Handl
}
}
extern "C" ANSFR_API int SetANSRFRecognizerModel(ANSCENTER::ANSFacialRecognition** Handle, int modelType) {
ANS_DBG("ANSFR","SetANSRFRecognizerModel: HandlePtr=%p, *Handle=%p, modelType=%d (0=AdaFace,1=ArcFace)",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), modelType);
try {
if (!Handle || !*Handle) return -1;
if (modelType < 0 || modelType > 1) return -1;
FRHandleGuard guard(AcquireFRHandle(*Handle));
if (!guard) return -1;
return (*Handle)->SetRecognizerModelType(modelType) ? 1 : 0;
}
catch (const std::exception& e) {
ANS_DBG("ANSFR","SetANSRFRecognizerModel EXCEPTION: %s", e.what());
return -1;
}
}
extern "C" ANSFR_API int GetANSRFRecognizerModel(ANSCENTER::ANSFacialRecognition** Handle) {
try {
if (!Handle || !*Handle) return -1;
return (*Handle)->GetRecognizerModelType();
}
catch (const std::exception&) {
return -1;
}
}
extern "C" ANSFR_API int GetANSRFModelInfo(ANSCENTER::ANSFacialRecognition** Handle, LStrHandle modelInfo) {
try {
if (!Handle || !*Handle || !modelInfo) return -1;
return CopyToLStrHandle(modelInfo, (*Handle)->GetActiveModelInfo());
}
catch (const std::exception&) {
return -1;
}
}
extern "C" ANSFR_API int RunInferenceComplete_LV(
ANSCENTER::ANSFacialRecognition** Handle,
cv::Mat** cvImage,