Mamd1 commited on
Commit
dce1dbf
Β·
verified Β·
1 Parent(s): 0b7fda2

Add model card

Browse files
Files changed (1) hide show
  1. README.md +93 -0
README.md ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ library_name: keras
4
+ pipeline_tag: image-classification
5
+ tags:
6
+ - emotion-detection
7
+ - facial-expression-recognition
8
+ - image-classification
9
+ - keras
10
+ - tensorflow
11
+ - efficientnetv2
12
+ ---
13
+
14
+ # Facial Emotion Recognition β€” Model
15
+
16
+ Detects the emotion expressed in a photo of a human face.
17
+
18
+ Facial emotion classification model in Keras 3 format (`best_model.keras`).
19
+ Given a cropped face image it outputs probabilities over 7 emotion classes.
20
+
21
+ - **Maintainer of this repository**: Mamd1
22
+ - **Repository**: `Mamd1/emotion-detection-model`
23
+ - **Demo Space**: `Mamd1/emotion-detection-app`
24
+ - **License**: Apache-2.0
25
+
26
+ ## Attribution
27
+
28
+ These weights were **not trained by the maintainer of this repository**. They are
29
+ redistributed from the original Apache-2.0 licensed release by **Ali Ahmed**
30
+ (`ali-ahmed-ai-developer/emotion_detection_model` on the Hugging Face Hub).
31
+ Apache-2.0 permits redistribution and modification provided the license and
32
+ attribution are preserved β€” this notice satisfies that requirement. Do not
33
+ remove it.
34
+
35
+ ## Classes
36
+
37
+ Index order matters β€” the output vector is in exactly this order:
38
+
39
+ | Index | Class |
40
+ |-------|----------|
41
+ | 0 | angry |
42
+ | 1 | disgust |
43
+ | 2 | fear |
44
+ | 3 | happy |
45
+ | 4 | neutral |
46
+ | 5 | sad |
47
+ | 6 | surprise |
48
+
49
+ ## Model details
50
+
51
+ - **Backbone**: EfficientNetV2-S (ImageNet pre-trained)
52
+ - **Head**: GlobalAveragePooling2D β†’ BatchNorm β†’ Dropout β†’ Dense(512) β†’ BatchNorm β†’ Dropout β†’ Dense(7)
53
+ - **Input shape**: `(380, 380, 3)`, float32, values in `[0, 255]` (EfficientNetV2 rescales internally)
54
+ - **Parameters**: ~21M
55
+ - **File**: `best_model.keras` (~343 MB, stored via Git LFS)
56
+
57
+ ## Preprocessing
58
+
59
+ The reference application converts the image to grayscale, then back to RGB
60
+ (so R=G=B across 3 channels), resizes to 380x380, and passes raw `[0, 255]`
61
+ float32 values. Matching this preprocessing is required for accurate results.
62
+
63
+ ## Usage
64
+
65
+ ```python
66
+ import numpy as np
67
+ import tensorflow as tf
68
+ from PIL import Image
69
+ from huggingface_hub import hf_hub_download
70
+
71
+ CLASSES = ['angry', 'disgust', 'fear', 'happy', 'neutral', 'sad', 'surprise']
72
+
73
+ path = hf_hub_download(
74
+ repo_id="Mamd1/emotion-detection-model",
75
+ filename="best_model.keras",
76
+ )
77
+ model = tf.keras.models.load_model(path)
78
+
79
+ image = Image.open("face.jpg").convert("L").convert("RGB").resize((380, 380))
80
+ x = np.expand_dims(np.array(image, dtype=np.float32), axis=0)
81
+
82
+ probs = model.predict(x)[0]
83
+ print(dict(zip(CLASSES, probs.tolist())))
84
+ ```
85
+
86
+ ## Limitations
87
+
88
+ - Trained on tightly cropped faces. Wide shots, small faces, or busy backgrounds
89
+ degrade accuracy significantly β€” crop to the face first.
90
+ - Facial expression recognition is not a reliable measure of a person's actual
91
+ internal emotional state. Do not use for consequential decisions about people
92
+ (hiring, security screening, medical or psychological assessment).
93
+ - Accuracy varies across demographic groups and lighting conditions.