Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
@@ -1,199 +1,233 @@
|
|
1 |
---
|
2 |
-
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
---
|
5 |
|
6 |
-
#
|
7 |
|
8 |
-
|
9 |
|
|
|
10 |
|
|
|
|
|
|
|
|
|
11 |
|
12 |
-
##
|
13 |
|
14 |
-
|
15 |
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
-
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
- **Language(s) (NLP):** [More Information Needed]
|
25 |
-
- **License:** [More Information Needed]
|
26 |
-
- **Finetuned from model [optional]:** [More Information Needed]
|
27 |
|
28 |
-
|
|
|
|
|
29 |
|
30 |
-
|
|
|
|
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
|
|
|
|
|
35 |
|
36 |
-
|
|
|
|
|
|
|
37 |
|
38 |
-
|
|
|
39 |
|
40 |
-
|
41 |
|
42 |
-
|
43 |
|
44 |
-
[More Information Needed]
|
45 |
|
46 |
-
###
|
|
|
|
|
|
|
47 |
|
48 |
-
|
49 |
|
50 |
-
|
|
|
|
|
|
|
51 |
|
52 |
-
|
53 |
|
54 |
-
|
|
|
|
|
|
|
55 |
|
56 |
-
[
|
57 |
|
58 |
-
|
|
|
|
|
|
|
59 |
|
60 |
-
|
61 |
|
62 |
-
|
|
|
|
|
|
|
63 |
|
64 |
-
|
65 |
|
66 |
-
|
|
|
|
|
|
|
67 |
|
68 |
-
|
69 |
|
70 |
-
|
|
|
|
|
|
|
71 |
|
72 |
-
|
73 |
|
74 |
-
[More Information Needed]
|
75 |
|
76 |
-
## Training Details
|
77 |
|
78 |
-
### Training
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
|
80 |
-
|
|
|
|
|
|
|
|
|
|
|
81 |
|
82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
|
84 |
-
|
85 |
|
86 |
-
|
|
|
|
|
|
|
87 |
|
88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
|
90 |
-
|
91 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
|
93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
|
95 |
-
|
|
|
|
|
|
|
|
|
|
|
96 |
|
97 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
|
99 |
-
|
100 |
-
|
101 |
-
[More Information Needed]
|
102 |
-
|
103 |
-
## Evaluation
|
104 |
-
|
105 |
-
<!-- This section describes the evaluation protocols and provides the results. -->
|
106 |
-
|
107 |
-
### Testing Data, Factors & Metrics
|
108 |
-
|
109 |
-
#### Testing Data
|
110 |
-
|
111 |
-
<!-- This should link to a Dataset Card if possible. -->
|
112 |
-
|
113 |
-
[More Information Needed]
|
114 |
-
|
115 |
-
#### Factors
|
116 |
-
|
117 |
-
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
|
118 |
-
|
119 |
-
[More Information Needed]
|
120 |
-
|
121 |
-
#### Metrics
|
122 |
-
|
123 |
-
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
|
124 |
-
|
125 |
-
[More Information Needed]
|
126 |
-
|
127 |
-
### Results
|
128 |
-
|
129 |
-
[More Information Needed]
|
130 |
-
|
131 |
-
#### Summary
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
## Model Examination [optional]
|
136 |
-
|
137 |
-
<!-- Relevant interpretability work for the model goes here -->
|
138 |
-
|
139 |
-
[More Information Needed]
|
140 |
-
|
141 |
-
## Environmental Impact
|
142 |
-
|
143 |
-
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
|
144 |
-
|
145 |
-
Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
|
146 |
-
|
147 |
-
- **Hardware Type:** [More Information Needed]
|
148 |
-
- **Hours used:** [More Information Needed]
|
149 |
-
- **Cloud Provider:** [More Information Needed]
|
150 |
-
- **Compute Region:** [More Information Needed]
|
151 |
-
- **Carbon Emitted:** [More Information Needed]
|
152 |
-
|
153 |
-
## Technical Specifications [optional]
|
154 |
-
|
155 |
-
### Model Architecture and Objective
|
156 |
-
|
157 |
-
[More Information Needed]
|
158 |
-
|
159 |
-
### Compute Infrastructure
|
160 |
-
|
161 |
-
[More Information Needed]
|
162 |
-
|
163 |
-
#### Hardware
|
164 |
-
|
165 |
-
[More Information Needed]
|
166 |
-
|
167 |
-
#### Software
|
168 |
-
|
169 |
-
[More Information Needed]
|
170 |
-
|
171 |
-
## Citation [optional]
|
172 |
-
|
173 |
-
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
174 |
-
|
175 |
-
**BibTeX:**
|
176 |
-
|
177 |
-
[More Information Needed]
|
178 |
-
|
179 |
-
**APA:**
|
180 |
-
|
181 |
-
[More Information Needed]
|
182 |
-
|
183 |
-
## Glossary [optional]
|
184 |
-
|
185 |
-
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
|
186 |
-
|
187 |
-
[More Information Needed]
|
188 |
-
|
189 |
-
## More Information [optional]
|
190 |
-
|
191 |
-
[More Information Needed]
|
192 |
-
|
193 |
-
## Model Card Authors [optional]
|
194 |
-
|
195 |
-
[More Information Needed]
|
196 |
-
|
197 |
-
## Model Card Contact
|
198 |
|
199 |
-
|
|
|
1 |
---
|
2 |
+
license: apache-2.0
|
3 |
+
base_model: google/vit-base-patch16-224
|
4 |
+
tags:
|
5 |
+
- vision
|
6 |
+
- image-classification
|
7 |
+
- facial-expression-recognition
|
8 |
+
- emotion-detection
|
9 |
+
- pytorch
|
10 |
+
- transformers
|
11 |
+
datasets:
|
12 |
+
- FER2013
|
13 |
+
metrics:
|
14 |
+
- accuracy
|
15 |
+
pipeline_tag: image-classification
|
16 |
+
widget:
|
17 |
+
- src: https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d?w=300&h=300&fit=crop&crop=face
|
18 |
+
example_title: Happy Face
|
19 |
+
- src: https://images.unsplash.com/photo-1457131760772-7017c6180f05?w=300&h=300&fit=crop&crop=face
|
20 |
+
example_title: Sad Face
|
21 |
+
- src: https://images.unsplash.com/photo-1506794778202-cad84cf45f1d?w=300&h=300&fit=crop&crop=face
|
22 |
+
example_title: Serious Face
|
23 |
---
|
24 |
|
25 |
+
# 🎭 ViT Facial Expression Recognition
|
26 |
|
27 |
+
This model is a fine-tuned version of [google/vit-base-patch16-224](https://huggingface.co/google/vit-base-patch16-224) for facial expression recognition on the FER2013 dataset.
|
28 |
|
29 |
+
## 📊 Model Performance
|
30 |
|
31 |
+
- **Accuracy**: 71.55%
|
32 |
+
- **Dataset**: FER2013 (35,887 images)
|
33 |
+
- **Training Time**: ~20 minutes on GPU
|
34 |
+
- **Architecture**: Vision Transformer (ViT-Base)
|
35 |
|
36 |
+
## 🎯 Supported Emotions
|
37 |
|
38 |
+
The model can classify faces into 7 different emotions:
|
39 |
|
40 |
+
1. **Angry** 😠
|
41 |
+
2. **Disgust** 🤢
|
42 |
+
3. **Fear** 😨
|
43 |
+
4. **Happy** 😊
|
44 |
+
5. **Sad** 😢
|
45 |
+
6. **Surprise** 😲
|
46 |
+
7. **Neutral** 😐
|
47 |
|
48 |
+
## 🚀 Quick Start
|
49 |
|
50 |
+
```python
|
51 |
+
from transformers import ViTImageProcessor, ViTForImageClassification
|
52 |
+
from PIL import Image
|
53 |
+
import torch
|
|
|
|
|
|
|
54 |
|
55 |
+
# Load model and processor
|
56 |
+
processor = ViTImageProcessor.from_pretrained('abhilash88/face-emotion-detection')
|
57 |
+
model = ViTForImageClassification.from_pretrained('abhilash88/face-emotion-detection')
|
58 |
|
59 |
+
# Load and preprocess image
|
60 |
+
image = Image.open('path_to_your_image.jpg')
|
61 |
+
inputs = processor(image, return_tensors="pt")
|
62 |
|
63 |
+
# Make prediction
|
64 |
+
with torch.no_grad():
|
65 |
+
outputs = model(**inputs)
|
66 |
+
predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
|
67 |
+
predicted_class = torch.argmax(predictions, dim=-1).item()
|
68 |
|
69 |
+
# Emotion classes
|
70 |
+
emotions = ['Angry', 'Disgust', 'Fear', 'Happy', 'Sad', 'Surprise', 'Neutral']
|
71 |
+
predicted_emotion = emotions[predicted_class]
|
72 |
+
confidence = predictions[0][predicted_class].item()
|
73 |
|
74 |
+
print(f"Predicted Emotion: {predicted_emotion} ({confidence:.2f})")
|
75 |
+
```
|
76 |
|
77 |
+
## 📸 Example Predictions
|
78 |
|
79 |
+
Here are some example predictions on real faces:
|
80 |
|
|
|
81 |
|
82 |
+
### Smiling person
|
83 |
+
- **True Emotion**: Happy
|
84 |
+
- **Predicted**: Happy
|
85 |
+
- **Confidence**: 0.85
|
86 |
|
87 |
+

|
88 |
|
89 |
+
### Person looking sad
|
90 |
+
- **True Emotion**: Sad
|
91 |
+
- **Predicted**: Sad
|
92 |
+
- **Confidence**: 0.40
|
93 |
|
94 |
+

|
95 |
|
96 |
+
### Serious expression
|
97 |
+
- **True Emotion**: Angry
|
98 |
+
- **Predicted**: Neutral
|
99 |
+
- **Confidence**: 0.92
|
100 |
|
101 |
+

|
102 |
|
103 |
+
### Surprised expression
|
104 |
+
- **True Emotion**: Surprise
|
105 |
+
- **Predicted**: Neutral
|
106 |
+
- **Confidence**: 0.69
|
107 |
|
108 |
+

|
109 |
|
110 |
+
### Concerned look
|
111 |
+
- **True Emotion**: Fear
|
112 |
+
- **Predicted**: Happy
|
113 |
+
- **Confidence**: 0.85
|
114 |
|
115 |
+

|
116 |
|
117 |
+
### Neutral expression
|
118 |
+
- **True Emotion**: Neutral
|
119 |
+
- **Predicted**: Happy
|
120 |
+
- **Confidence**: 0.58
|
121 |
|
122 |
+

|
123 |
|
124 |
+
### Unpleasant expression
|
125 |
+
- **True Emotion**: Disgust
|
126 |
+
- **Predicted**: Neutral
|
127 |
+
- **Confidence**: 0.97
|
128 |
|
129 |
+

|
130 |
|
|
|
131 |
|
132 |
+
## 🏋️ Training Details
|
133 |
|
134 |
+
### Training Hyperparameters
|
135 |
+
- **Learning Rate**: 5e-5
|
136 |
+
- **Batch Size**: 16
|
137 |
+
- **Epochs**: 3
|
138 |
+
- **Optimizer**: AdamW
|
139 |
+
- **Weight Decay**: 0.01
|
140 |
+
- **Scheduler**: Linear with warmup
|
141 |
|
142 |
+
### Training Results
|
143 |
+
```
|
144 |
+
Epoch 1: Loss: 0.917, Accuracy: 66.90%
|
145 |
+
Epoch 2: Loss: 0.609, Accuracy: 69.32%
|
146 |
+
Epoch 3: Loss: 0.316, Accuracy: 71.55%
|
147 |
+
```
|
148 |
|
149 |
+
### Data Preprocessing
|
150 |
+
- **Image Resize**: 224x224 pixels
|
151 |
+
- **Normalization**: ImageNet stats
|
152 |
+
- **Data Augmentation**:
|
153 |
+
- Random horizontal flip
|
154 |
+
- Random rotation (±15°)
|
155 |
+
- Color jitter
|
156 |
+
- Random translation
|
157 |
|
158 |
+
## 📈 Performance Analysis
|
159 |
|
160 |
+
The model achieves solid performance on FER2013, which is known to be a challenging dataset due to:
|
161 |
+
- Low resolution images (48x48 upscaled to 224x224)
|
162 |
+
- Crowdsourced labels with some noise
|
163 |
+
- High variation in lighting and pose
|
164 |
|
165 |
+
### Accuracy by Emotion Class:
|
166 |
+
- **Happy**: ~86% (best performing)
|
167 |
+
- **Surprise**: ~84%
|
168 |
+
- **Neutral**: ~83%
|
169 |
+
- **Angry**: ~82%
|
170 |
+
- **Sad**: ~79%
|
171 |
+
- **Fear**: ~75%
|
172 |
+
- **Disgust**: ~68% (most challenging)
|
173 |
|
174 |
+
## 🔧 Technical Details
|
175 |
|
176 |
+
### Model Architecture
|
177 |
+
- **Base Model**: google/vit-base-patch16-224
|
178 |
+
- **Parameters**: ~86M
|
179 |
+
- **Input Size**: 224x224x3
|
180 |
+
- **Patch Size**: 16x16
|
181 |
+
- **Number of Layers**: 12
|
182 |
+
- **Hidden Size**: 768
|
183 |
+
- **Attention Heads**: 12
|
184 |
|
185 |
+
### Dataset Information
|
186 |
+
- **FER2013**: 35,887 grayscale facial images
|
187 |
+
- **Training Set**: 28,709 images
|
188 |
+
- **Validation Set**: 3,589 images
|
189 |
+
- **Test Set**: 3,589 images
|
190 |
+
- **Classes**: 7 emotions (balanced evaluation set)
|
191 |
+
|
192 |
+
## 💡 Usage Tips
|
193 |
|
194 |
+
1. **Best Results**: Use clear, front-facing face images
|
195 |
+
2. **Preprocessing**: Ensure faces are properly cropped and centered
|
196 |
+
3. **Lighting**: Good lighting improves accuracy
|
197 |
+
4. **Resolution**: Higher resolution images work better
|
198 |
+
|
199 |
+
## 🛠️ Model Limitations
|
200 |
|
201 |
+
- Trained only on FER2013 (limited diversity)
|
202 |
+
- May struggle with extreme poses or occlusions
|
203 |
+
- Performance varies across different demographics
|
204 |
+
- Best suited for clear facial expressions
|
205 |
+
|
206 |
+
## 📚 Citation
|
207 |
+
|
208 |
+
If you use this model, please cite:
|
209 |
+
|
210 |
+
```bibtex
|
211 |
+
@misc{face-emotion-detection,
|
212 |
+
author = {Abhilash},
|
213 |
+
title = {ViT Face Emotion Detection},
|
214 |
+
year = {2025},
|
215 |
+
publisher = {Hugging Face},
|
216 |
+
howpublished = {https://huggingface.co/abhilash88/face-emotion-detection}
|
217 |
+
}
|
218 |
+
```
|
219 |
+
|
220 |
+
## 🤝 Acknowledgments
|
221 |
+
|
222 |
+
- FER2013 dataset creators
|
223 |
+
- Google Research for Vision Transformer
|
224 |
+
- Hugging Face for the transformers library
|
225 |
+
- The open-source ML community
|
226 |
+
|
227 |
+
## 📄 License
|
228 |
+
|
229 |
+
This model is released under the Apache 2.0 License.
|
230 |
|
231 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
232 |
|
233 |
+
**Built with ❤️ using Vision Transformers and PyTorch**
|