π 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
- π€ Live Demo Space
- π» GitHub Repository
π€ Author
Martin Badrous β Computer Vision & Deep Learning Engineer