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 <noreply@anthropic.com>
This commit is contained in:
2026-08-28 16:50:47 +10:00
co-authored by Claude Fable 5
parent 024d55197b
commit 430c8057b8
2 changed files with 23 additions and 24 deletions
+9 -17
View File
@@ -646,29 +646,21 @@ namespace ANSCENTER {
if (face.isEmotionsEnabled()) { if (face.isEmotionsEnabled()) {
const auto& [emotionName, emotionConfidence] = face.getMainEmotion(); const auto& [emotionName, emotionConfidence] = face.getMainEmotion();
std::ostringstream emotionStr; 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; std::string adjustedEmotionName = emotionName;
if (emotionName == "Sad" || emotionName == "sad") if (emotionName == "sad")
adjustedEmotionName = "Attentive"; adjustedEmotionName = "Attentive";
else if (emotionName == "Happy" || emotionName == "happy") else if (emotionName == "happy")
adjustedEmotionName = "Happy"; adjustedEmotionName = "Happy";
else if (emotionName == "Neutral" || emotionName == "neutral") else if (emotionName == "neutral")
adjustedEmotionName = "Neutral"; adjustedEmotionName = "Neutral";
else if (emotionName == "Angry" || emotionName == "angry") else if (emotionName == "anger")
adjustedEmotionName = "Attentive"; adjustedEmotionName = "Attentive";
else if (emotionName == "Surprised" || emotionName == "surprised") else if (emotionName == "surprise")
adjustedEmotionName = "Attentive"; 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<int>(emotionConfidence * 100) << "%)"; emotionStr << adjustedEmotionName << " (" << static_cast<int>(emotionConfidence * 100) << "%)";
detectedNode.put("Emotion", emotionStr.str()); detectedNode.put("Emotion", emotionStr.str());
+14 -7
View File
@@ -2184,8 +2184,12 @@ int TestOutputFormatParity()
V14Check(attrKeys(oldFirst) == attrKeys(newFirst), V14Check(attrKeys(oldFirst) == attrKeys(newFirst),
"attribute keys identical", failures); "attribute keys identical", failures);
// 3. Value vocabularies must match on every face of both packs // 3. Value vocabularies must match on every face of both packs.
auto checkVocab = [&](const boost::property_tree::ptree& pt, const char* label) { // 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<std::string>& emotionVocab) {
for (const auto& child : pt.get_child("results")) { for (const auto& child : pt.get_child("results")) {
auto ept = parse(child.second.get<std::string>("extra_info")); auto ept = parse(child.second.get<std::string>("extra_info"));
for (const auto& attr : ept.get_child("attributes")) { for (const auto& attr : ept.get_child("attributes")) {
@@ -2196,16 +2200,19 @@ int TestOutputFormatParity()
std::string(label) + " Gender in {Male, Female}: " + gender, failures); std::string(label) + " Gender in {Male, Female}: " + gender, failures);
V14Check(age == "Kids" || age == "Young Adults" || age == "Adults" || age == "Elders", V14Check(age == "Kids" || age == "Young Adults" || age == "Adults" || age == "Elders",
std::string(label) + " Age in bucket set: " + age, failures); std::string(label) + " Age in bucket set: " + age, failures);
const bool emotionOk = bool emotionOk = emotion.find("%)") != std::string::npos;
(emotion.rfind("Happy", 0) == 0 || emotion.rfind("Neutral", 0) == 0 || if (emotionOk) {
emotion.rfind("Attentive", 0) == 0) && emotion.find("%)") != std::string::npos; emotionOk = false;
for (const auto& name : emotionVocab)
if (emotion.rfind(name, 0) == 0) { emotionOk = true; break; }
}
V14Check(emotionOk, V14Check(emotionOk,
std::string(label) + " Emotion label/format: " + emotion, failures); std::string(label) + " Emotion label/format: " + emotion, failures);
} }
} }
}; };
checkVocab(oldPt, "v1.1"); checkVocab(oldPt, "v1.1", { "Happy", "Neutral", "Attentive" });
checkVocab(newPt, "v1.4"); checkVocab(newPt, "v1.4", { "Angry", "Fear", "Happy", "Neutral", "Sad" });
// 4. Both packs must recognize the enrolled user (same matching semantics) // 4. Both packs must recognize the enrolled user (same matching semantics)
V14Check(oldJson.find("ParityUser") != std::string::npos, "v1.1 recognizes enrolled user", failures); V14Check(oldJson.find("ParityUser") != std::string::npos, "v1.1 recognizes enrolled user", failures);