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:
@@ -107,6 +107,42 @@ namespace ANSCENTER {
|
||||
float age;
|
||||
float maleProb;
|
||||
};
|
||||
|
||||
// Which face-embedding model the recognizer runs. ADAFACE is the default
|
||||
// since ANS_FaceRecognizer v1.4 (adafacerecognizer.onnx); when that file
|
||||
// is missing from the model zip the recognizer silently falls back to
|
||||
// ARCFACE (ansfacerecognizer.onnx) so v1.3-and-older zips keep working.
|
||||
enum class FaceRecognizerModel : int {
|
||||
ADAFACE = 0,
|
||||
ARCFACE = 1,
|
||||
};
|
||||
|
||||
inline const char* FaceRecognizerModelName(FaceRecognizerModel m) {
|
||||
return (m == FaceRecognizerModel::ARCFACE) ? "arcface" : "adaface";
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// Attribute-model backends. The v1.4 model pack ships ONNX attribute
|
||||
// models (agegender.onnx / emotionsrecognition.onnx) next to the
|
||||
// legacy OpenVINO IR pairs (.xml/.bin). These interfaces let the
|
||||
// pipeline hold either backend behind the same two calls it already
|
||||
// makes: runInfer() and enabled().
|
||||
// ----------------------------------------------------------------
|
||||
class ANSF_API IAgeGenderEstimator {
|
||||
public:
|
||||
virtual ~IAgeGenderEstimator() = default;
|
||||
virtual AgeGenderResults runInfer(const cv::Mat& frame) = 0;
|
||||
virtual bool enabled() const = 0;
|
||||
virtual const char* backendName() const = 0; // "openvino" | "onnx"
|
||||
};
|
||||
|
||||
class ANSF_API IEmotionsClassifier {
|
||||
public:
|
||||
virtual ~IEmotionsClassifier() = default;
|
||||
virtual std::map<std::string, float> runInfer(const cv::Mat& frame) = 0;
|
||||
virtual bool enabled() const = 0;
|
||||
virtual const char* backendName() const = 0; // "openvino" | "onnx"
|
||||
};
|
||||
//// Class for face attribute
|
||||
class ANSF_API Face {
|
||||
public:
|
||||
@@ -200,7 +236,7 @@ namespace ANSCENTER {
|
||||
//std::vector<HeadPoseResults> getAllResults();
|
||||
};
|
||||
|
||||
class ANSF_API AgeGenderDetection :public BaseDetection {
|
||||
class ANSF_API AgeGenderDetection : public BaseDetection, public IAgeGenderEstimator {
|
||||
public:
|
||||
std::recursive_mutex _mutex;
|
||||
std::string outputAge;
|
||||
@@ -211,7 +247,9 @@ namespace ANSCENTER {
|
||||
bool doRawOutputMessages);
|
||||
|
||||
virtual std::shared_ptr<ov::Model> read(const ov::Core& core) override;
|
||||
AgeGenderResults runInfer(const cv::Mat& frame);
|
||||
AgeGenderResults runInfer(const cv::Mat& frame) override;
|
||||
bool enabled() const override { return BaseDetection::enabled(); }
|
||||
const char* backendName() const override { return "openvino"; }
|
||||
//void submitRequest();
|
||||
//void enqueue(const cv::Mat& face);
|
||||
//AgeGenderResults getResult(int idx);
|
||||
@@ -219,7 +257,7 @@ namespace ANSCENTER {
|
||||
|
||||
};
|
||||
|
||||
class ANSF_API EmotionsDetection : public BaseDetection {
|
||||
class ANSF_API EmotionsDetection : public BaseDetection, public IEmotionsClassifier {
|
||||
public:
|
||||
std::recursive_mutex _mutex;
|
||||
//size_t enquedFaces;
|
||||
@@ -230,7 +268,9 @@ namespace ANSCENTER {
|
||||
bool doRawOutputMessages);
|
||||
|
||||
virtual std::shared_ptr<ov::Model> read(const ov::Core& core) override;
|
||||
std::map<std::string, float> runInfer(const cv::Mat& frame);
|
||||
std::map<std::string, float> runInfer(const cv::Mat& frame) override;
|
||||
bool enabled() const override { return BaseDetection::enabled(); }
|
||||
const char* backendName() const override { return "openvino"; }
|
||||
//void submitRequest();
|
||||
//void enqueue(const cv::Mat& face);
|
||||
//std::map<std::string, float> getResult(int idx);
|
||||
|
||||
Reference in New Issue
Block a user