Reference : @codebasics
This project is my first step into image prediction, inspired by a celebrity face recognition project by @codebasics. It encompasses model building, server development, and user interface (UI) development.
I'm excited to showcase my image classification project, influenced by a celebrity face recognition project. It aided me in recalling all the project components, such as the server, model, and UI. This project marks the beginning of my data science journey, and I'm eager to see where it takes me next.
The dataset consists of images of my favorite role models:
- Kalpana Chawla
- Micheal Obama
- Nita Ambani
- Oprah Winfrey
- Priyanka Chopra
Source: Google Images (webscraping with the help of fatkun-batch).
- The notebook contains the model for predicting the faces of my favorite role models.
- Images are preprocessed by converting to grayscale and detecting faces and eyes using cascade classifiers.
- Images are cropped and saved in a dataset folder.
- Wavelet transformation is applied to images, and raw and wavelet images are combined for training.
- Support Vector Machine (SVM) is used for training with grid searching, achieving 98% accuracy.
- The trained model is saved as a pickle file.
- Flask-based server for running the project.
- Flask provides tools and features for creating web applications in Python.
- Contains common code blocks for classifying images and loading artifacts.
- Class for converting raw images into wavelets.
- Pretrained models for face and eye detection using Haar cascades.
- Contains pickle file and class dictionary.
- Stylesheet for webpage elements.
- Defines visual presentation of HTML document.
- HTML document structure for the webpage.
- Defines the structure and layout of webpage content.
- JavaScript code for interactivity and convenience.
- Adds dynamic behavior to HTML elements based on user actions.
- Launch an EC2 instance with Ubuntu OS
- Configure security groups to allow inbound traffic on ports 22 (SSH) and 80 (HTTP)
- SSH into the EC2 instance
- Install Python, pip, and required dependencies for the image prediction application
- Install Nginx on the EC2 instance if not already installed
- Configure Nginx as a reverse proxy to forward HTTP requests to the Flask application running on a specific port (e.g., 5000)
-
Install Nginx if not already installed:
sudo apt update sudo apt install nginx
-
Create a configuration file for the image prediction application:
sudo nano /etc/nginx/sites-available/imgpred.conf
-
Add the following configuration to the
imgpred.conf
file:server { listen 80; server_name imgpred.com; root /home/ubuntu/ImagePrediction/UI/; index app.html; location /api/ { rewrite ^/api(.*) $1 break; proxy_pass http://127.0.0.1:5000; } }
-
Save and close the file.
-
Create a symbolic link to enable the site:
sudo ln -s /etc/nginx/sites-available/imgpred.conf /etc/nginx/sites-enabled/
-
Test the Nginx configuration for syntax errors:
sudo nginx -t
-
If the syntax is OK, reload Nginx to apply the changes:
sudo systemctl reload nginx
- Verify that Nginx is running and listening on port 80:
sudo systemctl status nginx
- Access the domain name or public IP of your EC2 instance in a web browser to confirm that the reverse proxy is correctly forwarding requests to the Flask application.
unlink the default file in etc/nginx/sites-enabled and symlink with ingpred.conf
- Transfer the Flask application code and the trained model to the EC2 instance using WinSCP
- Run the Flask application using Gunicorn or any other WSGI server
- Access the EC2 instance's public IP or domain name in a web browser
- Upload an image to the deployed application and verify the prediction results