Views
No views yet

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.
1Classification Report:
2 precision recall f1-score support
3
4 Ahegao 0.9916 0.9801 0.9858 1205
5 Angry 0.8633 0.7502 0.8028 1313
6 Happy 0.9494 0.9684 0.9588 3740
7 Neutral 0.7635 0.8781 0.8168 4027
8 Sad 0.8595 0.7794 0.8175 3934
9 Surprise 0.9025 0.8104 0.8540 1234
10
11 accuracy 0.8665 15453
12 macro avg 0.8883 0.8611 0.8726 15453
13weighted avg 0.8703 0.8665 0.8663 15453
The model categorizes images into 6 facial emotion classes:
Class 0: "Ahegao"
Class 1: "Angry"
Class 2: "Happy"
Class 3: "Neutral"
Class 4: "Sad"
Class 5: "Surprise"!pip install -q transformers torch pillow gradio1import gradio as gr
2from transformers import AutoImageProcessor
3from transformers import SiglipForImageClassification
4from transformers.image_utils import load_image
5from PIL import Image
6import torch
7
8# Load model and processor
9model_name = "prithivMLmods/Facial-Emotion-Detection-SigLIP2"
10model = SiglipForImageClassification.from_pretrained(model_name)
11processor = AutoImageProcessor.from_pretrained(model_name)
12
13def emotion_classification(image):
14 """Predicts facial emotion classification for an image."""
15 image = Image.fromarray(image).convert("RGB")
16 inputs = processor(images=image, return_tensors="pt")
17
18 with torch.no_grad():
19 outputs = model(**inputs)
20 logits = outputs.logits
21 probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()
22
23 labels = {
24 "0": "Ahegao", "1": "Angry", "2": "Happy", "3": "Neutral",
25 "4": "Sad", "5": "Surprise"
26 }
27 predictions = {labels[str(i)]: round(probs[i], 3) for i in range(len(probs))}
28
29 return predictions
30
31# Create Gradio interface
32iface = gr.Interface(
33 fn=emotion_classification,
34 inputs=gr.Image(type="numpy"),
35 outputs=gr.Label(label="Prediction Scores"),
36 title="Facial Emotion Detection",
37 description="Upload an image to classify the facial emotion."
38)
39
40# Launch the app
41if __name__ == "__main__":
42 iface.launch()