Skip to content

This project implements a modified Decision Tree-based algorithm for facial expression recognition. Using a custom approach inspired by CART (Classification and Regression Trees), the system classifies facial images into different emotional categories (such as happy, sad, angry, etc.).

Notifications You must be signed in to change notification settings

Aditya10045/Modified-classification-and-regression-tree-for-facial-expression-recognition-

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

😊 Facial Expression Recognition with GUI

A Python project to detect facial emotions from images using a simple machine learning model (Decision Tree Classifier) and display results in a user-friendly Tkinter GUI.


📂 Project Overview

This project uses grayscale facial images to train a model that classifies them into one of the 7 basic human emotions:

  • 😠 Anger
  • 😒 Contempt
  • 🤢 Disgust
  • 😨 Fear
  • 😀 Happiness
  • 😢 Sadness
  • 😲 Surprise

It provides a GUI for uploading a facial image and viewing the predicted emotion.


📁 Dataset Structure

Place your emotion image folders in the ml project directory as follows:


ml project/
├── anger/
├── contempt/
├── disgust/
├── fear/
├── happiness/
├── sadness/
└── surprise/

Each folder should contain .jpg/.png/etc. images corresponding to that emotion.


🔧 Requirements

Install the following Python libraries:

pip install opencv-python scikit-learn numpy joblib Pillow

🚀 How to Run

  1. Ensure your dataset is placed in the proper folder structure.
  2. Run the Python script:
python main.py
  1. A GUI window will open. Click "Upload Image" to test an image from your system.

📌 Features

  • Decision Tree Classifier trained on 48x48 grayscale facial images

  • Preprocessing includes:

    • Grayscale conversion
    • Resizing
    • Flattening images for training
  • Uses Tkinter GUI for easy image upload and prediction

  • Automatically saves the trained model as emotion_model.pkl

  • Handles non-image and unreadable files gracefully


💻 GUI Preview

  • Upload any image containing a face
  • The GUI displays the image and the predicted emotion

GUI Screenshot Placeholder


📊 Model Evaluation

At the end of training, the console will display:

  • Accuracy Score
  • 📋 Classification Report

Example:

Accuracy: 0.81
Classification Report:
              precision    recall  f1-score   support
   happiness       0.89      0.85      0.87        52
       anger       0.78      0.82      0.80        50
      ...

🧠 Emotions Dictionary

emotions = {
    0: 'anger',
    1: 'contempt',
    2: 'disgust',
    3: 'fear',
    4: 'happiness',
    5: 'sadness',
    6: 'surprise'
}

🛠 Future Improvements

  • Upgrade model to Convolutional Neural Network (CNN) for better accuracy
  • Add webcam live detection
  • Include data augmentation
  • Save predictions or logs to a file

👤 Author

Aditya10045 Made with ❤️ and Python


📜 License

This project is open-source and free to use for educational or personal purposes.

About

This project implements a modified Decision Tree-based algorithm for facial expression recognition. Using a custom approach inspired by CART (Classification and Regression Trees), the system classifies facial images into different emotional categories (such as happy, sad, angry, etc.).

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages