{"id":19858026,"url":"https://github.com/ajay-308/facial_expression_recognition","last_synced_at":"2026-01-11T01:15:17.803Z","repository":{"id":188520996,"uuid":"675679835","full_name":"Ajay-308/Facial_Expression_Recognition","owner":"Ajay-308","description":null,"archived":false,"fork":false,"pushed_at":"2023-11-29T15:48:41.000Z","size":46998,"stargazers_count":1,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-11-12T14:22:27.255Z","etag":null,"topics":["deep-learning","emotion","emotion-recognition","face-detection","face-recognition","machine-learning","opencv"],"latest_commit_sha":null,"homepage":"https://face-rgh6.onrender.com/","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Ajay-308.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-08-07T13:27:35.000Z","updated_at":"2024-02-29T17:09:01.000Z","dependencies_parsed_at":"2023-11-29T16:54:01.204Z","dependency_job_id":null,"html_url":"https://github.com/Ajay-308/Facial_Expression_Recognition","commit_stats":null,"previous_names":["ajay-308/facial_expression_recognition"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ajay-308%2FFacial_Expression_Recognition","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ajay-308%2FFacial_Expression_Recognition/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ajay-308%2FFacial_Expression_Recognition/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ajay-308%2FFacial_Expression_Recognition/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Ajay-308","download_url":"https://codeload.github.com/Ajay-308/Facial_Expression_Recognition/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233490497,"owners_count":18684029,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deep-learning","emotion","emotion-recognition","face-detection","face-recognition","machine-learning","opencv"],"created_at":"2024-11-12T14:20:50.670Z","updated_at":"2025-09-18T14:32:14.352Z","avatar_url":"https://github.com/Ajay-308.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🎭 Facial Emotion Recognition with Deep Learning\n\n\u003cdiv align=\"center\"\u003e\n\n![Emotion Recognition](https://images.pexels.com/photos/3184419/pexels-photo-3184419.jpeg?auto=compress\u0026cs=tinysrgb\u0026w=800\u0026h=400\u0026fit=crop)\n\n[![Python](https://img.shields.io/badge/Python-3.8+-blue.svg)](https://python.org)\n[![TensorFlow](https://img.shields.io/badge/TensorFlow-2.0+-orange.svg)](https://tensorflow.org)\n[![Keras](https://img.shields.io/badge/Keras-2.0+-red.svg)](https://keras.io)\n[![License](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)\n\n*A deep learning solution for real-time facial emotion detection using Convolutional Neural Networks*\n\n\u003c/div\u003e\n\n## 📋 Table of Contents\n\n- [Overview](#-overview)\n- [Features](#-features)\n- [Architecture](#-architecture)\n- [Performance](#-performance)\n- [Installation](#-installation)\n- [Usage](#-usage)\n- [Dataset](#-dataset)\n- [Results](#-results)\n- [Future Improvements](#-future-improvements)\n- [Contributing](#-contributing)\n- [License](#-license)\n\n## 🎯 Overview\n\nThis project implements a sophisticated **Convolutional Neural Network (CNN)** for facial emotion recognition, capable of classifying human emotions from facial expressions into 7 distinct categories. The model achieved **81.4% training accuracy** and **62.7% validation accuracy** after 70 epochs of training on FER2013-style dataset.\n\n### Supported Emotions\n- 😠 **Angry**\n- 🤢 **Disgust** \n- 😨 **Fear**\n- 😊 **Happy**\n- 😐 **Neutral**\n- 😢 **Sad**\n- 😲 **Surprise**\n\n## ✨ Features\n\n- **Deep CNN Architecture**: 4-layer convolutional network with advanced regularization\n- **Real-time Prediction**: Fast inference for live emotion detection\n- **Robust Preprocessing**: Automated image normalization and augmentation\n- **Model Persistence**: Save/load functionality for trained models\n- **Comprehensive Evaluation**: Confusion matrix and performance visualization\n- **Production Ready**: Modular code structure for easy deployment\n\n## 🏗️ Architecture\n\n### Model Structure\n```\nInput (48x48 Grayscale) \n    ↓\nConv2D (128 filters) + LeakyReLU + MaxPool + Dropout\n    ↓\nConv2D (256 filters) + LeakyReLU + MaxPool + Dropout\n    ↓\nConv2D (512 filters) + LeakyReLU + MaxPool + Dropout\n    ↓\nConv2D (512 filters) + LeakyReLU + MaxPool + Dropout\n    ↓\nFlatten + Dense (512) + LeakyReLU + Dropout\n    ↓\nDense (256) + LeakyReLU + Dropout\n    ↓\nDense (7) + Softmax → Emotion Classification\n```\n\n### Key Components\n- **Activation**: LeakyReLU for better gradient flow\n- **Regularization**: Dropout layers to prevent overfitting\n- **Pooling**: MaxPooling2D for spatial dimension reduction\n- **Optimizer**: Adam with categorical crossentropy loss\n\n## 📊 Performance\n\n### Training Metrics\n| Metric | Training | Validation |\n|--------|----------|------------|\n| **Accuracy** | 81.4% | 62.7% |\n| **Loss** | 0.52 | 1.17 |\n| **Epochs** | 70 | 70 |\n\n### Training Characteristics\n- **Dataset Size**: ~28,000 training images, ~7,000 validation images\n- **Batch Size**: 128\n- **Convergence**: Optimal performance around epoch 45\n- **Overfitting**: Observed after epoch 45 (validation plateau)\n\n## 🚀 Installation\n\n### Prerequisites\n```bash\nPython 3.8+\npip package manager\n```\n\n### Setup\n```bash\n# Clone the repository\ngit clone https://github.com/yourusername/facial-emotion-recognition.git\ncd facial-emotion-recognition\n\n# Install dependencies\npip install tensorflow keras opencv-python numpy pandas matplotlib seaborn scikit-learn\n\n# Or use requirements.txt\npip install -r requirements.txt\n```\n\n## 💻 Usage\n\n### Training the Model\n```python\nfrom emotion_recognition import EmotionRecognizer\n\n# Initialize the model\nmodel = EmotionRecognizer()\n\n# Train on your dataset\nmodel.train(train_path='data/train', \n           validation_path='data/validation',\n           epochs=70, \n           batch_size=128)\n\n# Save the trained model\nmodel.save('emotion_model.h5')\n```\n\n### Making Predictions\n```python\n# Load pre-trained model\nmodel = EmotionRecognizer.load('emotion_model.h5')\n\n# Predict emotion from image\nemotion = model.predict('path/to/image.jpg')\nprint(f\"Detected emotion: {emotion}\")\n\n# Real-time prediction\nmodel.predict_realtime()\n```\n\n### Evaluation\n```python\n# Generate confusion matrix\nmodel.evaluate(test_path='data/test')\n\n# Plot training history\nmodel.plot_training_history()\n```\n\n## 📁 Dataset\n\nThe model is trained on a FER2013-style dataset with the following structure:\n\n```\ndata/\n├── train/\n│   ├── angry/\n│   ├── disgust/\n│   ├── fear/\n│   ├── happy/\n│   ├── neutral/\n│   ├── sad/\n│   └── surprise/\n└── validation/\n    ├── angry/\n    ├── disgust/\n    ├── fear/\n    ├── happy/\n    ├── neutral/\n    ├── sad/\n    └── surprise/\n```\n\n**Image Specifications:**\n- **Format**: Grayscale (48x48 pixels)\n- **Normalization**: Pixel values scaled to [0, 1]\n- **Augmentation**: Random rotations, shifts, and flips\n\n## 📈 Results\n\n### Training Progress\nThe model shows strong learning capability with steady improvement in training metrics. However, validation performance plateaus after epoch 45, indicating overfitting.\n\n### Performance Analysis\n- **Strong Training Fit**: 81.4% accuracy demonstrates good model capacity\n- **Moderate Generalization**: 62.7% validation accuracy shows room for improvement\n- **Overfitting Detected**: Divergence between training and validation metrics\n\n### Recommendations for Improvement\n1. **Early Stopping**: Halt training at epoch 45\n2. **Data Augmentation**: Increase variety in training data\n3. **Regularization**: Stronger dropout or L2 regularization\n4. **Model Architecture**: Experiment with lighter architectures\n\n## 🔮 Future Improvements\n\n### Short Term\n- [ ] Implement early stopping mechanism\n- [ ] Add data augmentation pipeline\n- [ ] Create real-time webcam integration\n- [ ] Develop REST API for deployment\n\n### Long Term\n- [ ] Experiment with transfer learning (VGG, ResNet)\n- [ ] Multi-face detection and emotion recognition\n- [ ] Mobile optimization with TensorFlow Lite\n- [ ] Integration with cloud services (AWS, GCP)\n\n### Research Directions\n- [ ] Attention mechanisms for better feature focus\n- [ ] Multi-modal emotion recognition (audio + visual)\n- [ ] Federated learning for privacy-preserving training\n- [ ] Emotion intensity prediction (not just classification)\n\n## 🤝 Contributing\n\nWe welcome contributions! Here's how you can help:\n\n1. **Fork** the repository\n2. **Create** a feature branch (`git checkout -b feature/AmazingFeature`)\n3. **Commit** your changes (`git commit -m 'Add some AmazingFeature'`)\n4. **Push** to the branch (`git push origin feature/AmazingFeature`)\n5. **Open** a Pull Request\n\n### Areas for Contribution\n- Model architecture improvements\n- Data preprocessing enhancements\n- Performance optimization\n- Documentation improvements\n- Bug fixes and testing\n\n## 📜 License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n---\n\n\u003cdiv align=\"center\"\u003e\n\n### 🌟 If you found this project helpful, please give it a star!\n\n**Made with ❤️ for the AI community**\n\n[⬆ Back to Top](#-facial-emotion-recognition-with-deep-learning)\n\n\u003c/div\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fajay-308%2Ffacial_expression_recognition","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fajay-308%2Ffacial_expression_recognition","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fajay-308%2Ffacial_expression_recognition/lists"}