From 430c8057b8a2d7d3a7a9230f3a0ee3824e2ed62d Mon Sep 17 00:00:00 2001 From: Tuan Nghia Nguyen Date: Fri, 28 Aug 2026 16:50:47 +1000 Subject: [PATCH] ANSFR: report v1.4 emotion class names verbatim in the attribute JSON The legacy display remap in FaceAttributeToJsonString rewrote most emotions to "Attentive", which hid the v1.4 classifier's real classes. The remap now applies ONLY to the legacy OpenVINO model's lowercase classes (sad/happy/neutral/anger/surprise - v1.1 output unchanged); every other name, i.e. the classes read from emotionsrecognition.names (Angry, Fear, Happy, Neutral, Sad), passes through verbatim. A retrained classifier with a different .names list needs no code change. Verified on the classroom video: faces previously labelled "Attentive" now read "Angry (100%)"; smiling faces read "Happy (100%)". Parity test updated to check each pack against its own emotion vocabulary. Note for client code: v1.4 deployments no longer emit "Attentive" - anything matching that string must handle Angry/Fear/Sad instead. Co-Authored-By: Claude Fable 5 --- modules/ANSFR/ANSFRCommon.cpp | 26 +++++++++---------------- tests/ANSFR-UnitTest/ANSFR-UnitTest.cpp | 21 +++++++++++++------- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/modules/ANSFR/ANSFRCommon.cpp b/modules/ANSFR/ANSFRCommon.cpp index fc95b49..99739a8 100644 --- a/modules/ANSFR/ANSFRCommon.cpp +++ b/modules/ANSFR/ANSFRCommon.cpp @@ -646,29 +646,21 @@ namespace ANSCENTER { if (face.isEmotionsEnabled()) { const auto& [emotionName, emotionConfidence] = face.getMainEmotion(); std::ostringstream emotionStr; + // The v1.4 ONNX classifier's classes (emotionsrecognition.names: + // Angry, Fear, Happy, Neutral, Sad) are reported VERBATIM. Only + // the legacy OpenVINO model's lowercase classes keep the + // historical display remap so v1.1 output is unchanged. std::string adjustedEmotionName = emotionName; - if (emotionName == "Sad" || emotionName == "sad") + if (emotionName == "sad") adjustedEmotionName = "Attentive"; - else if (emotionName == "Happy" || emotionName == "happy") + else if (emotionName == "happy") adjustedEmotionName = "Happy"; - else if (emotionName == "Neutral" || emotionName == "neutral") + else if (emotionName == "neutral") adjustedEmotionName = "Neutral"; - else if (emotionName == "Angry" || emotionName == "angry") + else if (emotionName == "anger") adjustedEmotionName = "Attentive"; - else if (emotionName == "Surprised" || emotionName == "surprised") + else if (emotionName == "surprise") adjustedEmotionName = "Attentive"; - else if (emotionName == "Surprise" || emotionName == "surprise") - adjustedEmotionName = "Attentive"; - else if (emotionName == "Disgusted" || emotionName == "disgusted") - adjustedEmotionName = "Attentive"; - else if (emotionName == "Fearful" || emotionName == "fearful") - adjustedEmotionName = "Attentive"; - else if (emotionName == "Fear" || emotionName == "fear") - adjustedEmotionName = "Attentive"; - else if (emotionName == "Anger" || emotionName == "anger") - adjustedEmotionName = "Attentive"; - else - adjustedEmotionName = "Neutral"; emotionStr << adjustedEmotionName << " (" << static_cast(emotionConfidence * 100) << "%)"; detectedNode.put("Emotion", emotionStr.str()); diff --git a/tests/ANSFR-UnitTest/ANSFR-UnitTest.cpp b/tests/ANSFR-UnitTest/ANSFR-UnitTest.cpp index d95e72c..bda8e9c 100644 --- a/tests/ANSFR-UnitTest/ANSFR-UnitTest.cpp +++ b/tests/ANSFR-UnitTest/ANSFR-UnitTest.cpp @@ -2184,8 +2184,12 @@ int TestOutputFormatParity() V14Check(attrKeys(oldFirst) == attrKeys(newFirst), "attribute keys identical", failures); - // 3. Value vocabularies must match on every face of both packs - auto checkVocab = [&](const boost::property_tree::ptree& pt, const char* label) { + // 3. Value vocabularies must match on every face of both packs. + // Gender/Age vocabularies are shared; the Emotion vocabulary is + // per-pack: v1.1's legacy display names vs v1.4's verbatim class + // names from emotionsrecognition.names. + auto checkVocab = [&](const boost::property_tree::ptree& pt, const char* label, + const std::vector& emotionVocab) { for (const auto& child : pt.get_child("results")) { auto ept = parse(child.second.get("extra_info")); for (const auto& attr : ept.get_child("attributes")) { @@ -2196,16 +2200,19 @@ int TestOutputFormatParity() std::string(label) + " Gender in {Male, Female}: " + gender, failures); V14Check(age == "Kids" || age == "Young Adults" || age == "Adults" || age == "Elders", std::string(label) + " Age in bucket set: " + age, failures); - const bool emotionOk = - (emotion.rfind("Happy", 0) == 0 || emotion.rfind("Neutral", 0) == 0 || - emotion.rfind("Attentive", 0) == 0) && emotion.find("%)") != std::string::npos; + bool emotionOk = emotion.find("%)") != std::string::npos; + if (emotionOk) { + emotionOk = false; + for (const auto& name : emotionVocab) + if (emotion.rfind(name, 0) == 0) { emotionOk = true; break; } + } V14Check(emotionOk, std::string(label) + " Emotion label/format: " + emotion, failures); } } }; - checkVocab(oldPt, "v1.1"); - checkVocab(newPt, "v1.4"); + checkVocab(oldPt, "v1.1", { "Happy", "Neutral", "Attentive" }); + checkVocab(newPt, "v1.4", { "Angry", "Fear", "Happy", "Neutral", "Sad" }); // 4. Both packs must recognize the enrolled user (same matching semantics) V14Check(oldJson.find("ParityUser") != std::string::npos, "v1.1 recognizes enrolled user", failures);