Skip to main content

Face Expression Detection: Tackling Class Imbalance with Ensemble Learning and Cloud GPUs

Technical deep-dive into building a facial expression recognition system for group photos. From handling severe class imbalance to cloud GPU training on Modal.com, deploying on Hugging Face Spaces.

15 min read
Computer VisionDeep LearningPyTorchTransfer LearningMTCNNFlaskHugging FaceModal.com
Face Expression Detection: Tackling Class Imbalance with Ensemble Learning and Cloud GPUs

Frequently Asked Questions

How accurate is the facial expression model?

The final weighted ensemble reaches 80% accuracy across 7 emotions on RAF-DB. More importantly, per-class recall on the rare Fear and Disgust classes rose from around 50% into the high-60s, so the model no longer ignores minority emotions.

How do you handle class imbalance in emotion recognition?

Not with SMOTEENN. A weighted sampler for balanced batches, class weights, high dropout (0.6), label smoothing (0.15), and ensembling models trained with different losses together beat any single fix. Focal Loss alone helped the minority classes but wrecked the majority ones.

Why ResNet-18 instead of a bigger model like EfficientNet-B2?

ResNet-18 generalized better on this 15,339-image dataset and outperformed the larger EfficientNet-B2. On smaller datasets the simpler model often wins, and the deeper custom classification head mattered more than backbone size.

How much did training cost?

About $3.50 total. Every experiment ran on Modal.com's pay-per-use A100 GPUs, which made cloud training affordable without owning a local GPU.