Emotion Classification from Images: A Deep Learning Journey
Table of contents
Hello, hope you are doing well. In this article, I will be documenting my journey of make an amazing deep CNN classification project. The aim of the project is to classify the image's emotion (happy or sad) inputted via the interface. I will be covering each and every aspect of the project, from data collection and preprocessing to model architecture and building a full-fledged website, every step was a learning experience that ultimately led to success.
Here is the github link of the project => https://github.com/Rhythm1821/CNN-Image-Classification
Step 1: Data Acquisition and Organization
At the heart of any machine learning project lies the data. Our journey began with a meticulous search for happy and sad images, each meticulously curated and stored in separate zip files. These files were then conveniently hosted on a GitHub repository, ensuring accessibility and seamless collaboration.
Step 2: Data Preprocessing
Preparing the data was crucial to ensure accurate and effective model training. The process kicked off with the creation of Python scripts that extracted images from the zipped files. These scripts not only unzipped the files but also filtered out irrelevant files by checking for valid image extensions like '.jpeg', '.jpg', and '.png'. Additionally, images smaller than 10KB were removed to ensure data quality.
Step 3: Data Labeling and Scaling
The next step involved labelling the images. TensorFlow's image_dataset_from_directory
function was employed to conveniently label the data as per the directory structure. Once labelled, the data was scaled to fit a range between 0 and 1, ensuring uniformity and aiding model convergence. This scaling step was a crucial part of preparing the data for the neural network.
Step 4: Data Splitting
For effective model training and evaluation, the dataset was split into training, testing, and validation sets. This separation of data allowed for rigorous testing of the model's performance on unseen images. An essential aspect of any robust machine learning project is ensuring the model's generalization capabilities and this step achieved just that.
Step 5: Deep Learning Model Architecture
The core of the project was the development of a deep neural network model capable of recognizing emotional nuances in images. This architecture comprised Convolutional 2D (Conv2D) and MaxPooling2D layers for feature extraction, accompanied by Dense, Flatten, and Dropout layers for effective learning and generalization. The model employed Rectified Linear Unit (ReLU) activation functions, BinaryCrossEntropy loss function, and the Adam optimizer.
Step 6: Model Training and Optimization
Training the deep learning model was an exhilarating process. Over the course of 20 epochs, the model's accuracy soared and the loss was significantly reduced. The intricate interplay of the model architecture and optimizer parameters ensured that the model progressively learned to distinguish between happy and sad emotions with increasing accuracy.
Step 7: Performance Evaluation
The true test of any model's prowess lies in its performance on unseen data. In this case, the model underwent evaluation by predicting emotions from images not seen during training. The outcome was that the model accurately classified images as happy or sad, showcasing its ability to discern emotional appearance from visual data.
Step 8: Building a User-Friendly Website
Taking the project a step further, a user-friendly website was developed using HTML, CSS, JavaScript, and Bootstrap. The website provides users with the ability to upload an image. Upon clicking the predict button, the website interacts with a backend Flask server, which processes the image using the trained model and returns the emotion prediction. This interactive feature enhances the project's accessibility and allows users to experience the model in action.
Moving Forward
This project really helped me in gaining a lot of insightful aspects of deep learning and how do you handle unstructured data and train it on neural networks and many more things. This project enhanced my knowledge in the field of deep learning and helped me gain a good on the respective topic.
Looking forward to working on more exciting projects.
Thanks for reading the article :)