Overview
The emotion recognition model is a scikit-learn classifier trained to predict emotions from facial landmark features. The model is serialized using Python’spickle module and stored in the model file.
Loading the Model
The model is loaded at application startup inapp.py:28-29:
Error Handling
If the model file is missing, the application raises a clear error:Model Interface
predict() Method
The model follows the standard scikit-learn interface:A 2D array where each row contains 136 facial landmark features (68 points × 2 coordinates). Typically passed as a single-element list:
[face_landmarks].Returns an array of emotion indices. For a single prediction, access the result with
output[0].Emotion Indices:0= HAPPY1= SAD
Emotion Mapping
The emotion labels are defined inapp.py:19:
| Index | Emotion | Description |
|---|---|---|
| 0 | HAPPY | Positive, joyful expression |
| 1 | SAD | Negative, sorrowful expression |
Usage Example
Complete Prediction Pipeline
Batch Prediction
Integration with Flask Endpoint
This is how the model is used in the actual/predict endpoint (app.py:50-51):
Model Requirements
Input Format
- Type: List of 136 float values
- Structure:
[x1, y1, x2, y2, ..., x68, y68] - Normalization: Coordinates normalized to 0.0-1.0 range
- Source: Output from
get_face_landmarks()
Output Format
- Type: numpy.ndarray
- Shape:
(n_samples,)for n predictions - Values: Integer indices (0 or 1 for current model)
Model Training
To train or retrain the model, run:model file with the trained classifier.
Model File Location
The model file is expected at:app.py is located.
Technical Details
- Format: Python pickle (protocol version depends on training environment)
- Framework: scikit-learn (exact classifier type determined during training)
- Feature dimension: 136 (68 facial landmarks × 2 coordinates)
- Output classes: 2 (HAPPY, SAD)
- Thread safety: Model predictions are thread-safe in scikit-learn

