Face Recognition System for provisioning AWS instance using Terraform scripts and generating Mail & WhatsApp alerts
Tags: aws, cnn, terraform, cv2
Published: 2021-06-24 09:52:47

In this article, We are going to know how to create a face recognition system by CV2 and use it for performing some automation tasks in **Real-time** such as Provisioning AWS instance and its dependencies such as VPC, Subnet, Security Groups, Route tables, Internet Gateway, and 5GB EBS Volume which is done by triggered Terraform scripts.

We are also going to know how to generate Whatsapp and Email **alerts** when our face is **recognized** using Python.

**Technologies used:** Python CV2 and Terraform

#Contents Overview:
- Model1
  - Data Collection
  - Model Training
  - Face Recognition
  - Running Terraform Scripts to provision AWS Instance

- Model2
  - Data Collection
  - Model Training
  - Face Recognition
  - Generating WhatsApp and Email Alerts

##Data Collection
First step of in Machine Learning world is always a Data Collection. Without data, nothing can be achieved. In this step, we are going to collect **100 samples** of my face with the size of **200 x 200 pixels** and stored in the folder named as Vishnu. 
![11](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3167d2nmd2ssl8kj9wwf.PNG)
 
This folder name is crucial because this folder name will be our **Object name/face name** for our model in future. So, give Human name to your folder.

Here, We are going to use haarcascade_frontalface_default.xml file as a  face detector.

##Model Training
In this phase, model is created using **LBPHFaceRecognizer** algorithm and the model is trained to recognize my face whenever my face appears in real time in video or appear in image.

Finally, the model is created and now the model has the capability to identify or recognize my face.

##Face Recognition
Final step is to do Face Recognition. Our desired output would be the model should recognize my face and display the confident score and say "Hi Vishnu" and ask to hit Enter to perform further operations.

![fr](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0h5ousvm1xmpdy5koj6z.PNG)
The above figure shows that our model predicted successfully and if we press enter, in the mean time, our Terraform scripts will automatically run and launch VPC, Subnet, Security Groups, Route tables, Internet Gateway, 5GB EBS Volume and finally provisioned AWS instance.
![2 success](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h6v12anmxhu0jwxrpgm0.PNG)
###EC2 Dashboard
![4](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fjnyosprmuj3sleuwfha.PNG)

###VPC Dashboard
![5](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eqqkb7yyzwlhzaxx6bga.PNG)
 
##Model2
Now, We are going to create another model for demonstrating automatic Email and WhatsApp alert messages when the face is detected and recognized. Here, we are going to use the face of Actor Vijay.

##Data Collection
Same Procedure. Samples are collecting and storing in another folder named "Vijay" for training the model.

![Capture](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mu9pnnnqizl607uv12kc.PNG)

##Model Training
Model is trained using **LBPH(Local Binary Pattern Histogram)** algorithm and used to trained the samples of Actor Vijay's face.

![v2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gn0ch1kuruh84h72vojw.PNG)

Above figure shows model is trained successfully and attain its capability of Face Recognition.

##Face Recognition
When the Vijay's face is recognized, it will give the confident score and will say "Hi Vijay" and asked to hit enter to perform further operations. When we hit enter, it will send Email and Whatsapp messages alert to the mentioned mail ID and WhatsApp number.

###WhatsApp Alert
![ww](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nj3v4ljjkvd2eg6yvtoa.PNG)

###Email Alert
![vv](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e4oc68gsh5nv2ewqzebj.PNG)

Output will be..

![ffffffffffffffffffff](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5r67s05j2dad784a368e.PNG)

Above figures shows that desired output was got and it shows our model was trained successfully and predicted correctly.

If you want to play, feel free to download the code in the GitHub by click [here](https://github.com/vishnuswmech/Face-Recognition-System-for-launching-AWS-instance-using-Terraform-and-generating-Mail-WhatsApp-al.git)

>That's it. Thank you for your reads. Stay tuned for my upcoming more interesting articles!!