hf_mirrors/Facial-Emotion-Detection-FER-RAFDB-AffectNet-BEIT-Large
Model Introduction
Files & versions
Analysis

BEiT-Large for Emotion Detection on FER-2013, RAF-DB, and AffectNet

This model is fine-tuned from microsoft/beit-large-patch16-224-pt22k-ft22k for facial emotion recognition using a combined dataset made from:

  • FER-2013
  • RAF-DB
  • AffectNet (Cleaned & Balanced)

This fusion of diverse facial expression datasets improves the model's ability to generalize across real-world facial emotion recognition tasks.


🧠 Classes

The model predicts the following 7 basic emotion classes:

  • 😠 anger
  • 🤢 disgust
  • 😨 fear
  • 😀 happy
  • 😐 neutral
  • 😢 sad
  • 😲 surprise

📈 Training Metrics

EpochTraining LossValidation LossAccuracyPrecisionRecallF1
10.47880.68790.72490.69060.68890.6863
20.38650.62260.74000.70050.71240.7015
30.32770.61820.74420.70420.71360.7045
40.27130.64810.74000.70250.71120.7022
50.23720.75960.75440.72630.72140.7216
60.19160.73920.75540.72340.72410.7223
70.15690.80170.74950.71790.71500.7078
80.12970.87380.76150.73060.72200.7228
90.11290.92510.75670.72830.71940.7175
100.09870.89250.76530.73370.72630.7267
110.08191.08420.76160.73980.71680.7227
120.06710.92450.76200.73320.72770.7254
130.05910.97750.76700.74000.72770.7298
140.05231.04650.76640.74490.72570.7298
150.04761.04870.75710.72740.72190.7189
160.04811.11640.76190.74140.71880.7237
170.03781.17380.75670.73760.71390.7196

✅ Final Accuracy: ~76.2%
✅ Final F1 Score: ~0.725


🛠️ Training Configuration

The model was trained using the Hugging Face Trainer with the following key arguments:

  • num_train_epochs=20
  • per_device_train_batch_size=32
  • per_device_eval_batch_size=32
  • gradient_accumulation_steps=2
  • learning_rate=2e-5
  • fp16=True (mixed precision)
  • eval_strategy="epoch"
  • save_strategy="epoch"
  • save_total_limit=2
  • load_best_model_at_end=True
  • metric_for_best_model="f1"
  • greater_is_better=True

🔄 Confusion Matrix

Confusion Matrix


📊 Classification Report

Classification Report


🔧 How to Use

from transformers import BeitImageProcessor, BeitForImageClassification
from PIL import Image

image = Image.open("/your/image/path.jpg").convert("RGB")

processor = BeitImageProcessor.from_pretrained("Tanneru/Facial-Emotion-Detection-FER-RAFDB-AffectNet-BEIT-Large")
model = BeitForImageClassification.from_pretrained("Tanneru/Facial-Emotion-Detection-FER-RAFDB-AffectNet-BEIT-Large")

inputs = processor(images=image, return_tensors="pt")
outputs = model(**inputs)
predicted_class = outputs.logits.argmax(-1).item()

print("Predicted emotion:", model.config.id2label[predicted_class])

📄 License

This model is released under the Apache 2.0 License. You are free to use, modify, and distribute the model with attribution.


✍️ Author

  • Username: Tanneru
  • Base model: microsoft/beit-large-patch16-224-pt22k-ft22k

📚 Citation

If you use this model in your work, please cite:

@misc{tanneru2025beit_affectnet,
  title={BEiT-Large fine-tuned on AffectNet for Emotion Detection},
  author={Tanneru},
  year={2025},
  publisher={Hugging Face},
  howpublished={\url{https://huggingface.co/Tanneru/Facial-Emotion-Detection-FER-RAFDB-AffectNet-BEIT-Large}},
}

@article{bao2021beit,
  author       = {Hangbo Bao and Li Dong and Furu Wei},
  title        = {BEiT: BERT Pre-Training of Image Transformers},
  journal      = {CoRR},
  volume       = {abs/2106.08254},
  year         = {2021},
  url          = {https://arxiv.org/abs/2106.08254},
  archivePrefix = {arXiv},
  eprint       = {2106.08254},
  bibsource    = {dblp computer science bibliography, https://dblp.org}
}