{"id":25534621,"url":"https://github.com/aksweb/emotiondetection","last_synced_at":"2026-01-26T09:30:17.563Z","repository":{"id":147721812,"uuid":"528910468","full_name":"aksweb/emotionDetection","owner":"aksweb","description":"Detecting real time emotion using CNN with KDD Analysis","archived":false,"fork":false,"pushed_at":"2024-04-29T15:02:31.000Z","size":16013,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-04-29T16:27:26.155Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/aksweb.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":"2022-08-25T15:27:40.000Z","updated_at":"2024-04-29T16:27:28.061Z","dependencies_parsed_at":"2023-04-03T14:48:50.801Z","dependency_job_id":null,"html_url":"https://github.com/aksweb/emotionDetection","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aksweb%2FemotionDetection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aksweb%2FemotionDetection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aksweb%2FemotionDetection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aksweb%2FemotionDetection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aksweb","download_url":"https://codeload.github.com/aksweb/emotionDetection/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239768925,"owners_count":19693764,"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":[],"created_at":"2025-02-20T03:20:10.660Z","updated_at":"2026-01-26T09:30:15.600Z","avatar_url":"https://github.com/aksweb.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Data Mining Project: \u003cbr\u003e\n# Emotion Detection in Real-Time Video (With KDD analysis)\n\n## Overview\nThis project focuses on detecting emotions in real-time video streams using deep learning techniques. The model is trained on facial expression data to predict emotions in live video feeds.\n\n## Knowing the Data\n- The dataset comprises images of facial expressions categorized into seven emotions: angry, disgust, fear, happy, neutral, sad, and surprise.\n- Data is split into two sections: train and validation, each containing subfolders for different emotions.\n- The objective is to classify facial expressions into predefined emotion categories.\u003cbr\u003e\n#### **KDD**\n- **Objective**: Gain insights into the dataset and understand its structure, features, and distribution.\n- **Actions**:\n  - Explore the dataset to understand the distribution of facial expressions.\n  - Analyze the characteristics of images in the dataset, such as resolution and quality.\n  - Identify any missing or erroneous data that may require preprocessing.\n\n## Data Preprocessing\n- Data preprocessing involves several steps to prepare the dataset for model training:\n  1. **Loading Images**: Images are loaded using the `load_img` function from the Keras library.\n  2. **img_to_array**: This function converts a PIL image object into a NumPy array. It is used to convert the loaded images into arrays for further processing.\n  3. **ImageDataGenerator**: This class generates batches of tensor image data with real-time data augmentation. It is used to perform data augmentation on the image data during training.\n  4. **Data Splitting**: The dataset is split into training and validation sets for model evaluation.\u003cbr\u003e\n#### **KDD**\n- **Objective**: Preprocess the dataset to ensure it is suitable for model training.\n- **Actions**:\n  - Load the image data and convert it into a format compatible with the chosen deep learning framework.\n  - Perform data augmentation techniques to increase the diversity of the training data and improve the model's generalization.\n  - Split the dataset into training and validation sets to evaluate the model's performance.\n  \n## Dataset Details\n- The dataset is organized into two main folders: train and validation.\n- Each folder contains subfolders corresponding to different emotion categories.\n- Images in each subfolder represent facial expressions of the respective emotion category.\n\n## Model Building\n- The model architecture consists of a convolutional neural network (CNN) designed to classify facial expressions.\n- Various CNN layers, including convolutional, pooling, and fully connected layers, are utilized to learn and extract features from facial images.\n- The model is trained using the Adam optimizer with a learning rate of 0.001 over 48 epochs.\u003cbr\u003e\n#### **KDD**\n- **Objective**: Developed a deep learning model to classify facial expressions in real-time video streams.\n- **Actions**:\n  - Designed a convolutional neural network (CNN) architecture suitable for image classification tasks.\n  - Experiment with different CNN architectures, activation functions, and optimization algorithms to optimize model performance.\n  - Train the model using the prepared dataset and evaluate its performance on the validation set.\n\n## Function Explanation:\n1. **load_img**: This function loads an image file and returns it as a PIL (Python Imaging Library) image object. It is used to load images from the dataset.\n2. **img_to_array**: This function converts a PIL image object into a NumPy array. It is used to convert the loaded images into arrays for further processing.\n3. **ImageDataGenerator**: This class generates batches of tensor image data with real-time data augmentation. It is used to perform data augmentation on the image data during training.\n4. **Sequential**: This class allows you to build a sequential model layer-by-layer. It is used to create a sequential model for the CNN.\n5. **Conv2D**: This class creates a convolutional layer for 2D spatial convolution. It applies a specified number of filters to the input data.\n6. **BatchNormalization**: This layer normalizes the activations of the previous layer at each batch. It helps in stabilizing and accelerating the training process.\n7. **Activation**: This layer applies an activation function to the output of the previous layer. Common activation functions include 'relu' (Rectified Linear Unit) and 'softmax'.\n8. **MaxPooling2D**: This layer performs max pooling operation for spatial data. It reduces the spatial dimensions of the input volume.\n9. **Dropout**: This layer applies dropout regularization to the input. It randomly sets a fraction of input units to zero during training to prevent overfitting.\n10. **Dense**: This layer implements the operation: output = activation(dot(input, kernel) + bias). It is the standard fully connected layer.\n11. **Model**: This class groups layers into an object with training and inference features. It is used to define the model architecture and compile it for training.\n12. **Adam**: This optimizer is an extension to stochastic gradient descent. It computes adaptive learning rates for each parameter.\n13. **ModelCheckpoint**: This callback saves the model after every epoch if the validation accuracy improves.\n14. **EarlyStopping**: This callback stops training when a monitored metric has stopped improving.\n15. **ReduceLROnPlateau**: This callback reduces the learning rate when a metric has stopped improving.\n\n## Working of the Code:\n1. The code starts by importing necessary libraries and setting parameters such as image size, folder path, and target emotions.\n2. It loads images from the specified folder path using `load_img` and `img_to_array`.\n3. The dataset is split into training and validation sets using `ImageDataGenerator` and `flow_from_directory`.\n4. A CNN model architecture is defined using `Sequential` and various layers such as `Conv2D`, `BatchNormalization`, `Activation`, etc.\n5. The model is compiled with the Adam optimizer and categorical cross-entropy loss function.\n6. Callbacks such as `ModelCheckpoint`, `EarlyStopping`, and `ReduceLROnPlateau` are defined to monitor the training process.\n7. The model is trained using the `fit_generator` function, which iterates over the training set for a specified number of epochs.\n8. Training and validation loss/accuracy curves are plotted using `matplotlib`.\n\nThis code serves as a foundation for building an emotion detection model and can be further extended and optimized for improved performance.\n\n\n## Performance Metrics\n- Training and validation loss/accuracy curves are plotted to evaluate the model's performance.\n- The model achieves a test accuracy of 65%, significantly outperforming random guessing.\n\n## Predictive Modeling\n- A predictive model is built to classify emotions in real-time video streams.\n- Key variables such as facial features, expressions, and historical data are considered in predicting emotions.\n- Various classifiers including Logistic Regression, Support Vector Machines, Decision Tree, etc., are tested to determine the best-performing model.\n\n## Results\n- The final model achieves a test accuracy of 65%, demonstrating its effectiveness in real-time emotion detection.\n- The model's performance is compared to a baseline predictor, showing a significant improvement in accuracy.\u003cbr\u003e\n#### **KDD**\n- **Objective**: Assess the performance of the trained model and identify areas for improvement.\n- **Actions**:\n  - Evaluate the model's accuracy, precision, recall, and F1-score on the validation set.\n  - Use techniques such as confusion matrices and ROC curves to analyze the model's performance across different emotion categories.\n  - Identify any misclassifications or patterns in the model's predictions and refine the model accordingly.\n    \n## Future Work\n- Implement real-time video processing optimizations for faster inference.\n- Extend the model to detect and classify complex emotional states in diverse scenarios.\n\n## Procedure to run:\n1.Libraries Required:\u003cbr\u003e\n    Keras \u003cbr\u003e\n    tenserflow\u003cbr\u003e\n    pandas\u003cbr\u003e\n    scikit-learn\u003cbr\u003e\n    numpy\u003cbr\u003e\n    matplotlib\u003cbr\u003e\n2.Open main.py file.\u003cbr\u003e\n\nData Set Link - https://www.kaggle.com/jonathanoheix/face-expression-recognition-dataset\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faksweb%2Femotiondetection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faksweb%2Femotiondetection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faksweb%2Femotiondetection/lists"}