Facial Emotion Analysis Benchmark
💡 Testing Environment:
- 1 RTX 4090
- Python 3.12.0
- 2 drama VOD episodes (1 episode of Manager Kim, 1 episode of My Perfect Secretary), 1 frame per second
1. Overview
1.1 Background
- The goal is to tag characters’ emotions (joy, anger, sadness, etc.) in drama scenes for use in search and clip extraction
- To analyze the facial expressions of characters on screen and to test the performance of OpenCV FER in real-world conditions
- The key is to identify emotions only in critical situations, rather than detecting them on every face
- Conditions: Open source, no fine-tuning, basic emotion classification using a single model
1.2 Purpose of the PoC
- Although OpenCV_FER is used due to licensing issues, it is employed to conduct practical testing of the model
- To determine the ground truth classification scheme and probability thresholds for use in the service
- Finalize a library structure that can be directly integrated into future internal processes
1.3 Decisions
| Item | Decision |
|---|---|
| Target Classes | Joy / Anger / Sadness / Surprise / Normal 5 classes (grouping model classes) |
| Cluster Score | The sum of the softmax probabilities of the clustered classes |
| Threshold | 0.8 recommended (If the emotion cluster score is below 0.8, classify as “Normal”) |
| Model | Preliminary OpenCV FER — Fast, and visually correct in most cases where results differ. Final determination will be made after evaluating the ground truth labels |
| Structure | lib/model_emotion/ Separated so that only one needs to be moved to a worker (independent of the detector) |
1.4 Processing Flow
Frame (jpg, 1 fps)
→ insightface buffalo_l: Face box + 5 landmarks + embedding
→ Face filter (detection score ≥ 0.6, side length ≥ 60px) ← Same as the worker
→ Two emotion models (both on the same face)
OpenCV FER: 5-point alignment, 112×112
hsemotion : Box crop 224×224
→ Softmax probabilities → Group into 5 correct answers → Apply threshold
→ Group of Characters (Same as Walker)
2. Comparison of Designs
2.1 Models
| OpenCV FER (Progressive Teacher) | hsemotion (EmotiEffLib) | |
|---|---|---|
| File | facial_expression_recognition_mobilefacenet_2022july.onnx (4.6MB) | enet_b0_8_best_vgaf.onnx (16MB) |
| Backbone | MobileFaceNet | EfficientNet-B0 |
| Classes | 7 | 8 (including Contempt) |
| Input | 112×112 aligned with 5 landmarks, (x/255−0.5)/0.5 | 224×224 box-cropped, ImageNet mean and standard deviation |
| Public Accuracy | RAF-DB 88.27% | AffectNet 8-class 61.32% |
| Execution | onnxruntime-gpu (fixed at 1 batch) | onnxruntime-gpu |
Both models run directly via onnxruntime without any official packages. Since we are already using onnxruntime-gpu internally, there are no new dependencies. The emotiefflib package is fixed to CPU, so it is not used.
Excluded Candidates
- LibreFace: Good performance, but requires a USC research license (commercial use prohibited)
- POSTER / POSTER++: Code is MIT-licensed; publicly available weights have no license notation
2.2 Answer Mapping
| Answer | OpenCV | hsemotion | Reason for grouping |
|---|---|---|---|
| Joy | happy | happy | |
| Anger | angry, disgust | angry, disgust, contempt | Frowning and contorted expressions. Often mixed up between models |
| Sadness | sad | sad | |
| Surprise | surprise, fear | surprise, fear | Both involve wide-open eyes and an open mouth. |
| Neutral | neutral | neutral | All emotions other than the four listed above |
- The cluster score is the sum of the probabilities of the emotions in the cluster, and the sum of the five clusters is 1.
- Select the answer with the highest cluster score; if that emotion is below the threshold, classify it as neutral.
- For example, if the emotion is “joy” at a threshold of 0.9, the sum of the other four clusters must be 0.1 or less.
2.3 Variables
- Threshold: 0.5 / 0.6 / 0.7 / 0.8 / 0.9
- Instead of running the model again, we simply recalculate using the saved probabilities while changing only the threshold.
2.4 Metrics
Since there are no ground-truth labels, we use the agreement rate between the two models instead of accuracy.
| Metric | Calculation | Meaning |
|---|---|---|
| Overall Agreement | Same answer / All faces | Since most faces are those of ordinary people, this metric naturally increases as the threshold is raised |
| Emotion-Based Agreement | Same answer / Faces with emotions assigned to at least one of them | Agreement on whether a face “exhibits an emotion” |
| Emotion Match | Same emotion / Both faces have an emotion assigned | Agreement on “What emotion is it?” |
In the distribution table, “General” is divided into two categories.
- General (Neutral is 1st): Fixed regardless of the threshold
- Pending (Emotion is 1st but below the threshold): Increases as the threshold is raised
2.5 Dataset
| Video | Frames | Detected Faces | People (Clusters) |
|---|---|---|---|
| Manager Kim Part 1 | 4,015 frames | 3,530 faces | 22 people |
| My Perfect Secretary Episode 1 | 4,752 images | 4,360 faces | 34 people |
| Total | 8,767 images | 7,890 faces |
3. Implementation
3.1 Directory Structure
poc-face-emotion/
├── Path to config.py / Device / Model location (same format as the worker's config.py)
├── main.py Video 1: Detection + 2 Types of Sentiment Analysis → output/{v_id}_{stream_id}/
├── script/
│ ├── download_models.sh Download two ONNX emotion models
│ └── sweep.py: Comparison of default values 0.5–0.9 → output/sweep/
└── lib/
├── model_emotion/ ← Library to be moved to the worker
│ ├── frame.py Emotion data / labels / ground truth mapping / reference values
│ ├── onnx_util.py: Session (GPU check) / Inference / 5-point sorting / Cropping
│ ├── opencv_fer.py OpenCV FER backend
│ ├── hsemotion.py hsemotion backend
│ └── pipe_model.py Models.load() + run() + to_group()
├── model_face/ ← Copy the worker code; add # [emotion] to the modified line
└── report/ ← Reports and spreadsheets for PoC only
3.2 Design for Internal Module Integration
-
The emotion analysis code is separated from the face detection code
-
Emotion analysis operates using only "frame image + face position (bounding box) + eye, nose, and mouth positions (5 points)"
-
Currently, insightface is used for face detection, but even if we switch to a different face detection model later, the emotion analysis code will remain unchanged
-
-
Emotion analysis runs concurrently with the face detection step
- Immediately after a face is detected, the original frame and face position are available, so emotion analysis is performed on the spot
-
Integrating it into the internal module is simple
-
Simply copy the
lib/model_emotion/folder as-is -
Move only the few lines marked with
# [emotion]from the existing face detection code
-
-
The execution environment is configured to match that of the internal module
- Python 3.12.0 and package versions are fixed to match those of the internal module, ensuring that the PoC results are identical to those of the internal module
3.3 Implementation Verification
✅ Both models achieved 87/87 label agreement with the official implementation on 87 faces (probability difference ≤ 0.002)
Two issues were discovered during validation
| Issue | Symptom | Action |
|---|---|---|
| Face Alignment Method | Aligning using cv2.estimateAffinePartial2D (outlier removal method) results in 7 label discrepancies compared to the original | Replaced with 5-point least-squares alignment, identical to the OpenCV Zoo original → 87/87 |
| Batch Inference Latency | Since the number of faces varies per frame, batch size changes result in 60 ms per call (1.2 ms if the faces are identical) | Infer faces one at a time |
3.4 Environment / Dependencies
requires-python = "==3.12.0"
dependencies = [
"insightface==2.0",
"onnxruntime-gpu[cuda,cudnn]==1.30.0",
"opencv-python-headless==5.0.0.93",
"numpy==2.5.1",
"scikit-learn==1.9.0",
"pillow==12.3.0",
"python-dotenv==1.2.2",
]
[tool.uv]
# insightface prevents the CPU version of onnxruntime from overwriting the GPU version (same as for workers)
override-dependencies = ["onnxruntime ; sys_platform == 'never'"]
3.5 How to Run
uv sync
bash script/download_models.sh # Run once
uv run main.py 1027 VOD # Video 1 (Detection + 2 types of sentiment analysis)
uv run main.py 1055 VOD
uv run script/sweep.py 1027_VOD 1055_VOD # Compare reference values 0.5–0.9
4. Results
4.1 Speed
| Per Face | 1,027 (3,530 faces) | 1,055 (4,360 faces) | |
|---|---|---|---|
| OpenCV FER | Approx. 1.1 ms | 4.0 seconds | 4.8 seconds |
| hsemotion | Approx. 2.4 ms | 8.6 seconds | 10.4 seconds |
| Total (Detection + 2 Emotions) | 54.8 seconds | 64.8 seconds |
- When converted to a 1-hour video (3,600 frames), the additional time required for the emotion model is approximately 4 seconds for OpenCV and approximately 9 seconds for hsemotion. Most of the time is spent on face detection
- The time is proportional to the number of faces, not the number of frames (excluding InsightFace)
4.2 Distribution by Threshold (Total for both videos, 7,890 faces)
OpenCV FER
| Threshold | Joy | Anger | Sadness | Surprise | Normal (Neutral 1st) | Pending (Below Threshold) |
|---|---|---|---|---|---|---|
| 0.5 | 807 (10.2%) | 140 (1.8%) | 536 (6.8%) | 395 (5.0%) | 5,855 (74.2%) | 157 (2.0%) |
| 0.6 | 747 (9.5%) | 108 (1.4%) | 422 (5.3%) | 351 (4.4%) | 5,855 (74.2%) | 407 (5.2%) |
| 0.7 | 698 (8.8%) | 82 (1.0%) | 320 (4.1%) | 295 (3.7%) | 5,855 (74.2%) | 640 (8.1%) |
| 0.8 | 642 (8.1%) | 55 (0.7%) | 236 (3.0%) | 235 (3.0%) | 5,855 (74.2%) | 867 (11.0%) |
| 0.9 | 552 (7.0%) | 35 (0.4%) | 152 (1.9%) | 176 (2.2%) | 5,855 (74.2%) | 1,120 (14.2%) |
hsemotion
| Baseline | Joy | Anger | Sadness | Surprise | Normal (Neutral 1st) | Pending (Below Threshold) |
|---|---|---|---|---|---|---|
| 0.5 | 394 (5.0%) | 371 (4.7%) | 2,149 (27.2%) | 727 (9.2%) | 2,501 (31.7%) | 1,748 (22.2%) |
| 0.6 | 335 (4.2%) | 222 (2.8%) | 1,648 (20.9%) | 469 (5.9%) | 2,501 (31.7%) | 2,715 (34.4%) |
| 0.7 | 273 (3.5%) | 130 (1.6%) | 1,152 (14.6%) | 283 (3.6%) | 2,501 (31.7%) | 3,551 (45.0%) |
| 0.8 | 215 (2.7%) | 62 (0.8%) | 713 (9.0%) | 177 (2.2%) | 2,501 (31.7%) | 4,222 (53.5%) |
| 0.9 | 167 (2.1%) | 19 (0.2%) | 299 (3.8%) | 66 (0.8%) | 2,501 (31.7%) | 4,838 (61.3%) |
-
The two models have opposite tendencies: 74% of OpenCV’s top-ranked facial expressions are neutral, while 32% of hsemotion’s are neutral
- hsemotion mostly ranks emotions as the top choice but has low confidence; at a confidence level of 0.8, it withholds a judgment for more than half of the cases
-
hsemotion overestimates sadness. At 0.5, 27% are classified as sadness, and the samples mostly consist of expressionless or serious faces
4.3 Agreement Rate Between the Two Models
| Reference Value | Total | Emotion Criteria | Emotion Agreement | Both Joy / Anger / Sadness / Surprise |
|---|---|---|---|---|
| 0.5 | 58.6% | 22.5% | 73.1% (950/1,299) | 358 / 38 / 318 / 236 |
| 0.6 | 67.3% | 22.9% | 80.9% (769/951) | 305 / 26 / 244 / 194 |
| 0.7 | 75.3% | 23.2% | 85.3% (590/692) | 250 / 16 / 190 / 134 |
| 0.8 | 81.8% | 23.1% | 91.3% (430/471) | 196 / 9 / 140 / 85 |
| 0.9 | 88.3% | 22.5% | 98.5% (269/273) | 151 / 4 / 82 / 32 |
Emotion Match by Video:
| Reference Value | 1027/VOD | 1055/VOD |
|---|---|---|
| 0.5 | 67.4% | 79.7% |
| 0.6 | 76.3% | 85.9% |
| 0.7 | 81.2% | 89.8% |
| 0.8 | 89.7% | 93.0% |
| 0.9 | 98.5% | 98.6% |
4.4 Sample Observation
📷 Attached images: output/sweep/{영상}/t{기준값}/agree.jpg , mismatch.jpg , sheet_opencv_fer.jpg , sheet_hsemotion.jpg
- Faces classified as the same emotion by both models mostly matched the actual expressions even at a threshold of 0.5 (based on visual inspection)
- Joy is a smiling face, sadness is a crying face, and surprise is a face with wide-open eyes
- The increase in the match rate when the threshold is raised is due to the exclusion of faces that the two models interpreted differently; the quality of the matches where they agreed was already high
- Most cases where the two models disagreed involved one model assigning an emotion while the other classified the face as “neutral”
-
Based on a threshold of 0.5, 2,921 out of 3,270 (89%) were mismatched
-
Only 349 cases (11%) involved the assignment of different emotions, such as joy versus sadness
-
| Mismatched Combination | Actual Face | Correct-Looking Side |
|---|---|---|
| OpenCV Normal / hsemotion Sad (Most Common) | Expressionless, serious face | OpenCV |
| OpenCV Joy / hsemotion Normal·Sadness | Actually smiling faces | OpenCV |
| OpenCV Surprise / hsemotion Normal | Mixed with faces with mouths open while speaking | Ambiguous (excessive OpenCV Surprise) |
| OpenCV General / hsemotion Joy (1,055, several dozen) | Many smiling faces | hsemotion |
5. Conclusion
Recommended threshold: 0.8–0.9 (Use 0.9 to reliably capture only important scenes; use 0.8 to capture more emotional scenes)
-
Emotion matching exceeded 90% for the first time at 0.8
- Total 91.3% (1,027: 89.7%, 1,055: 93.0%)
-
At 0.9, emotion alignment reaches its highest at 98.5%, and the remaining emotional expressions are distinct
-
Based on OpenCV FER standards, 552 instances of joy, 152 of sadness, and 176 of surprise remain—sufficient for service use
-
When upgrading from 0.8 to 0.9, the faces that are mostly excluded are those with faint smiles, serious expressions, or mouths open while speaking; therefore, the loss from excluding them is minimal
-
-
At thresholds of 0.7 or lower, more than 15% of faces are misclassified by the two models as different emotions
Issues not resolved by the threshold
-
For "Angry," there are only 35 faces (0.4%) at a threshold of 0.9, and the expressions are ambiguous
- "Angry" requires either a separate, lower threshold or a distinct evaluation
-
"Emotion Threshold Match"
-
Both models accurately identify "what emotion it is," but they diverge on whether "the face actually shows an emotion"
-
Even when the threshold is raised, the number of correct answers where the two models disagree decreases.
-
6. References
- OpenCV Zoo FER: https://github.com/opencv/opencv_zoo/tree/main/models/facial_expression_recognition
- EmotiEffLib (hsemotion): https://github.com/sb-ai-lab/EmotiEffLib
- insightface: https://github.com/deepinsight/insightface
- RAF-DB: http://whdeng.cn/RAF/model1.html
- AffectNet: https://www.mohammadmahoor.com/pages/databases/affectnet/