
Develop an end-to-end face recognition project using machine learning and OpenCV, train gender prediction, build a Flask web app, and deploy to the cloud.
The components that are used to develop the face recognition projects is Machine Learning, Python, OpenCV, Numpy, Pandas, Sklearn, Flask, HTML & CSS
Visit python.org and download the latest Windows release, such as Python 3.9.6. Run the installer as administrator, verify the setup, and test by typing Python in the command prompt.
Clone the face recognition template for the flask app using the provided code URL or by downloading the zip, and save the templates in your working folder.
Install and verify the necessary packages from the requirements file, then explore the foundations of Open CV in the next lesson; see you there and happy learning.
Discover how OpenCV, the open source computer vision library with 2500+ algorithms, provides a foundation for vision applications and covers image concepts like color channels, grayscale, and JPEG/PNG formats.
Load and extract pixels from an image using OpenCV, Pillow, and Matplotlib. OpenCV returns a numpy array, Pillow returns an image object, and Matplotlib is used to load the image.
Explore how images are stored as a pixel matrix with blue, green, and red channels in OpenCV's bgr order, and how matplotlib and Pillow read them into arrays.
Learn how to display images in OpenCV using cv2.imshow and compare BGR color order with RGB in matplotlib and pillow, highlighting color interchange and window handling.
Learn how to convert a color image to grayscale in OpenCV using cv2.cvtColor with color code cv2.COLOR_BGR2GRAY, then display and manage the grayscale image with imshow, waitKey, and destroyAllWindows.
Detect faces using OpenCV's cascade classifier by loading the frontal face xml, converting to grayscale, and applying detectMultiScale, then tune scale factor for better accuracy, drawing green bounding boxes.
Apply the phase detection algorithm to a video using OpenCV, capturing frames and displaying real-time face detection with a cascade classifier. Learn frame handling and escape-based playback control.
Build and train a face recognition model with OpenCV and image processing, then develop a Flask web app and deploy it to the cloud, focusing on gender detection.
In this course we are using IMDB Wiki data for developing Face recognition model. However it is highly recommended to download the given in the resources.
This lecture explains the training architecture for the face recognition model.
Data Gathering
Data Preprocessing
Train ML model
Create ML Pipeline
Perform data preprocessing by detecting faces with a Hardcastle classifier in OpenCV, crop the faces, and organize them into crop data/male and crop data/female folders for training.
Create a data folder under train/face recognition with ML, extract labeled images (female and male), activate the virtual environment, and launch Jupyter Notebook to begin data preprocessing.
Perform data preprocessing by cropping faces and storing them in directories after importing required libraries, including numpy, cv2, glob, and plotting tools.
Read images, convert to grayscale, apply the Haar cascade frontal face default classifier to detect faces, crop them, and save the preprocessed face images.
Crop the region of interest from the image using y and x ranges, display the cropped face, and save it with cv2.imwrite for future batch processing.
Crop all faces from images using a hardcastle classifier, convert to gray scale, crop regions of interest, and save female and mail crops into separate crop_data folders with dynamic names.
Identify unstructured image data with varying dimensions in male and female folders, then structure it by resizing all images to a common width and height after exploratory data analysis.
Perform exploratory data analysis to determine image width and height, structure data by gender, and prepare a resized, cleaned dataset using seaborn charts and pandas.
Perform exploratory data analysis of gender and image size distributions using bar, pie, box, and histogram plots. Propose resizing to 100 by 100 to balance data for preprocessing.
Filter images with dimensions at least 60, convert to grayscale, resize to 100 by 100 (area for shrinking, cubic for enlarging), and flatten to a 1 by 10000 vector.
Structure all images by flattening 100x100 pixels into 10,000 columns, normalize by 255, add gender as a label, remove missing values, and save the prepared data with pickle.
Extract features for face recognition using the eigen phase approach, applying normalization, mean subtraction, and the principle common analysis to generate eigen phase representations.
Compute the eigen phase from normalized face data with PCA, subtract the mean face, and apply the elbow method to select PCA components for a face recognition model.
Visualize explained variance and cumulative variance from PCA to determine the optimal number of components, using an elbow plot to select around 50 components for 80% explained variance.
Train a PCA with 50 components on 4390 images, save the PCA data and mean phase for future prediction and for the web application.
Train a face recognition model using a support vector machine, with grid search cross-validation for hyperparameter tuning, and save results after data preprocessing and feature extraction.
Train a face recognition model using a support vector machine, tune hyperparameters via grid search (C, kernel, gamma, coefficient), enable probability estimates, and fit on x_train/y_train with 3-fold cross-validation.
Use grid search with cross-validation to identify the best parameters, yielding C=20 and gamma=0.02 with an RB kernel and a final model. Note that random state may produce different parameters.
Save the face recognition model by serializing model_final with pickle as model_svm.pkl in the models folder, then prepare to build the model pipeline with data preprocessing and principal analysis.
Navigate the 11-step face recognition pipeline from reading images with OpenCV and grayscale conversion to cropping faces with a cascade classifier, normalization, resizing, and SVM prediction, ending with a report.
Normalize images to 0–1, resize to 100 by 100 with inter_area or cubic, subtract mean, apply PCA to 50 components, and classify with an SVM to predict male or female.
Build a face recognition pipeline that generates and visualizes predictions by drawing colored bounding boxes, overlaying gender and probability scores, and saving the annotated images.
Explore how to run final predictions for a face recognition model using OpenCV and the face recognition pipeline, test with images and a video, and visualize the results.
Execute a real-time face and gender recognition pipeline by capturing video from a webcam, processing frames, producing predictions, and displaying results before exiting with q.
Install Visual Studio Code on Windows 10 64-bit from official site, run the installer with add to path, then open and start using Visual Studio Code for the course projects.
Create a cloud-ready Flask app folder structure with templates, static, model, and app folders, plus requirement.txt, proc file, and app files for deployment.
Create the base.html for a flask face recognition web app, establishing a navigation bar and shared templates across the home, app, and gender pages using render_template and bootstrap.
Build a reusable base.html with a Bootstrap navigation bar, integrate a logo and static assets, and apply Flask template inheritance with a body block for pages.
Create an app page in Flask by building app.html, linking it to the route, and displaying a description with an image and a navigation button.
Build and connect a gender app page in a Flask app that allows image upload, passes it to a machine learning model for gender prediction, and displays predictions and reporting.
Set up a gender app backend by handling post requests, saving uploaded images to an upload folder, running a face recognition pipeline, and saving and displaying predictions.
Generate and report gender predictions from uploaded images by extracting grayscale and inverted images, formatting probabilities, saving report images with Matplotlib, and displaying results in a Flask app.
Develop and deploy a face recognition workflow by training a machine learning model, performing detection and gender prediction on images, and presenting results in a Flask web app.
Publish your Flask face recognition app to the cloud by pushing files to GitHub and linking GitHub with Heroku for deployment, while noting Git requirements on Mac, Linux, and Windows.
Install git on Windows by downloading the installer, running as administrator, and completing the on-screen prompts to finish; Mac and Linux typically have git pre-installed.
Learn to deploy a Flask app for face recognition, including creating backups, configuring a virtual environment, generating requirements.txt, and setting up a Procfile and app dependencies for cloud deployment.
Create a public GitHub repository, configure git, initialize the local repo, add and commit files, set the main branch, connect the remote origin, and push the code to GitHub.
Deploy a Flask app to the cloud with Heroku, connect to GitHub, and deploy from the main branch, then test image predictions in the hosted face recognition app.
Learn to reflect code changes in your Heroku deployed face recognition app by updating the web page, committing to GitHub, and deploying a release branch.
Deploy a face recognition flask app to Railway.app, a free open source cloud platform, by linking your GitHub repo and deploying from GitHub, then test predictions with a sample image.
Deploy your face recognition app with a custom domain on railway app, configure environment settings, monitor memory usage and usage details from the dashboard.
Explore Python essentials for project work, including data structures and conditionals, importing the built-in library, checking Python version, and mastering print statements, keywords, and custom separators and end parameters.
Master Python print statements using escape sequences like backslash, newline, and tab. Use %s, %d, %f and format to insert strings, integers, and floats.
Define variables and use assignment to bind values. Demonstrate assigning multiple variables to multiple values and check data types, with A = 2 and X, Y = 1, 2.
Explore Python data types such as integers, floats, strings, booleans, and none, and learn how null values are represented.
Explore common list methods in Python, including append, extend, count, insert, pop, remove, and reverse, and learn how nested lists and element positions affect list structure and behavior.
Explore tuples in Python: their immutability, how to define and index them, perform slicing and negative indexing, use count and index, concatenate, and cast between tuple and list.
Explore the set data structure, create sets with curly braces, and handle multiple data types while no duplicates exist; perform intersection, union, and subtraction to compare and combine sets.
Explore the in operator as a membership test for lists and strings, returning true or false to indicate presence and enabling conditional statements.
Master the plus operator to concatenate lists, tuples, and strings, and use the star operator to repeat elements in Python, with practical list and string examples.
Learn how to create user defined functions using def, name, and arguments, return values, and indentation, then call them to perform operations like addition and checking even or odd numbers.
Explore range, enumerate, and zip as operators for for loops, showing how range uses start, stop, and step to generate values and how enumerate and zip provide indexing and merging.
Master for loops with range to generate 0 to 9 and iterate lists, printing elements and indices. Use enumerate to access indices and embed if else inside loops.
Learn url building in Flask using variable rules and converters, integer, float, and path, and build a simple app that demonstrates dynamic routes, blog ids, and weight parameters.
Learn to integrate Flask with HTML using Jinja templates, create views and routes, and render index.html from a templates folder.
Explore for loops in Jinja2 templates within a Flask app, render a dynamic table from a data dictionary, and use if/else to display pass or fail with color.
Learn to manage static CSS and JavaScript in a Flask app by creating static/css and static/js folders, linking files with url_for, and applying styles to HTML.
Set up a Flask app with templates and a static/uploads folder, implement a multipart file upload form, save the file, and display the uploaded image from static/uploads.
MLOPs: AI based Face Recognition Web App in Flask & Deploy
Face recognition is one of the most widely used in my application. If at all you want to develop and deploy the application on the web only knowledge of machine learning or deep learning is not enough. You also need to know the creation of pipeline architecture and call it from the client-side, HTTP request, and many more. While doing so you might face many challenges while developing the app. This course is structured in such a way that you can able to develop the face recognition based web app from scratch.
What you will learn?
Python
Image Processing with OpenCV
Image Data Preprocessing
Image Data Analysis
Eigenfaces with PCA
Face Recognition Classification Model with Support Vector Machines
Pipeline Model
Flask (Jinja Template, HTML, CSS, HTTP Methods)
Develop Face Recognition Web
Deploy Flask App in Cloud (Heroku)
You will learn image processing techniques in OpenCV and the concepts behind the images. We will also do the necessary image analysis and required preprocessing steps for images.
For the preprocess images, we will extract features from the images, ie. computing Eigen images using principal component analysis. With Eigen images, we will train the Machine learning model and also learn to test our model before deploying, to get the best results from the model we will tune with the Grid search method for the best hyperparameters.
Once our machine learning model is ready, will we learn and develop a web server gateway interphase in flask by rendering HTML CSS and bootstrap in the frontend and in the backend written in Python. Finally, we will create the project on the Face Recognition project by integrating the machine learning model to Flask App.