Views
No views yet
microsoft/beit-large-patch16-224-pt22k-ft22k for facial emotion recognition using a cleaned and balanced version of the AffectNet dataset.| Emotion | Train Samples | Test Samples |
|---|---|---|
| anger | 1500 | 1718 |
| disgust | 1229 | 1248 |
| fear | 1512 | 1664 |
| happy | 2340 | 2704 |
| neutral | 2758 | 2368 |
| sad | 3091 | 1584 |
| surprise | 2119 | 1920 |
| Epoch | Training Loss | Validation Loss | Accuracy |
|---|---|---|---|
| 1 | 0.4552 | 0.5809 | 0.6917 |
| 2 | 0.3000 | 0.6669 | 0.7079 |
| 3 | 0.1473 | 0.7098 | 0.7378 |
| 4 | 0.0674 | 0.8904 | 0.7353 |
| 5 | 0.0291 | 0.9008 | 0.7452 |
| 6 | 0.0216 | 0.9844 | 0.7503 |
| 7 | 0.0118 | 1.0369 | 0.7522 |
| 8 | 0.0069 | 1.0992 | 0.7486 |
| 9 | 0.0035 | 1.0947 | 0.7482 |
| 10 | 0.0023 | 1.1336 | 0.7461 |
Trainer with the following main arguments:num_train_epochs=10per_device_train_batch_size=64per_device_eval_batch_size=64gradient_accumulation_steps=2learning_rate=5e-5fp16=True (mixed precision training)eval_strategy="epoch"save_strategy="epoch"save_total_limit=2load_best_model_at_end=Truemetric_for_best_model="accuracy"
1from transformers import BeitImageProcessor, BeitForImageClassification
2from PIL import Image
3import requests
4
5image_path = '/RAF-DB/aligned/test_0031_aligned.jpg' # ⬅️ Replace with your image path
6image = Image.open(image_path).convert("RGB")
7
8processor = BeitImageProcessor.from_pretrained("Tanneru/Facial-Emotion-Detection-BEIT-Large")
9model = BeitForImageClassification.from_pretrained("Tanneru/Facial-Emotion-Detection-BEIT-Large")
10
11inputs = processor(images=image, return_tensors="pt")
12
13outputs = model(**inputs)
14logits = outputs.logits
15
16
17predicted_class_idx = logits.argmax(-1).item()
18print("Predicted class:", model.config.id2label[predicted_class_idx])microsoft/beit-large-patch16-224-pt22k-ft22k1@misc{tanneru2025beit_affectnet,
2 title={BEiT-Large fine-tuned on AffectNet for Emotion Detection},
3 author={Tanneru},
4 year={2025},
5 publisher={Hugging Face},
6 howpublished={\url{https://huggingface.co/Tanneru/Facial-Emotion-Detection-BEIT-Large}},
7}
8
9@article{bao2021beit,
10 author = {Hangbo Bao and Li Dong and Furu Wei},
11 title = {BEiT: BERT Pre-Training of Image Transformers},
12 journal = {CoRR},
13 volume = {abs/2106.08254},
14 year = {2021},
15 url = {https://arxiv.org/abs/2106.08254},
16 archivePrefix = {arXiv},
17 eprint = {2106.08254},
18 bibsource = {dblp computer science bibliography, https://dblp.org}
19}
20
21