Update README.md
Browse files
README.md
CHANGED
@@ -1,6 +1,11 @@
|
|
1 |
---
|
2 |
license: apache-2.0
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
4 |
```py
|
5 |
Classification Report:
|
6 |
precision recall f1-score support
|
@@ -17,3 +22,71 @@ Classification Report:
|
|
17 |
weighted avg 0.8703 0.8665 0.8663 15453
|
18 |
```
|
19 |

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
license: apache-2.0
|
3 |
---
|
4 |
+
# **Facial-Emotion-Detection-SigLIP2**
|
5 |
+
|
6 |
+
> **Facial-Emotion-Detection-SigLIP2** is an image classification vision-language encoder model fine-tuned from **google/siglip2-base-patch16-224** for a single-label classification task. It is designed to classify different facial emotions using the **SiglipForImageClassification** architecture.
|
7 |
+
|
8 |
+
|
9 |
```py
|
10 |
Classification Report:
|
11 |
precision recall f1-score support
|
|
|
22 |
weighted avg 0.8703 0.8665 0.8663 15453
|
23 |
```
|
24 |

|
25 |
+
|
26 |
+
The model categorizes images into 6 facial emotion classes:
|
27 |
+
|
28 |
+
Class 0: "Ahegao"
|
29 |
+
Class 1: "Angry"
|
30 |
+
Class 2: "Happy"
|
31 |
+
Class 3: "Neutral"
|
32 |
+
Class 4: "Sad"
|
33 |
+
Class 5: "Surprise"
|
34 |
+
|
35 |
+
```python
|
36 |
+
!pip install -q transformers torch pillow gradio
|
37 |
+
```
|
38 |
+
|
39 |
+
```python
|
40 |
+
import gradio as gr
|
41 |
+
from transformers import AutoImageProcessor
|
42 |
+
from transformers import SiglipForImageClassification
|
43 |
+
from transformers.image_utils import load_image
|
44 |
+
from PIL import Image
|
45 |
+
import torch
|
46 |
+
|
47 |
+
# Load model and processor
|
48 |
+
model_name = "prithivMLmods/Facial-Emotion-Detection-SigLIP2"
|
49 |
+
model = SiglipForImageClassification.from_pretrained(model_name)
|
50 |
+
processor = AutoImageProcessor.from_pretrained(model_name)
|
51 |
+
|
52 |
+
def emotion_classification(image):
|
53 |
+
"""Predicts facial emotion classification for an image."""
|
54 |
+
image = Image.fromarray(image).convert("RGB")
|
55 |
+
inputs = processor(images=image, return_tensors="pt")
|
56 |
+
|
57 |
+
with torch.no_grad():
|
58 |
+
outputs = model(**inputs)
|
59 |
+
logits = outputs.logits
|
60 |
+
probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()
|
61 |
+
|
62 |
+
labels = {
|
63 |
+
"0": "Ahegao", "1": "Angry", "2": "Happy", "3": "Neutral",
|
64 |
+
"4": "Sad", "5": "Surprise"
|
65 |
+
}
|
66 |
+
predictions = {labels[str(i)]: round(probs[i], 3) for i in range(len(probs))}
|
67 |
+
|
68 |
+
return predictions
|
69 |
+
|
70 |
+
# Create Gradio interface
|
71 |
+
iface = gr.Interface(
|
72 |
+
fn=emotion_classification,
|
73 |
+
inputs=gr.Image(type="numpy"),
|
74 |
+
outputs=gr.Label(label="Prediction Scores"),
|
75 |
+
title="Facial Emotion Detection",
|
76 |
+
description="Upload an image to classify the facial emotion."
|
77 |
+
)
|
78 |
+
|
79 |
+
# Launch the app
|
80 |
+
if __name__ == "__main__":
|
81 |
+
iface.launch()
|
82 |
+
```
|
83 |
+
|
84 |
+
# **Intended Use:**
|
85 |
+
|
86 |
+
The **Facial-Emotion-Detection-SigLIP2** model is designed to classify different facial emotions based on images. Potential use cases include:
|
87 |
+
|
88 |
+
- **Mental Health Monitoring:** Detecting emotional states for well-being analysis.
|
89 |
+
- **Human-Computer Interaction:** Enhancing user experience by recognizing emotions.
|
90 |
+
- **Security & Surveillance:** Identifying suspicious or aggressive behaviors.
|
91 |
+
- **AI-Powered Assistants:** Supporting AI-based emotion recognition for various applications.
|
92 |
+
|