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:
@@ -53,6 +53,12 @@ namespace ANSCENTER {
|
||||
int GetEmbeddingSize() const { return FACE_EMBEDDING_SIZE; }
|
||||
std::shared_ptr<faiss::gpu::StandardGpuResources> GetGpuResources() const { return m_gpuResources; }
|
||||
|
||||
// Which embedding model to load (call BEFORE Initialize). Default is
|
||||
// ADAFACE; Initialize falls back to ARCFACE when the model pack has
|
||||
// no adafacerecognizer.onnx (pre-v1.4 zips).
|
||||
void SetPreferredModel(FaceRecognizerModel m) { _preferredModel = m; }
|
||||
FaceRecognizerModel GetActiveModel() const { return _activeModel; }
|
||||
|
||||
bool UpdateParamater(double knownPersonThreshold) {
|
||||
_modelConfig.unknownPersonThreshold = knownPersonThreshold;
|
||||
m_knownPersonThresh = _modelConfig.unknownPersonThreshold;
|
||||
@@ -68,6 +74,11 @@ namespace ANSCENTER {
|
||||
private:
|
||||
bool LoadEngine(const std::string& xmlModelPath, bool engineOptimisation = true);
|
||||
|
||||
// Resolves the .onnx file for _preferredModel, falling back
|
||||
// ADAFACE -> ARCFACE when adafacerecognizer.onnx is absent. Sets
|
||||
// _activeModel and m_swapRB; returns "" when nothing usable exists.
|
||||
std::string ResolveRecognizerModelFile();
|
||||
|
||||
// Batched forward: one embedding per Object.mask (caller must hold _mutex)
|
||||
std::vector<std::vector<float>> ForwardUnlocked(const cv::Mat& input,const std::vector<ANSCENTER::Object>& outputBbox);
|
||||
|
||||
@@ -127,6 +138,13 @@ namespace ANSCENTER {
|
||||
float m_knownPersonThresh = 0.35f;
|
||||
EngineType engineType;
|
||||
|
||||
FaceRecognizerModel _preferredModel = FaceRecognizerModel::ADAFACE;
|
||||
FaceRecognizerModel _activeModel = FaceRecognizerModel::ADAFACE;
|
||||
// ArcFace was trained on RGB (needs the BGR->RGB swap); AdaFace on
|
||||
// BGR (OpenCV native order, no swap). Gates every cvtColor in the
|
||||
// TensorRT preprocessing paths.
|
||||
bool m_swapRB = true;
|
||||
|
||||
#ifdef USE_ONNX_ENGINE
|
||||
std::unique_ptr<GlintArcFace> faceRecognizer = nullptr;
|
||||
const int CPU_FACE_WIDTH = 112;
|
||||
|
||||
Reference in New Issue
Block a user