Downloads · 30 days
222
62% of all-time downloads
jihedjabnoun/vit-face-emotion-recognition
vit-face-emotion-recognition is a image classification model from jihedjabnoun. Use it when you need a label for an image. It is set up for transformers. The card lists the license as apache-2.0.
This model is a fine-tuned Vision Transformer (ViT) for facial emotion recognition. It can classify images into 7 different emotions: Anger, Disgust, Fear, Happiness, Neutral, Sadness, and Surprise.
Downloads · 30 days
222
62% of all-time downloads
All-time downloads
356
Public
Parameters
85.8M
1.4 GB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors343 MB · 100%
From the Hugging Face model README
This model is a fine-tuned Vision Transformer (ViT) for facial emotion recognition. It can classify images into 7 different emotions: Anger, Disgust, Fear, Happiness, Neutral, Sadness, and Surprise.
The model was trained on a combination of four popular emotion recognition datasets:
Total: 61,743 training images, 10,909 validation images
The model achieves the following performance on the validation set:
| Emotion | Precision | Recall | F1-Score | Support |
|---|---|---|---|---|
| Anger | 0.827 | 0.799 | 0.813 | 1570 |
| Disgust | 0.869 | 0.835 | 0.852 | 629 |
| Fear | 0.786 | 0.743 | 0.764 | 1374 |
| Happiness | 0.926 | 0.914 | 0.920 | 2579 |
| Neutral | 0.767 | 0.820 | 0.793 | 1738 |
| Sadness | 0.760 | 0.798 | 0.779 | 1851 |
| Surprise | 0.867 | 0.846 | 0.856 | 1168 |
precision recall f1-score support
Anger 0.827 0.799 0.813 1570
Disgust 0.869 0.835 0.852 629
Fear 0.786 0.743 0.764 1374
Happiness 0.926 0.914 0.920 2579
Neutral 0.767 0.820 0.793 1738
Sadness 0.760 0.798 0.779 1851
Surprise 0.867 0.846 0.856 1168
macro avg 0.829 0.822 0.825 10909
weighted avg 0.831 0.829 0.830 10909
from transformers import ViTImageProcessor, ViTForImageClassification
from PIL import Image
import torch
# Load model and processor
model = ViTForImageClassification.from_pretrained("jihedjabnoun/vit-face-emotion-recognition")
processor = ViTImageProcessor.from_pretrained("jihedjabnoun/vit-face-emotion-recognition")
# Load and process image
image = Image.open("path_to_your_image.jpg")
inputs = processor(images=image, return_tensors="pt")
# Make prediction
with torch.no_grad():
outputs = model(**inputs)
logits = outputs.logits
predicted_class_id = logits.argmax().item()
# Get emotion labels
emotions = ['Anger', 'Disgust', 'Fear', 'Happiness', 'Neutral', 'Sadness', 'Surprise']
predicted_emotion = emotions[predicted_class_id]
# Get confidence scores
probabilities = torch.nn.functional.softmax(logits, dim=-1)[0]
confidence = probabilities[predicted_class_id].item()
print(f"Predicted Emotion: {predicted_emotion}")
print(f"Confidence: {confidence:.3f}")
# Show all emotion probabilities
for i, emotion in enumerate(emotions):
prob = probabilities[i].item()
print(f"{emotion}: {prob:.3f}")
If you use this model, please cite:
@misc{jihed-vit-emotion-2025,
author = {Jihed Jabnoun},
title = {Vision Transformer for Face Emotion Recognition},
year = {2025},
publisher = {Hugging Face},
howpublished = {\url{https://huggingface.co/jihedjabnoun/vit-face-emotion-recognition}}
}
For questions or feedback about this model, please contact the model author through Hugging Face.