--- license: mit language: - en tags: - computer-vision - face-recognition - face-verification - facial-expression - image-classification - biometrics - deep-learning - pytorch - CNN pipeline_tag: image-classification --- # 🙂 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 ```python 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](https://huggingface.co/spaces/martinbadrous/Facial-Recognition-Verification) - 💻 [GitHub Repository](https://github.com/martinbadrous/Facial-Recognition) --- ## 👤 Author **Martin Badrous** — Computer Vision & Deep Learning Engineer [![LinkedIn](https://img.shields.io/badge/LinkedIn-%230077B5.svg?style=flat&logo=linkedin&logoColor=white)](https://www.linkedin.com/in/martinbadrous) [![GitHub](https://img.shields.io/badge/GitHub-181717.svg?style=flat&logo=github&logoColor=white)](https://github.com/martinbadrous) [![HuggingFace](https://img.shields.io/badge/HuggingFace-FFD21E.svg?style=flat&logo=huggingface&logoColor=000)](https://huggingface.co/martinbadrous)