πŸ™‚ CNN β€” Facial Expression Recognition

CNN-based facial expression classifier trained to recognize 7 emotion categories from face images with a clean, reproducible pipeline.


πŸ“Œ Model Summary

Property Details
πŸ—οΈ Architecture CNN (custom)
🎯 Task Image Classification
πŸ˜€ Classes 7 emotions
βš™οΈ Framework PyTorch
πŸ“ Input size 48 Γ— 48 px (grayscale)
πŸ“œ License MIT

🧠 Emotion Classes

# Emotion
0 😠 Angry
1 🀒 Disgust
2 😨 Fear
3 πŸ˜„ Happy
4 😐 Neutral
5 😒 Sad
6 😲 Surprise

πŸš€ How to Use

import torch
import torch.nn.functional as F
from torchvision import transforms
from PIL import Image

# Load model
model = torch.jit.load("model.pt", map_location="cpu")
model.eval()

# Preprocessing
transform = transforms.Compose([
    transforms.Grayscale(),
    transforms.Resize((48, 48)),
    transforms.ToTensor(),
    transforms.Normalize([0.5], [0.5]),
])

EMOTIONS = ["Angry", "Disgust", "Fear", "Happy", "Neutral", "Sad", "Surprise"]

# Inference
image = Image.open("face.jpg")
tensor = transform(image).unsqueeze(0)

with torch.no_grad():
    probs = F.softmax(model(tensor), dim=1)[0]

predicted = EMOTIONS[probs.argmax()]
confidence = probs.max().item()

print(f"Prediction: {predicted} ({confidence:.0%})")

πŸ—‚οΈ Training Data

  • Base dataset: FER-2013 (Facial Expression Recognition)
  • Input format: 48Γ—48 grayscale face images
  • Classes: 7 universal emotion categories

⚠️ Limitations

  • Optimized for frontal face images
  • Performance may degrade with partial occlusion, extreme lighting, or non-frontal poses
  • Not intended for surveillance or identity recognition β€” expression classification only

πŸ”— Related Resources


πŸ‘€ Author

Martin Badrous β€” Computer Vision & Deep Learning Engineer

LinkedIn GitHub HuggingFace

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support