Artificial Intelligence: Face Recognition with Machine Learning | Srikanth Guskra | Skillshare

Playback Speed


  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Artificial Intelligence: Face Recognition with Machine Learning

teacher avatar Srikanth Guskra, Data Scientist

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

83 Lessons (6h 60m)
    • 1. Introduction

      5:34
    • 2. Install Python

      1:04
    • 3. Install Required Packages

      1:36
    • 4. Install Dlib and Cmake

      2:49
    • 5. Project Phase 0, Image Processing with OpenCV

      4:51
    • 6. Load Image

      9:12
    • 7. Display Image

      7:42
    • 8. Save Image

      1:49
    • 9. Acessing Pixels

      5:47
    • 10. Manipulate Pixels

      2:26
    • 11. Color Space - Split BGR

      6:23
    • 12. Color Space - Convert Colors

      10:00
    • 13. Drawings - Line

      5:58
    • 14. Drawings - Line part2

      2:26
    • 15. Drawings - Rectangle

      5:23
    • 16. Drawings - Polygon

      5:43
    • 17. Drawings - Circles

      5:30
    • 18. 12 put text

      2:41
    • 19. Object Detection with OpenCV What you will Learn ?

      0:46
    • 20. Viola-Jones Object Detection Intuition

      2:39
    • 21. Download Cascade Classifier

      3:02
    • 22. Face Detection with Cascade Classifier

      12:15
    • 23. Multiple Faces Detection

      6:56
    • 24. Eyes Detection

      8:21
    • 25. Smile Detection

      5:22
    • 26. Face Detection & Feature Extraction using DNN OpenCV What you will Learn ?

      0:59
    • 27. Face Detection with Deep Neural Network Framework

      2:12
    • 28. Face Detection with DNN part-1

      6:17
    • 29. Face Detection with DNN part -2

      1:33
    • 30. Face Detection with DNN part-3

      9:39
    • 31. Feature Extraction Framework

      1:55
    • 32. Facial Feature Extraction: part-1

      7:20
    • 33. Facial Feature Extraction: part-2 (Landmark Detection)

      3:40
    • 34. Facial Feature Extraction: part-3 (Face Descriptors)

      1:44
    • 35. Project Phase-1, Face Recognition Framework

      3:51
    • 36. Data Preprocessing

      4:15
    • 37. Data Preprocessing - face detection

      8:47
    • 38. Data Preprocessing - feature extraction

      2:44
    • 39. Data Preprocessing - Helper Function

      1:58
    • 40. Data Preprocessing - Feature Embedding and Labeling

      4:53
    • 41. Save data

      2:15
    • 42. Machine Learning - Data

      6:20
    • 43. Machine Learning and Evaluation - Logistic Regression, Accuracy and F1score

      10:05
    • 44. Machine Learning & Evaluation - Support Vector Classifier, Accuracy and F1score

      2:37
    • 45. Machine Learning & Evaluation - Random Forest, Accuracy and F1score

      2:56
    • 46. Machine Learning & Evaluation - Voting Classifier

      4:23
    • 47. Grid Search Parameter Tuning

      9:50
    • 48. Save Face Recognition Model in Pickle

      3:52
    • 49. Facial Emotion Recognition Get the Data

      3:05
    • 50. Data Preprocessing

      5:51
    • 51. Train Machine Learning Model

      6:08
    • 52. Load all Face Recognition and Detection Machine Learning Models

      5:08
    • 53. Automatic Multiple Faces Detections

      7:27
    • 54. Combine Predictions of all Machine Learning Models

      10:50
    • 55. Create Function for Entire Code

      5:25
    • 56. Phase-2: Setting Up Web App Project Django Web App

      1:12
    • 57. Install Visual Studio Code

      2:33
    • 58. Setting Up Visual Studio Code

      3:44
    • 59. Create Virtual Environment from Visual Studio Code (Windows)

      4:17
    • 60. Install & Freeze Requirements

      2:30
    • 61. Django Basics - Your First Django App

      3:44
    • 62. Django Overview

      5:31
    • 63. HttpRespones in Django

      4:31
    • 64. Django Templates

      7:55
    • 65. Static Files

      5:36
    • 66. Face Recognition Webapp with Django Model Views Templates + Machine Learning Framework

      2:17
    • 67. Upload Images into Models - part-1

      13:57
    • 68. Connect Models, Views, Template part-2

      8:51
    • 69. Connect Models, Views, Template part-3

      3:04
    • 70. Import Machine Learning Models in Django App

      12:43
    • 71. Get Face Recognition Predictions from Machine Learning in Django

      6:46
    • 72. Display Face Recognition Output in Django Templates

      7:32
    • 73. Display Face Recognition Output in Django Templates part-2

      8:39
    • 74. Styling Django WebApp with Bootstrap (CSS)

      4:41
    • 75. Styling Django Web App with Bootstrap part2

      5:51
    • 76. Styling Django Web App with Bootstrap part3

      7:14
    • 77. Project Phase-3: Deploy Face Recognition Web App in Heroku

      0:54
    • 78. Create Heroku Account

      2:13
    • 79. Install GIT

      1:30
    • 80. Install Heroku CLI

      2:12
    • 81. Deploy Django in Heroku - part1

      4:43
    • 82. Deploy Django in Heroku - part2

      4:34
    • 83. Solution for missing Static in Heroku- collectstatic

      6:05
  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.

60

Students

--

Projects

About This Class

Curious about Artificial Intelligence? Start here with Machine Learning — what it is, what it isn't, and how we all interact with it every day.

Join principal data engineer and keynote speaker Srikanth for a fascinating class all about Machine Learning and deploy models into production with Face Recognition Project. From how we all use it to where it's headed in the future, you'll learn the ins and outs of how machines are processing our data, finding patterns, and making our lives easier every day. With a focus on how machine learning can power human interfaces and ease our interactions with technology, lessons are packed with tools and tips for developers, designers, and the curious-minded. Key lessons include:

  • OpenCV for Image Processing
  • Train Machine Learning and create data pipeline model
  • Tools to incorporate machine learning into your products
  • Create Django API for face recognition project
  • Deploy machine learning model into cloud 

Whether you're a developer looking to incorporate machine learning into your work or are just curious about artificial intelligence today, this class is a behind-the-scenes glimpse into the world of cutting edge technology.

After taking this class, you'll have a clear understanding of how we all interact with artificial intelligence, what that means for your life, and how to harness it to make the world a better place.

Meet Your Teacher

Teacher Profile Image

Srikanth Guskra

Data Scientist

Teacher

A Machine Learning Engineer with a demonstrated history of working in the information technology and services industry. Skilled in Machine Learning, Deep Learning, Statistical algorithms. I mostly worked on Image Processing and Natural Language processing application. I also successfully deployed many data science-related projects in cloud platforms as a service in AWS, Google Cloud, etc.

See full profile

Class Ratings

Expectations Met?
  • Exceeded!
    0%
  • Yes
    0%
  • Somewhat
    0%
  • Not really
    0%
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.

Transcripts

1. Introduction: Hey everyone, welcome to the class on end-to-end face recognition web app project. This course is meant to be hands-on approach to the Computer Vision. The goal of this project to understand the story and folding in the face recognition. This is quite simple for us, but for computer, a task is extremely difficult. Why learning face recognition? Well, let me explain you what is face recognition first? Face recognition is a part of computer vision technology, where it is a way of identifying or confirming an individual person identity using that phase. Nowadays, face recognition is used in many fields. First domain that is coming to my mind is category of biometrics security, like I locking phones. Most of the mobile phones has this technology to unlock their phones using the face recognition. This technology offers a powerful way to protect the personal data and ensure the sensitive data reminds an accessible mobile is stolen. Face recognition has a familiar sight at many eight ports around the world. Increasing the number of travelers holding the bio-metric passports, which allowed them to stick the ordinary long lines and instead of walk them through an automatic age passport control to reach the gate, faster. Face recognition not only reduce the waiting times, but also allows a port to improve the security. Face recognition can also be used to find the missing persons and victim of human trafficking. Suppose a missing you individual or added to the database. In that case, the law of enforcement can be alerted as soon as there has been recognized by the face recognition, whether it is an output retail store or other public spaces. Face recognition has also been used in improving the retail experience. This technology offers a potential to improve the retail experience of customers. For example, kiosks in store could recognize the customer, make the products additions based upon their purchase history and point them in the right direction. And face recognition can also be used in the countless applications in banking, marketing, healthcare, a gaming, military, etc. Certainly, face recognition is an exciting field with an endless possibilities. To explore the world of face recognition. We designed this class into the five phases. Here are the five phases of the project. The first phase is phase 0. In this phase of the project, I will teach you the prerequisites of the project that are required in this course. Those are image basics of OpenCV and Python and phase reduction using Viola Jones algorithm and deep neural networks. In image basics, I will teach you some basic mathematical concepts on images and how to walk on images with OpenCV, Python. Then in the next section I will extend the image basics for the face detection open CV using Viola Jones algorithm and deep neural networks. Next, in the phase one, we will actually start the project by doing the data pre-processing to the images and train the machine learning model to identify the person name, etc. Here are the topics that we're going to cover in this section, like extracting the phases from the image, labeling, data, preprocessing, and train the machine learning model. In the next section, we will tune the machine learning model and evaluate the performance of the machine learning model using precision, recall, and F and scope. Then we move to the phase 2 of the project, which is actually we're going to build one more face recognition, that is facial emotion recognition. This is actually similar to the phase 1. Here we also do data gathering, data preprocessing, and train the machine learning model. In phase three, we will develop the website for the face recognition using Django framework by integrating machine learning model to the jangle Model View Template framework. Here we will be discussing about setting up the projects like installations and requirements. Then we'll start the concepts on Django. After that, we will develop the face recognition where BAP and jangle using modal view template plus machine learning framework. Phase 4 is the final phase of the project. Here we will deploy the web app in the heroku Cloud for production. This class is completely hands-on and every topic and algorithm will start from 0, where I'll teach you the essential background and mathematical concept in the algorithm wherever required. This actually help you to understand the algorithm. Using this course, you can develop any type of computer vision project from scratch. Now, let's start the class with the project phase 0, that is image processing with OpenCV. And here you will start with, start with the image basics with OpenCV and Python. And these are the topics that we're going to discuss in the next lesson. I will see you on that. 2. Install Python: Hello everyone, welcome back. In this lesson, we are going to see how to install Python in our local machine. For that, go to Google and type python. And this is the first URL which appeals, which is the official website of the Python. Go to our official website of your Python. Once you are in the official website, then go to downloads and click on the latest Python version available here. In my case it is 3.9.2. What are the latest Python version available to you? Download that? Okay, I have successfully downloaded my Python software. Right-click and click on Run as administrator. Now, make sure you check this box and click on Install. Wait for a couple of minutes until this process is completed. Okay, my Python setup was successful and I have successfully installed my Python LLC in the next lecture more on this. Until then, happy learning. 3. Install Required Packages: Welcome back. In this lesson, we will see how to install the packages that was required for this project. For that in section 1, you can see the lecture download dot requirements.txt. What do you do is that just click on the resources and click on requirements.txt to download the document. And make sure you put that in appropriate folder. That is 0, install and click on sale. Let's go to the folder. Now. Let's see how to install the packages that was returned in requirements.txt. Go to Search and type CMD. Navigate to the folder where your requirements.txt, copy the path and paste it here by cd space and paste. Now, navigate to that particular folder. Now type the command to install the following packages and requirements.txt for that pip install hyphen our requirements dot text executed. All right, you can see that requirements.txt is installed and most of the packages already installed for me. That's the reason it's saying that requirement is already satisfied. But for your case, the packages might be installed and it might take around five to ten minutes to complete the whole process. I will see you in the next lesson more on this. Until then, happy learning. 4. Install Dlib and Cmake: Welcome back. In this lesson, we will see how to install daily. Depends upon your operating system. We need to install the dealership. For Mac and Linux, we can simply uses pip install daily. Whereas for Windows it is not pretty straightforward. Just like Mac and Linux, we need to install first CMYK, then we need to use is falling command pip install to install it on Windows. Now let us see how to install on Windows. Go to Google and type CMake download. Now, go to the first link that appears here, which is cmake.org, and go to the downloads page, click on the first link. Okay, now you're in the downloads page and depends upon your operating system, you need to download the appropriate CMake executable file. In my case, I'm using the Windows, so I'm downloading the latest available CMake version that is 3.2.22. And also download the executable file, which is dot MSI. Save that in your respective folder. I have saved in my desktop. And what I'll do, not an install that right-click and click on install. Now click Next to continue. Accept all terms and conditions and click next. Check add CMake system path to the current user. And click on Next. And it stop. Okay, that's it. This is how we need to install CMake and click on Finish to complete the setup process. Now we are ready. Now let's install. Go to Search and click on command prompt and type pip install hyphen icon user. Wait for a couple of minutes until this process is completed. Usually this process will take at least 10 to 20 minutes, depends upon your computer setup. So please be patient and not stop the process until this process has been completed. I will see you once I'm done with my installation process. Dan, I have successfully installed my daily for this is how we need to install deliberate in our Windows. I'll see you in the next lecture more on this. Until then, happy learning. 5. Project Phase 0, Image Processing with OpenCV: Welcome. In this lesson, we are going to review the building block of an image with the pixel. We will discuss exactly what is pixel and how pixel is used to form an image. And then we will see how to access and manipulate pixels using OpenCV, Python. So what is exactly pixel? Every image consists of set of pixels, pixels or the raw building block of an image. Normally we think a pixel as a color or intensity of the light that appears in a given place in our image. If you think a made us a grid, each square box in a grid is consist of a single pixel. For example, let us pretend we have an image with a resolution of 300 by 300, which means that already measured it present the grid of pixels that a 100 rows and 300 columns. Overall there are 5023, that is, one lack 50000 pixels in our image. Generally the range of pixels can be defined by the width of an image. For an n-bit image, the end of pixels is between 0 to two to the power of n minus one. So for an eight-bit image, the range of pixels is between 0 to two to the power of eight, which is 256 minus one is 255. Now let us try to understand the difference between color image and Grace Kelly made most of the pixels are represented in two ways, grayscale and color. In grayscale image, each pixel has a value between 0 to 255, with 0 corresponds to black and to notify corresponds to white color. The values between 0 to 255, or wearing the shades of gray where the value closest to 0 are darker and the value closest to have defined lighter in color. Whereas color pixels are normally represented in RGB color space. One value for red component, one for green, and one for blue. Each of the three colors is represented by the end-user and the range between 0 to 255, which indicates how much the color is. Given that pixel values only needs to be in the range of relativity five, we normally use 8 bit unsigned in desert to represent each color intensity. We then combine all the values into RGB tuple in the form of red, green, and blue. This tuple represents our color. To construct a white color, we fill up each of red, green, and blue bar gets completely like this, something like 255, 255 and 255. To create the black color, we would empty all the buckets of red, green, and blue colors, which is filling up the values with 0. Fourier friends. Here are the common colors represented in the RGB tuples. Black is zeros 0000, white is 255, 255, 255. And for red, 255 comma 0, comma 0, and so on. Now we have a good understanding of the pig cell. Let us have a quick review of the coordinate system of the image. As I mentioned, Nebo, the image is at a presentation of the grid of pixels. Imagine our grid as a piece of graph paper. Using this graph paper, the 0 comma 0 corresponds to upper left corner of the image. As we move down and to the right where the x and y values increases. Let us look into the image as shown here to make the point more clear. Here we have a letter I on a piece of graph paper waste. We see that we have eight by eight grid with a total of 64 pixels. The 0 comma 0 correspond to the top-left pixel image, whereas 0.7 comma seven correspond to the bottom right corner. Finally, the 0.3 comma four is a pixel, three columns to the right and four columns with the DOM. This is what the pixel and coordinate system of our image. In the next lecture, we will see how to access pixels and convert the color in OpenCV. Until then, happy learning. 6. Load Image: Hey guys, welcome back again. In this lesson we will see how to load an image, display the image, and save the image in some different format. Okay, in the complete image processing technique, we are working on Jupiter notebook. So what we will do now is that let's open our Jupyter Notebook and load the image from there. Now let's first open the Jupyter Notebook. You can open the Jupyter Notebook by click on Search and type CMD command prompt. And what I'll do is that since I just wanted to walk my Jupyter Notebook in this current working directory. So what I will do is that let me copy the path, whatever, where exactly you want to work on. And now pasted here cd space, space to base the path of your current working directory and press Enter. Since I'm in the derive, that's why I'm just navigate to my D. And now we can see that this is what the path has been set successfully. Now let us open the Jupyter Notebook ER, by the command Jupiter space notebook, executed as soon as you execute the command and you are Jupiter notebook open in your default web browser. Wait for a couple of seconds until your Jupyter notebook has a loaded successfully hit ago. And this is what my Jupyter notebook has been loaded successfully, and this is what my current working directory. And as again see, this is what the Images folder and inside that we have few images. Now let us open the Jupyter Notebook. You can open the Jupyter Notebook by click on New and click on Python 3. This will open a new notebook. Wait for a couple of seconds until your notebook has initialized successfully? Yes. So my notebook has initialized successfully him with a name and title. The first, what I will do is that let me rename my Jupyter Notebook with one underscore. Let me name it as I just wanted to load enemies, display the image, and save the image and executed. So I just want to rename this with the whatever the name I want. The first library that you want to import before OpenCV is numpy. Import numpy as np. Numpy is a numerical Python library which is basically the dependency for OpenCV. A reason before importing computer vision CB2, we need to import the numerical Python. It may not be necessary like here you are using that, but OpenCV library will use it. So that's the reason it is better to import the nominal, better to import the numerical Python library before CO2. Now let us import our OpenCV library, which is cv T2. So this is my OpenCV library. Use a keyboard shortcut Shift plus Enter that will execute this cell. Now let us load an image using OpenCV library. You can load an image by the variable IMG equal to CV to dot. Cb2 basically represents the library open CV and we are using the module. I am Reed. I am raid is basically stands for reading an image. You can open this doc string using the keyboard shortcut Shift plus Tab. And what you can see here is that this function will load the image from the specified file path. So what do you need to provide here is that we just need to provide the file name or the path where exactly your images. So let me specify the path of the file. And since I just wanted to load any major and I know that my images thought there in the Images folder. And wherever you are Folder and wherever your images you can just simply path and it will load the image. And the image I just wanted load here is carved 000 1 dot JPEG and executed using keyboard shortcut Shift plus Tab. That's it. So this is how like, you know, you have load any mate successfully. Now let us print the image, whatever the variable we have, let us print it. Print IMG, executed. As soon as you execute that, this is what the image, and it looks like something like this. Any amazed that was loaded from the CB2 IM read command will be lower in a three-dimensional array. So the array is basically is a three-dimensional array. So the first one, the first dimension represents the number of rows, second dimension represents number of columns, and third dimension represents the channels. Specifically number of channels, red channel, green channel, and blue channel. So that's what this basically represents. And remember, one thing that like no open CV will read an image. And BGR format means blue comes first, followed by green and red. So that's what you need to keep in mind. And as I said, like you know, in the previous lectures we discussed that the pixels is the range of values between 0 to 255, since this is a color image. So this tuple represents one single pixel, means this represents the weightage of the blue color. This represents the weightage of a green color, and this represents the weightage of the red color. So if you combine all together, we'll get one color. Basically this three part, a hundred and twenty, hundred and fifteen and a hundred and sixty represents one single color or one pixel. Awesome, right? And one more point I just wanted to mention here is that all the majors that was read by this following command is eight-bit image. So since the amazed that we are reading is an eight-bit image. So the range of pixel values is between 0 to 255, means that all the values, whatever is there inside the pixel, or between 0 to 255. So you can check that by looking into the minimum and maximum value. So IMG dot Vmax. So basically the maximum value could be the 255 and the minimum value is 0. And the minimum value inside this array is 0. And in also you can look in the shape of that. It's basically very much similar to the numerical Python RA. So you can look into that by looking at the shape of that. And it says that we have 423 rows and 678 columns and three channels. Remember, again, the channels starts with blue, green, and red. Okay? So this is how like, you know, you can read any image. And one more thing you need to keep a note that whenever you are executing this command, open CV will not throw any error if that e-mail does not exist. For example, let me load I one more image. It is cv T2.ai read. And let's say it was, I'm just set the path is my images folder. And you can see here there are three images, or the 0, 0 21, 2002 to www dot JPEG and cod dot JPEG. So let's say, let me read some random image, basically that between majors not there with me. And just mentioned like JPEG, this image is not there in this any particular folder. But when your load that open CV will not throw any error. It not give any error. Basically it says like image not found and you can, image cannot be loaded successfully or something like this. So a do not throw any error. Basically when our, the image is not there, it will not throw any errors. But we can look into that by look into six. It whenever a printing this, that is nothing. And you can look into the data type of this. And if you look into the data type of this, it'll show you the NoneType. So that is water you to keep in mind here. So whenever the type of the image, whatever you read and this is a NoneType, indicates that open CV did not read that image, means that maybe that image is not present. And you need to specify some other folder or some other image properly. So that thing you need to keep in mind whenever you're loading any image. When are you Lord, any major can't display all those things. And if you get NoneType, it indicates that that image is not there. Alright, so this is how you need to load an image. 7. Display Image: Hey guys, welcome back again. Now let us see how to display the image. As we can see that in the previous lecture, we have load an image, then we save and variable IMG. Now what we will do is that let us display this image. In order to display the image. I will show you the different ways of displaying the image. The one thing that is there in the open CV, which is CV to dot m show. And if you look into the docstring of this inter-district is asking for window name and matrics. And the name of the window that I want to provide is any, any name, let's say, and this is what my original image or something like. This is my original image. And this is the matrix I just had to provide here. Means the matrix I need to provide here is IMG and which has some image or IMG. And immediately after that, what we do is that we need to specify the weight key. So if I specify the weight gain and what it indicates is like, you know, how much time delay. I just want to display this image. What are the image that we have displaying in some window? How much time delay I just wanted to display it. And remember that time is measured in milliseconds. For example, if you put 10, indicates that it will wait for ten milliseconds. If we put 4 thousand, it will wait for 1000 milliseconds. That means 1 second. And if you put 10 thousand, it will wait for means the window it will display for 10 thousand milliseconds, that is ten seconds. So let me write it here like you know, this command will display the window four and milliseconds. So here we have 10000 means and in the case 10 thousand milliseconds. So once we're done with the 10000 milliseconds, my next command will be, I just want to close it soon order to close that. And we use a command, does try all windows. Well that's it. So this is what I just wanted to do here. This is what the way of displaying an image executed. Again, see that this is what the image, and it'll wait for ten milliseconds. And immediately out of 10 milliseconds it, but it will get closed. We can say that. Let me execute one more time. It will wait for exactly 10 seconds. And after that, this window, we'll get close. Yes. So this is what like, you know, the weight k is going to do here in order to display the image. Let's say I just wanted to display the AMH for infinite number of times. Or in a simple way, like, you know, I just want to display the image until unless I manually close the window. In that case, what we will do is that will specify the weight key to 0. So this command will display, display the window until you press X or like you know, any keyboard key, any key. So let me execute this. Now you can see that it'll get anything until unless if I press on, Close, it will close it. Or here I'm pressing some any keyboard button and now it is getting closer. So that's what like, you know, the use of weight keep in going forward, what we will do, we will use the weight k of 0 means that I just want to display the image until unless I press any button. Okay, so this is what like an O, one of the method of displaying an image. There is one more method of displaying the image is displaying within the browser itself. Means like, you know, just like we are printing any kind of values, just like that. I just want to print an image. So that's one more method. So in order to do that method, what I will do is that I will use a one mode library called matplotlib. Using the matplotlib, I will plot it. Basically, I'm doing cumsum kind of chat. So let's do that. Let's import matplotlib. Import matplotlib dot pyplot as PLT executed. Now we can display the image using the matplotlib. So plt.plot, I'm show ditch like the CV to dot m show. We have the plt.plot Show. And here we just need to provide the x axis, basically an array. So here the array is what? Basically we just need to show an array that which we want to display. So the array that I want to display ease I am t. And now plt.plot Show, in order to show that we will use is like an appeal to dot show. Now execute it. Perfect. Now you can see that here we can able to display the image inside the browser itself. Okay, you might wonder this is not the original color of the picture, means this is the original color of the picture. What do we have? A is the L0 and some green and some what we have a, some reddish care, something like this. But what happened here is that it is changed completely. The reason behind that is matplotlib assumes that image is in RGB format. Assumes that image is in RGB format. So that's what the problem with this, since we read the image in the BGR format. And that's a reason like, you know, wherever her Louise there it is being replaced by red and red is replaced by blue. That's why we got this, for example, this person weighs a blue color and it's now it shows like something like a reddish. This is what the problem when our displaying with matplotlib. And the quick remedy for that is that simple indexing, just like NumPy indexing, just selecting all rows and all columns. Now just rivers that pixel values means the image, whatever we have A's and BGR format, I just wanted to spend RGB format. So this is two comma one comma 0, what indicates like an O, I'm just reversing the picture colors. So what I'm doing here is that as IMG is BGR format, so I'm just replacing that blue with red and red, red, blue. So that's what I'm doing here. Two is basically I'm just putting red is the first place and followed by green and followed by blue. So that's what exactly I'm doing here. Now let us says Give that. Now we can see that we have our original image. Okay, so this is how we can display any image using matplotlib and also using OpenCV m show. 8. Save Image: Hey guys, welcome back again. In the previous lecture, we have seen how to display the image. Now let us see how to save this image. You can see on that he made using Open CV, CV to dot IM, write M bridle. Basically using this command, we can save the image. What do you need to specify? Is that with nice, just need to specify the name of the file name that we need to save. And the format. For example, let me save this with the filename. Let's say in the image that I just want to save in the Images folder and say Save dot PNG. And that's what the extinction and the name I just want to save here. And the next 100 provide is that RA, basically, what is the RA? I just want to save. And the RA I just want to say is IMT now executed. And as you said like an O, the moment you'll get through, it indicates that you have saved the image successfully. Suppose you got fault. It indicates that like a know, your image does not able to save successfully. That's the meaning of this. Okay, anyway, so now in this case I got true. So let us look into our folder and let's see whether we have able to save our image or not. Alright, I'm in my folder and you can see that the scar 0, 0, 1 dot JPEG and save that PNG is what the name of the file. And that is what I've saved. And you can see this, I can able to save in a different format. That's it. So this is how like, you know, you can say any image you want. I'll see you in the next lecture more on basics of images with OpenCV. 9. Acessing Pixels: Hey guys, welcome back. In the previous lecture, we have seen how to load an image and display the image and save it in a different file format. Now, in this lecture, we will see how to access and manipulate the pixels using OpenCV. So first what we will do is that let us load an image and the image that I'm going to consider in this case is the same image which I've used in the previous lecture. So let us load the image and save it in the variable IMG. So I am d equal to v2 dot m read. And I say no, like, you know, my images, he's in my images folder and emails that I'm basically interested ease costs 000 001 dot JPG executed. And let us look into the shape of an array. I'm the dot shape. And what we can see here is that we have 423 rows and 678 columns. And we have three channels. B. B stands for blue, G for green, and R4 read. Now let us display the image what we have read. So we can use a CB2 dot ng-show followed by CB2 dot weight k of 0 and CB2 dot destroy all Windows using that. We can do that and every time writing that is highly not recommendable. So what we'll do, we'll write a simple function. And using that function, we will load the image. So let us write a function and name it as display, df space displayed. And the argument that I want to pass here is winning means basically the name of the window and the image array. And after that, we have to show the image using IM Show. And we know that like, you know, the first argument in ng-show is we name and second argument is Matt. Matt is basically an array or the image. So when name is basically the input is coming from the display first argument we name. So let me pause it here. And the name of the image array is IMAP, which is my image. Now the next step, what I wanna do is that let us put some weight key of 0. And finally, we will do display or destroy all windows executed. Alright, so we have successfully created the function display. Now what we will do let us display the image using the display function, displaying. And I know that the first one is the wind name. And the wind name that I want to create a is let say the cars. And the matrix that I just want to display is I am an image executed. Okay? So this is what the image which have loaded successfully. And what do you can understand from this image is that we have 423 rows and 678 columns. Rows is defined by the height of an image. So basically it says that the height of the images, 423 pixels and width of the image is 678 pixels. So that is how we can define the rows as a height and columns as a wet. Now what we'll do in this lesson, we will try to access the pixels from it. So here I just want to access, let's say first 300 rows and first 300 columns. Let's say maybe I just want to access this portion of the image. So let us see how to access those pixels. So before moving for the, let us look into the data type of the image by using the type of IMG. And what you can see is that the IMG, which is an array, is basically a numerical Python array. So this matrix has all the properties that was there with the numerical Python array. So we can slice it, we can manipulate it just like how we do for the numerical Python. So we can do exactly the same thing with the numerical Python array. Anyway. So what we will do now is that my question is that I just want to access first 300 rolls. And bracket is basically the height. And first 300 columns, which is nothing but the width of the image. Of the image. Nothing but my NumPy array. Okay, so how to do that? So basically we can do exactly the same thing, how you slice it for the numerical Python RA is like that. We can do it. So take an image IMG and use a square braces. And 0 colon 300 is basically we are asking for first kinda rows comma 0 comma 300. The next 0 comma 300 is asking for the first 300 columns. So that is how like, you know, we can access the image. So let me name it as ROI and execute it. So we can display this ROI using the display function, let's say display. And this is what my axis. And let us display the image and the name of the image is ROI executed. So this is what the ROI busy, this is what we have crop. And you can see we can access the pixel of first piano rolls and firstly 100 columns. Awesome, right? It is really very, very easy to access the pixels using OpenCV because it is very much similar to numerical Python. I will see you in the next lecture on how to manipulate the pixels using OpenCV. 10. Manipulate Pixels: Welcome back. In the previous lesson, we have seen how to access the pixels of an image. Now in this lesson, we will see how to manipulate the pixels in open CV. Okay, so we know that like you know, the accessing the pixel is almost similar to the RA slicing. Just like ROS slicing, we will replace the NumPy values to some value, which is nothing but the manipulating the pixels. In the previous lesson, we extract a 300 roles and 300 columns. So what we will do is that now we will not only extracted first dinner rows and first 100 columns. Also, we will replace that first 100 rows and first 100 columns with a green color. So that is what we're going to do in this case. So let us define the green pixel now. So green could pixel can be defined as a tuple of 0 comma two comma 0. So this is basically defined one pixel and the color is green. Now, what I will do is that let us manipulate the pixels. Means I'll take the first 10 rows and first-hand columns, and I'll replace them with the green pixel. So how to do that is almost similar to this. So IMG of 0 comma 3000, comma 300 is basically accessing first 10 rows and first 100 columns. And now I just want to replace them with a Greek pixel. That's it. Executed. So done. So what we have done is that like an OH, we have manipulated our image. Means we not only access the pixels, also, we have manipulated the pixel here. So let us display it using the display function, display, and it says manipulate comma and the name of the image IMG executed. Now here we go, he can see that we have not only access it, but also we have changed that into the green color. So this is how we can manipulate the pixel values to what are the desired value you want. Awesome, right? Now, what do you do? Just play with the water, the images you want. Just access it and manipulate it with the different colors you like. I'll see in the next lecture more on image processing with OpenCV. Until then, happy learning. 11. Color Space - Split BGR: Hello everyone, welcome back. In this lesson we'll talk about the color space, a color image kansas TO the multiple channels, red, green, and blue components. We have seen that we have access to this components via an indexing into NumPy arrays. But what if we want to split any image into the respective component that is ready-made, Louis made, and green image. So what I'm trying to say is that we know that image is basically the combination of three channels, red, green, and blue. So in this lesson, what we will do, we will split this three competence. And let's try to analyze like you know what like no, the ready-made consist of green image cons of stall, blue, he made tons of stuff. In this lesson, what we will do, we will consider this image and we will split the three components in this image and see how it looks like in open CV. So let us go to our Python and import all the necessary libraries that is NumPy and open CV. Now let us read an image and IMG equal to CV to dot IM read. And the name of the image is not Images folder. And this time the name of the image is three costs dot JPEG. And let us display the image using CB2 dot m show. And this is what my original image. And the name of the image is IMG. Next CV to dot weight king of 0 and CB2 dot. Let's try all windows. So this is what the image we are considering now. So we know that this image is basically consists of three channels. Let's look into shape. And if you look into the shape that we have, 795 rows and two columns and three channels using OpenCV split command. Let us split that into three different metrics. Anyway, the first matrix is B. Since the amazed that we read a sin the BGR format like becomes false for the green and for r by R means the first matrix, what you'll get is a blue teammate and the second matrix is a green image. A third matrix is a red image. Let us split that using CBT dot split command. So b comma g comma r equal to CV to dot split. And here I just want to provide the RA or the image which I will just want to split. So in this case it is IMG. So perfect. Now what we have is that like, you know, we have splitted our image into three different components, blue, green, and red. B consists of information about the blue color and G consists the information about the green color and our consists the information about the red color. So let us print the b here. If you print a, b is basically a two-by-two array, unlike, like IMD, is basically a three-dimensional array. And whereas the B is basically a two-dimensional array. So even the g is also the two-dimensional array. And you can see that all BGR or the two-dimensional array basically become and three tunnels, you'll get one image. And so what we'll do, let us separately display we are and try to understand like what exactly happening in that image. So let us display that using the command him show. So CV to dot m show. And this is what my blue image. And RA is blue and CB2 dot m show. And this is the green image. Basically, this green image consists of information about the green color, which is nothing but G, NCBI two dot m show ready-made, which basically contains the information about the red color. And also let us display my original image. So this is my original image, IMG. And now let's specify the weight key of 0 and CB2 dot destroy all windows executed. Here you go. What do we have? Is that like, you know, this is what my original image, and we split this original image into three components. And this is my blue and this is who? My red, and this is what my green. And what he can't understand here is that like, you know, each and every image has different sorts of information. So basically, if you look into this blue image, this blue image basically consists the information about the blue color, the lighter or like note the value near to white color, I think but 255. Basically, this is where the blue colour present and rest all is like, you know, we have like very, very less amount of amount of blue is there. So what you can see here is that this is the car is basically consist of the blue color. So that's why you can see here in this image. And this is what the virtual image, as you can see, this is my blue car and the blue image, this is what, much more lighter. Now let us consider one more image this time it is a green. And as you can see, the green image and we have the car in the middle is basically very much lighter in color. So this indicates that this is the portion where the green color is present. So let us look into that. So obviously this is what my green color. And finally, let's look into my red. Obviously like, you know, you can see this is what the car is very much lighter. So this here we have like, you know, the rich information about the red color. Let us look into my original image. Obviously, this is what this, and now what we can understand is that like, you know, if you combine the three major hills, like red, green, and blue, this is if you combine three images like this. And what you can get here is this image. I'll see you in the next lecture more on the Color Space. Until then, happy learning. 12. Color Space - Convert Colors: Welcome back. In the previous lesson, we have explored the RGB color space. However, there are different spaces that we are going to utilize. Hue saturation value color space is the most similar to how humans think and conceive of color. There is another color is L star a star b, i think about LAB is also a color space which is most tune into the human's perspective color. Opencv provides many different color spaces and understanding how the color is perceived by the human and representation by the computer occupies an entire library for the literature itself. In order to not go down into the details about this, I will show you how to convert the colors using OpenCV. If you think you are application of image processing and computer vision might need different color space than RGB BGR. I will leave that as an exercise to read two more explored the peculiarities of each color space. Now let us explore some code to change the color space. So now what I'm going to do is that let me use a different image now. Let us first load the image. I am G1 equal to CV to dot. I'll read one more image. And this time the name of the images in the Images folder. And this time it is beach dot JPEG image executed. Let us display this image using CB2 dot M shell. And obviously we need to provide the window name. Let's say this is my original image, nothing bad, my BGR image. Let me write the BGR for the mode specific way. Then what if the provider is Matt? Matt means basically the matrix I M G1. And finally see V2 dot. We're a team of 0 and say V2 dot destroy all windows. Now executed. Okay, this is the beautiful scenery. What we have is the beach and some coconut trees. So what we'll do let us apply some filters to this image and let's see how exactly our image is going to be work now. Let us close this. Now what I'll do here is that let me use a color space that was available in open CV and try to convert that into different color space. The first color space, what we'll see is that like no converting into BGR image to gray. Basically this is the BGR format. So what I'm gonna do is that the first color space, let's see converting that BGR image to gray. Also, we will see how to convert BGR to RGB. And you'll also the third one, we will see BGR to hedge us Vg, which is the most widely used. And for BGR two LAB. Okay, so, alright, so step-by-step, we'll see and try to understand how exactly it's going to work. The first, let us convert that BGR to grade. So gray equal to c v2 dot. We have a method in OpenCV which is convert color. And if you open the docstring using the command Shift plus Tab, and what you can see is that source, which is my source image. And I think that input image, in this case I am z1 and I need to provide the, what is the color space code I just want to use here. So let us see how to do that. Again, an eighth of source images, SRC is I M G1, and the color code is. So formula to get the color code, you need to use a Cv T2 dot, and use the CAPM capital letters color. And if you press the tab, you can get all lot of fill, like color. Underscore BGR. Since my format, the default format is BGR and just provide the BGR. Now you can see that a different color spaces are there. Hello, We will see like, you know, the four different color spacers. And for your thick of enclosed, you can also look into all the different kinds of color spaces anyway. So here is the BGR to the first color space I want to use is great. And you can search for BGR to gray here. That's it. So this is how you can convert that any image which is in BGR, it to gray. Let us display this. And in order to display that, lets you see V2 dot m show. And this is what my original image, virginal, which is my BGR format, and the name of the MAD psi m Z1. And also let us display the gray, I'm sorry, you say V2 dot IM Show. And this is my grayscale image. And the array of the Grace Kelly made 0s gray. That's it. And finally, let's use a CV to dot weight, CHEOPS, hero, and CV to DOD. Let's draw it. All. Windows executed. Awesome. This is what my original image, and this is what my grayscale image, awesome, right? We can see that this is a perfect Grace Kelly made and this is the color image and gray scale image. Alright, so now what we will see, we will look into the one more color space, which is converting BGR to RGB. You can also do that like an OB-GYN to RGB equal to CV to convert color. And here the source image, nothing bad. My input images I M G1 and this image, I just want to convert that into RGB. So in order to do that, we will do the exactly the same way what we did for the greyscale, which is CV to dot color and those code BGR to. And if you press tab, you can get the auto-fill and now just select what you want. Since I just want to convert VCR to RGB. Click on this, That's it. And let us display it. Okay, You say you two dot m show and this is what my word, those are. This is what my RGB. And this is the main underscore RGB. That's it for part of the displayed. This is my original image, and this is my RGB image. This looks like cool right hand. This is what my grayscale image is really, really like. You know, what happens here to wherever we have the blue that is being replaced by red. And red is being replaced by blue and green still remains same. For example, you can see some, some, there is some reddish behavior is there. And that is going to be converted into glucose. Okay? So that's what the basic difference between BGR to RGB, just basically the change of colors. Let us close this and let us also look into the color space BGR to hedge a sweep. So IMD hedge S V equal to CV to say Mother, kinda weird color and source images. I am D1. And this time I will change the color code to BGR to hatch as we hit us. V stands for hue, saturation and value. Let us display it, say V2 dot m show. And this is what my HSV and innate underscore hedges we executed. This may have originally made. That way minimizes this is the Hejaz. So you made and this is my BGR MH, Sorry, RGB image. And this is what my grayscale image, awesome, right? And one more image that was most widely used, apart from HSV, EDs LAB, physically L into a, into B. I just don't want to go more details into that. Let us see how to convert that colors. So IMG and Oscar LAB equal to CV to dot convert color and source images. I'm D1. And what do we got going here? Is that the color-code, his change the color code to BGR two. We have LAB executed. And finally, let us display this, just copy this and paste it here. What we will do this is what my LAB and copy paste it here. That's it executed. So this is what the colored course, what do we have? This is my original image and this is what my LAB image. It looks like, more like a segmentation, right? Let's do one more image. This is what my hedge SV basically hedge as we end LAB, lab book look more similar but there is a blurring effect. And LAB. This is what my RGB image. And this is what my grace Kelly major. Awesome, right? This is all about the color space in OpenCV. I'll see you in the next lecture more on image processing with OpenCV. Until then, happy learning. 13. Drawings - Line: Hey everyone, Welcome back. In the previous lessons, we have seen how to deal with the color spaces. Now we will see how to draw straight lines, circles, rectangles, and polygons in our image. Luckily, OpenCV provides a convenient, easy to matter to draw the shapes on the image. In this lesson, we will see that boast basic methods to draw the shapes in OpenCV. Before we exploring the drawing capabilities of OpenCV, let us define our canvas in which we will draw our masterpiece. Up until this point, we have loaded our image from the disk. But however, we will also define only majors manually using NumPy array. Given that open CV interprets as an image as NumPy array. Therefore, there is no reason why we can't do them manually. Defining remains ourself. First, let's import the necessary libraries, OpenCV and numerical Python executed. So now what I'll do is that I'll create my own image and name it as a canvas. And here my canvas is in black color. In order to create a black pixel, I just want to fill my array all the values to 0. As we know that any value closest to 0 is dark in color, basically black, 400, it is black. So now let us define our Canvas. Canvas, a call to using numpy as np dot zeros. And I just want to create the shape of my canvas and the shape of the Canvas. I just want to create a 300 by 300 pixels. And three is basically define the shape of it. All right? And this is very important. I need to provide the datatype of my image. Remember, the data type of an image is an unsigned eight-bit reason. So let's specify the data type to be unsigned eight-bit and diesel, which is u, I, and t. So that's it. Now this is what my Canvas, and if you execute this, your canvas has been Solicitor successfully. Let us displayed using OpenCV. In order to display that, I can use CBT dot m show. And this is what my canvas. And the name of the array is. Canvas also provides a way to dot weight king of 0 and CV to Dawn and destroy all windows executed. Here we go. This is what made Canvas that 300 roles and 300 columns, and the color is black. So what we will do in this Canvas, we will try to draw a line, rectangles and also circles on his canvas and try to understand what we can do more Enders drawings. The first and foremost thing, what we'll do is that let us try to draw a line, something like an in a diagonal point. For example, if we execute this image and I just wanted to draw a line from this point to this point. Okay, So in order to draw a line for OpenCV, we need to provide the arguments from 0.1.2. So between these two points, open CV will draw a line. So let us see how to draw a line here. Live. In order to draw a line, we have a method called CB2 dot line. And here I just wanted to provide the IMG, which is what my input image. And 0.1.2. As a mention that 0.1 at the point 2 are the two points and between which my open CV will draw a line. And color is basically what color you want to draw. And thickness indicates like, you know, what is the thickness of a line in pixels. Okay? So since I just want to draw a diagonal line between some 00 to three hundred, three hundred. So let me define my point 2 1. So 0.1 is basically a tuple. And at wha, what is a to another point in between which we will try to draw a line and point 2 to 300, 300. And the color I just want to draw here is assume that it is a green pixel. For green pixel is a tuple of 0 comma 255, comma 0. Basically we need to fill the green bucket. Alright, and so I think everything is done. So let us draw a line. Now. What we need to provide is a mate, which is my canvas. And point 1, 2 ET-1, and point to the SP2 and the color is my color. For time being, let us not specify that thickness. If you are not specifying any thickness, it was assumed to be one pixel. Ok, so this is what my line, That's it. So let us display this image. We can display the image using submitted dot and the name of the window pane canvas. And this is what my canvas. And CB2 dot weight gain of 0 and c2 dot and destroy or Windows executed. So that's it. So this is what my cameras, as I said, we have the diagonal line between the 0 comma 0.3003002. The color which we drawn is red color. Awesome, right? So I'll see you in the next lecture more on this line and also how to deal with the thickness of the line. And next lecture. Until then, happy learning. 14. Drawings - Line part2: Welcome back. In the previous lesson, we have seen how to draw a straight line. And in this case we have drawn and draw a line between from this point to this point. So in this lesson we'll see how to draw one more line. And this time we will draw from this point to this point. And this time we will increase the thickness of the line. And moreover, we're also add in sort of green color. Let me put some other different color like red. So let's see that how to draw a line. Okay, so I'm using the same canvas, whatever I'm having here, I'm using a same camels and this time I'll change the point 1, 2, sense. So this is the point we are going to consider and the point at which we are having a rose is equal to 0 and columns is equal to 300, so 0.1 to be 0 comma 300 and similarly point to the 300 comma 0. So this is the two points that we are going to consider now. Alright, so let's use the same code, exactly what we had. Cv T2 dot line, and the image name is Canvas and the 0.10 comma 300.2 is 0.2. And the color, what we're going to do in this case, a red color. Since it is a BGR format, blue comes 00 and 255, you fill with the full value that is 255. And the 11 argument that you are going to look in this lesson is thickness. And the thickness is basically measured in terms of pixels. Let's say if you put the thickness is equal to five. It indicates that like no, that outlined, what I'm going to draw is with a thickness of five pixels. So that's what we're going to draw now. So let us display this image. Let me do one thing. Let me copy this and paste it here. Now execute this. We're gonna go and this is what the line we have drawn. And this is the previous green line which is already drawn. And on top of that, what we did is withdrawn and the red line with the thickness is equal to five pixel from the point 1 to point 2. Awesome, right. I'll see you in the next lecture on harder draw the rectangles using OpenCV. Until then, happy learning. 15. Drawings - Rectangle: Welcome back. In this lesson, we will see how to draw the rectangles on our Canvas. So this time what I did, I took the different Canvas with the np.zeros of six hundred and six hundred means we have the width is equal to 600 and height is equal to 600. So I just save that in my Canvas and let me display the image. So this is some fought bigger Canvas. What do we have L and now what we're trying to do is that I will try to create a three different types of rectangles. Like one is without any thickness, and second is by adding some thickness. And third, we will fill that rectangle. We will see that like node three types of drawing a rectangle. Just like similar to the CB2 dot line. We have the CB2 dot rectangle and we had the oligomers more similar to it. So what we have is that we have an image and we have the point 1 and point 2, color, thickness and line type, something like this. So basically what we had is that like an O, we will have like no same arguments what we had for our line. But here the point 1 and point 2 indicates the two diagonal points of a rectangle. So let's see how to draw a rectangle to our image canvas. So what I'll do is that like no, let me take 0.1.2, which are my two diagonal points. Assume that let me consider the diagonal point to be, to take them off. If T is what my 0.11 more diagonal point E, assume that this time I'll take 400 km a 100. So this is what the point, what I'm having with me. And first and foremost thing what I want to do is that let me draw a color. And the color I just want to draw here is blue color. So blue forearm to draw a blue color and just fill the blue portion to full like 255 and rest to 00 comma 0. And that's it. Alright, so now let us draw a rectangle using CV to dot rectangle. So we need to provide here is Image 1, which is what my canvas. And point 1, 2, PT-1, point 2, 2, 3, 2, 2, and color to color. And that's it. So what we'll do now, let us display our image. So COV 2 dot m show endless. He swapped my Canvas and Canvas and see with the dot weight key of 0 and CB2 dot. Let's try all windows executed. As again, seeing here, we have a blue rectangle boxes appeared here. So which is basically the two diagonal point. As I mentioned, this is my 50 comma 15, and this is what my 100102 diagonal points. That is what we've drawn here. So let me draw one more rectangle here. And this time the rectangle I want to draw here with the thickness for the different kinds of thickness. So for that what I will do is I liquidate the same rectangle. And on the top of that, we'll, we'll add it on the canvas. And I'll chain the different points, p1 and p2. This time what I'll do, I'll take some my PT-1 to a 100182 to, let me take a 100 comma two. Okay? Thickness in terms of pixels. Let me take the fine and the color I just wanted to draw here, e. Let me take some green color. So the green is 0 comma two, comma 0. Okay, So let us execute this. Oh, I'm sorry. So basically boasted color and followed by thickness executed. Here we go. This is the blue one and this is what mine, green rectangle box. And this time Hal row one more rectangle box. And here, basically, I'll fill it. Basically what I'll do, I'll try to fill my rectangle box. So let me do the same CV to dot rectangle. And this time we'll change the points to 200 comma two. And so endpoint is 300 comma three. And so the color, I'm just going to fall go for red color is 255 and 0 comma 0 comma 255 basic as the red color. In order to fill the rectangle box, you need to use minus1, minus1. It'll basically understands that we need to fill the rectangle box with this color. Okay, Now I get x, execute this. Here we go. We have some a red color. And this is a box which was filled with the red color. Awesome, right? So this is a three rectangles which we drawn. One is the blue, green, and red. What are the rectangle? Whatever color you want, what are the thickness with whatever that you want to fill it or not? We can easily do it with CB2 dot rectangle. I will see you in the next lecture on how to draw the polygons and OpenCV. Until then, happy learning. 16. Drawings - Polygon: Hey everyone, Welcome back. In the previous lessons, we have seen how to draw a rectangle and also drawing a straight lines. Now in this lesson, we will see how to draw the polygons. Opencv is not only limited to drawing the rectangles or lines we can draw what are the shape you want? So let's create a canvas, canvas equal to np dot ones. In the previous two lectures, we have seen, we have seen the drawing in the blank canvas. Now we will take the white canvas. So in order to define the white canvas, I just want to create the ones and the shape. I just want here a six hundred, six hundred and three. Obviously the datatype to be unsigned eight bit integer. And so we got to the ones. So in order to get the white color, I just want to multiply that with 255. So with this we can, I can get the white color. So let us display it. You can display say V2 dot m, show Canvas and Canvas. See you two dot weight gain of 0, CV to dot. Let's try all windows executed. Here you go. This is what a white canvas. And this canvas, what I want to do is that I just want to draw one hexagon. Let me define the points of the hexagon here. So the point of the hexagon pace that we define in np.array. And so the first is 200, 200, 250, 300, 350, 300. You can take one of the points you want because this is the point that I calculated. So that's the reason I'm giving you this points. 400 comma two is in that list. Next is three hundred fifty hundred. Fifty hundred. Okay. So remember the order of the points we have. It should be in the two-dimensional array. So let me take this point and bt dot reshape that into minus one comma, one comma two. Okay, Now let's take the polygon module in open CV, CV to dot polylines. Now here I just wanted to provide the IMD is basically my source images, candles and the point or points BTS. And he's closed is basically this is the binary. Do you want to close or do you want to open? So this is the binary value. Let me put the falls at the moment. And the color, I just want the color to be, let's say blue color, that particular blue color, it is the top law is 255 comma 0, comma 0, and the thickness is five pixels. So let me displayed, so CB2 dot m show Canvas. Canvas weighed key of 0, CV to Don, destroying all windows. Executed 0. Oh, we should suppose to get the polygon here. Yeah, I think we should give the list here. It's a list off peak, yes. Yes, cool. Now you can see that this is what the polygon, what do we have? And remember, like, you know, the polylines I mentioned, like no lines to be false. So that is a reason it is not get connected. So if I specify to Drew, I can see that this lines are getting connected. So this is how like, you know, you can try a simple polygon provided you have the points. If you have a point, then you can draw what are the shape you want. So let me do one thing, let me create one more polygon. And this time maybe I'll change the coordinates. So here what I'll do, let me take that 200 Tessa shift. I'll just do one shift. And 100, this is 215, is 300, 250, and parallel 50. I can give it a different color here you can do what are the color you want? And it's not only like an all blue, green, and red. We can also have different colored. Just fill like No, this time I'll fill it with the 255 comma 0 comma 255, I can get some different color. The color will be the magenta. Let's say that as okay, this is cool, right? You can see that the blue color is what this line and the magenta or the pink line is this code. And it's really awesome, right? Like how drawing, what are the shape you want provided you, but you should have the points to draw. What are the lines you want? But anyway, this is really the cool way of drawing the polygons using OpenCV. I'll see you in the next lecture more on image processing basics. Until then, happy learning. 17. Drawings - Circles: Welcome back. In this lesson, we will see how to draw circles using OpenCV circle. Let us create a canvas again. And in that candles, let us draw the circle. So let me create the Canvas. Canvas a call to a and B dot once. And this time I just want to create the shape of an array between 600 rows and columns. And comma three is what? Depth of an image and data type 2, unsigned eight bit integer. All right, so this is what my Canvas. So let us display the Canvas CB2 dot Canvas, canvas and see V2 dot weight king of 0. Cbot dot destroy all Windows executable. Okay, since I want to create some white canvas, so what I'll do, I'll just multiply this with 25055. And this time I got the white canvas. So let us draw the circle on top of the canvas. So let us create a circle here, CV to dot circle. And here you go. You can see that the docstring is, we need to provide the image and the center of the circle and the radius of the circle, color and thickness. What we will do is that like a known for time being, let us consider the center of the circle to a 100, a 100, and the radius is 100. So let us create it using this same age scandalous center pays a 100, a 100, and the radius of a 100 pixels. So the color I just want to create here is that like an old paper, some blue color, 55 comma 0, comma 0. And obviously the thickness, negative values 0s indicates like, you know, you're closing the values. And the positive value is basically the thickness of the line and pixels. So let me take the five pixels and this is what I'm getting here. So let us display that, say V2 dot m show. And this is what my cameras Canvas. And CB2 dot weight gain of zeros, CB2 dot. Let's try all windows executed. Here you go. What you can see is that like an O, we can create a nice circle. So it's very simple. What do you do provide here is that center and the radius of the circle. So we can draw some abstract drawing. Let me create some logo. Maybe I'll create some Olympics logo. So let me create that basically Olympics. You know, that Olympics is basically consists of five circles. So let us draw that. So this is 200, let's say like an O, let me do some space of 200. Sends. It is a fight circles. Let me copy this and paste the five circles. So we have the five circles now and the first three circles on the top. So let's maintain like you know, the height to be 200 and now I'll change the wet my radius to 400 to 700. And so we got the first three circles. And in the next two circles, let me bring the other two circles down. Let's say, let me bring this to 300. And this is also to 300 in order to get the same alignment. And now let us, let me change that. Maybe I'll bring this in-between these two. So it will be two hundred and fifty and five hundred and fifty. And it can change. What are the color you want? I can give it a random color. This is the blue. Let me do green here. And let you read through the device 0 comma 0 contiguity by. And obviously I can do what are the color I want like an Olds may not be BGR. I can use some random color, 255 comma 0 comma z two pi. And probably disease also called color Quixote pi comma two comma 0. So that's it. So let me ask you this. And here we go. We got like in all the circle and maybe you've got some extra circle. Let me execute this cycle again. Let me show you this canvas again and, and execute this. How is it guys? So really awesome, right? So we can create any kind of abstract drawing using OpenCV. You can create a circles with a different radius and different colors. And you can also fill the color by adding some thickness is equal to negative minus one. And you can get, so what are the shape you want you can get using the polygons and etc. I'll see you in the next lecture more on image processing. Until then, happy learning. 18. 12 put text: Hey everyone, welcome back. In this lesson, we will see how to put text in our image using OpenCV. Okay, so you can see that like I know in the previous lecture we have seen like novae Creator some Olympics logo. So what I have to do is that like I want to put some text here, maybe Olympics, something like this. And that is what basically I just want to put it. So let's see now how to put the text. Open CV has special module called put text. Using that like, you know, you can put what other text you want. Again, put that in here. What do you do provide is that like an image and the text. And what is a text you want to provide and ORG, he's basically origin means where my first let us should start. And face font scale and color quantities is basically the type of font. And font scale is basically the size of the font and color. What is the, what is the color of the font you want? Okay, so first let us define the image. So image is basically the canvas and the text. Let's say I just want to create a text-based Olympics, LY MPI. That's what I want to create a text, Olympics and origin. The origin is I just want to create somewhere between 200 to 500. That's what my origin and font-face is. Basically what is a type of content is italic or what kind of font you on? An open CV by default consists of few forms or dare, you can use that. So for that, we too dark font and this font options that was there. And so this is quite easy and quite cool. I'll use a plain font here. And the scale. Let's say I'll take the five and the color calories. I'll go for the black color. So black color is 0 comma 0, comma 0. These were the black color and thickness is five pixels. So now let us display this image so we can display the image. Use the CV to dot info and Canvas. You will use exactly the same thing now executed. That's it. Like an OH, here I go again. See that we have the Olympics that is being displayed in our image. Excellent, Right, So what are the position you want and what are the color you want? What are the Text tool on? You can easily put into your image using CB2 dot put text. I'll see you in the next lecture more on image processing. Until then, happy learning. 19. Object Detection with OpenCV What you will Learn ?: Hi, welcome to the section object detection with OpenCV. In this section, I'm going to teach you how to do the opposite direction using Viola Jones algorithm, popularly known as cascade classifier. Let us look into the output of this section. Considered the inmate has three goals. For this image. We will do their face deduction, I detection and even the smile deduction. It is not only limited to the three detection. You can apply this technique to get the whatever the object action using the available pre-trained models using OpenCV. Let us go into the section to get more detail about this. How will see you inside the section? 20. Viola-Jones Object Detection Intuition: Hey guys, welcome back. In this section, we will discuss about object detection using OpenCV. We are going to look into the object detection algorithm that was used in open CV is YOLO Jones, object and Action Framework. Object detection using half feature based cascade classifier is an effective object detection method developed by Paul Viola and Michael Jones. It is a machine learning-based approach with a casket function is trained from lots of positive images and also negative. Then it is used to detect the objects in other majors. And this Viola Jones algorithm can also apply to any kind of object detection technique. However, our interest here is on the face detection. So let's look into the face detection perspective. The algorithm needs lots of pasta in majors and negative images. That means positive images or images with phasors and negative images are images without phasors. In step two, we need to extract the features from it using her features. This is just like a convolution kernel in convolutional neural network has shown below or the kernels that is used to the feature extraction. In step three, we will take each feature as a single value obtained by subtracting some of pixels under the white rectangle box and some of pixels and other black rectangle box. So once we got the fetus will train this with a machine learning model. So this is what the process that was used in the wireless Jones algorithm. And this is the most simplest algorithm that is used for the object detection technique. So without going much into the details, I request you to go to this original paper by Paulo ILO and Michael Jones, which is robust realtime opposite action technique. This is the original paper written by Paul YOLO and Michael Jones, articles to you to have a look into this paper on how to train your own object detection classifier using Viola Jones algorithm. And it has very, very wide applications. I'll see you in the next lecture more on how to do the opposite action using cascade classifier and open CV. Until then, happy learning. 21. Download Cascade Classifier: Welcome back. In this lesson, we will see how to download the had cascade classifier. So what do you do is that just go to Google and type has cascade classifier, OpenCV. Get up. And you can open the first link that was up here, here. And it says like, you know, had cascade. Get up, just click on that. Okay, So now you are in the OpenCV GitHub account and you can see that open CV slash data slash head gasket classifiers. So there you can see like, you know, the bunch of classical classifiers are also readily available for you and you can use it for free. In this section, we will see how to use a Haar cascade classifier. And this is almost similar to applying to the all cancel had casket classifies that was readily available here. So now first what we will do, we will see the three kinds of casket classify filters. That is the frontal face default, which is nothing but the face detection. And also we will see how to detect the eyes. And also we will look into those smile classified two. So first what we will do, let's click on this hard cascade classifier, had casket frontal as default. And now what do you have? Is that like, you know, you're in this particular file. Click on Rob. There you go, you're in this file and it is the Haar cascade frontal face. So right-click and save as, and save it to your respective folder. So wherever you exactly want to save, you can save it. For example, I just want to save in this particular folder and let me create a name of the folder is a cascade classifier. Okay? So copy the path. Now save it and this particular folder, click Save. And it's now similarly sale the cascade classifier. It just like how we did. For example, I want I know, just click on this, I click on Ron, right-click, save as. And what are the name is there? Just put the name and say, that's it and do it for smile also. Yep, click on this cascade, smile, click on Rao and save and it's done. So this is how, you know, you can download. What are the cascade classifier that you wanted to. You can easily sale in your respective folder. I'll see you in the next lecture more on ADI redaction with OpenCV. Until then, happy learning. 22. Face Detection with Cascade Classifier: Welcome. Now we will see how to use this casket classifier for face detection. And as you can see, like I know I have loaded my Jupyter notebook in your respective folder. Way. I have downloaded my casket classifier and this is what the folder where my casket classifiers are there, like had casket and Oscar. I had a cascade underscore parental phase endoscope default and Haar cascade endoscope smile. And also I'm having some couple of images with me and which I will do in this lesson. Next, what we will do now is that just need to open our new Jupyter Notebook, go to file and create Python 3. I already created the Jupyter Notebook with the file, one of those core of the reduction casket classifier. So let me open this. So this is the empty notebook. So first and foremost thing we're gonna do is that let's import few necessary libraries that was required for object detection. Obviously it is open CV. So let's import numpy as np, also import CB2 executed. Alright, so what we're trying to do in this lesson is that like an O, we all working on the face detection. Now we will see how to use his casket classifier to detect the face. So first let's load our image. I'll take an image, a call to CO2 dot m read. And my image you'll see is there in my images folder. And let me take some image 000 to JPEG and also displayed using CB2 dot m show. And this is my image. And I am gene NCBI, two dot weight gain for given a delay of 02 dot, destroy all windows executed. And here I go. I'm having the picture of Ronaldo. So what I'll do is that I'll apply the hat casket classifier to this image and I'll detect the face of the Ronaldo. Okay, So this is what I'm going to do in this lesson. So first let's load casket classifier. So the casket classifier that I want to lower A's frontal face, frontal faces and object detection cascade classifier, which is already trained for 6000 plus images. And this'll work decently good for the most of the images. Okay, let's load it. So this is the face cascade. And that's going to be called to ALU, the CB2 dot cascade classifier. And I just need to provide the path of the file. So my file is hidden, the casket classifier and had cast care frontal phase and Roscoe DePaul dot xml. And this is what the casket classifier that will detect the face executed. Perfect. And so we have successfully loaded our model. I think about casket classifier. Now what I need to do is that I just need to apply this cascade classifier to my image IMG. So let us apply cascade classifier to an image. So it's very simple to apply this cascade classifier. It's so almost simple, like phase endoscope, cascade dot. And we have a method called Detect multiscale Washington. And detect multiscale two will basically written the two parts. One is objects and second one is number of detections. And the inputs for the detect multi-skilled too, is that just need to provide the image. And you can set the order, the default settings that was there. And you need, don't need to worry about this. And it will remember like, like you know, it will, it will written two parts done its objects and number of detection object will basically give you the x, y coordinates of the face and also width of the face and also the height of the face. And number of reductions will tell you, like know how many phases has been detected. At the same time, it will also display the number of features that is being matched. Okay? So it will return the two-part one is phases. So how many phases and number of detections? And that's going to be equal to and just need to provide the image in an open CV Ira. Just provide this IMG executed. You'll take a while to calculate all the phases, so done. So what you can see here is that we have the phases and you can print phases. And we got like, you know, the coordinates of the phases. It says that this is the x, y position means the explanation is a 114 and y position. A 40 and a hundred and ninety six and a hundred ninety-six defines width of the face and height of the face. So basically we'll get some square box and the position is this. And what do you need to do is that if you calculate the diagonal point of this, and obviously we can draw the rectangle box of that. So we'll see that. And also let's also look into the number of deductions. So in order to print the number of deductions, use print number did underscore deduction. And it sounds like, you know, we have, the number of detections we have is 189 points. Basically the number of neighbors, you can see here is a minimum number of neighbors. Basically the 89 indicates, like know, the number of neighbors that is matched. 89. So that's what It's going to say. It doesn't mean that like, you know, you have eight or nine phases. This is number of points that has been matched. And the length of this is basically defined, the number of phases. So here the length is basically 1, so we have only one phase. All right, so this is what the meaning of the output or what do we got. And now what we see is that like an a, we have the point x, y point. And we know that we told the phase, and we know the height of the face. And using that can't we do that rectangle box as of course we can do that. So what we have here is the point 1 is basically my x, y position, nothing bad. 114 and 14. And the point 2 is basically we got the width of the face and height of the face just to add the a 114 with width of the face, which is 106 and 40 with a 196. What do we can get A's that died one more diagonal position of this. And obviously we have the two diagonal points. We can draw the rectangle, right? Yes, Now we'll do how to draw the rectangle. So let's draw the rectangle. So we can draw that rectangle using CO2 dot rectangle. We have we seen in the previous lesson how to draw the rectangles, rectangle and image one is IMG. And we can also have the point. The point is basically we can, we're going to get the point 1 is p21 and point to a speedy 21 again, get is a color. I just want to draw the green color. So green is 0 comma two, comma 0 and thickness. Let me define what are the default thickness it has. Now let us display it. So CV to dot, wait him shown. And this is what my face detection. And the name of the image is IMG CV to dot weight key of 0. And finally destroy all windows. Executed. Her ego, he can see like, you know, our object detection model that is casket classifier can able to detect the face and we have able to draw our rectangle box successfully. So this is how like, you know, the power of casket classifier. What it will do is that basically the X-ray position. This is what makes my position on what our calculator is that it calculated the diagonal point here. How using the width of the face and height of the base, the width of the face is 96 and out other bases a 196. And using that I can get the diagonal point. And using the CVD dot rectangle, I can draw this nice rectangle box. Awesome, right? Okay, It's not only that we can draw the rectangle, we can draw what are the shape you want? You can really draw it. For example, let us also draw the circle on top of this. So let's close this and now, now draw the circle. In order to draw the circle, basically what we required for the circle. We want a name. Obviously we got the image and the center of the image and radius of the image. We can calculate the center of the image using width and height of the image. So basically, width by two and height by two, we can get the center of the image. And what is the radius of the image? It can be either width by two or height by two. So let us calculate the center here. So let us calculate the cx, cx a goal to, since as you can see, that like an OC axis basically width of the image by 21 into six divided by two. So since I want the end-user, That's why I'm using the double slash and I can get this. But here, remember that this is basically we can get if, if at all, if you take the image in a square rectangle box and directly we can take 126 by two. But here, the problem is that like a no, we can't take directly a 108 is expect to. We need to add with that expedition so that we can get the center. So what is the expedition is? Expedition is a 114. And similarly, we can get the CY is that can be equal to 4009 to six divided by two. So we got the Cx and C Y and the radius of the image. We can take whatever you can take simply Harold 96 by two. We can take whatever like an a width or height because anyway that is saying and 109 to six double slash two in water they can get is the radius of the image. So now I think we already, so let's draw the circle, which is the image. And the center of the image is CX CY, and the radius of the image is color. This time I'll select the different colored 0 comma 255, 255, and thickness is two pixels. I've been preserved thickness of the image. Now, let us display it. Cb, cb 2 dot m show. And this is the face detection circle. I mean, of course we also get the rectangle box because we already drawn here and we'll also get a circle on top of that. I am gene NCBI two dot with v of 0 and CB2 dot. Let's try all windows executed. Awesome, right? You can see like I know I can able to draw the circle. Awesome, right again, see that I'm having a rectangle box and also I'm having the circle and that is inside my rectangle walks. This is really cool, right? So like this, you can use the shapes and draw anything you want. Only thing you need to get the coordinates. If we got the coordinates and water the shape you want, you can really able to do that. I'll see in the next lecture more on object detection with OpenCV. Until then, happy learning. 23. Multiple Faces Detection: Welcome back. In the previous lesson, we have seen how to do the phase reduction using OpenCV. But now the question is, how to do it for the multiple phases. This is not the recommended method of way of doing the coding. Now let's see how to do the conventional way of base deduction. So let us consider the image Ham, ham, the images here with me. Let us now consider the friends dot JPEG image. And if you see this, this is a friend's dot AVG. And what you can see here is that like an all we can see three phases means we have some multiple phases. Now let us see how to apply our face detection to this. So let us go to our core. And first and foremost thing, what we will do is that let me read that image. Img equal to CV to dot m read and the images folder, friends dot JPEG. Let us display it. Cb2 dot m shown. I'm Jean, image, IMG and see we dot weight gain of 0. Similarly destroy all windows after that. Okay, so we have this image with me. And what I want to do is that I want to detect the three phase. I need to draw some rectangle box on top of this. Okay? Since we already did this Haar cascade classifier and let me load it again. Generally that is what the more conventional way. So let me load this again. Now, what we need to do is that the step 1 is basically not the redaction. Like, you know, apply cascade classifier to an image. So if you apply this casket classified to an image, let's say what you'll get is that we might get phasors and we might get number of detections. Okay? So that's going to equal to face cascade dot detect multiscale to and what into providing ease image IMG. So that's it. So let me print my faces. And what do we got here is that we can find the five phases means this is one phase, does is one phase and one more phase here and one more vase here. So that is what basically we got. But in reality, in our image, I had only three images. So why I'm getting this phi majors? So the reason behind this is minimum neighbors, minimum Naples is what The reason behind that. So what did it do is that let's look into the number of deductions to. So if you print the number of detections, and we got the 40 majors that we have. And obviously these, you can see that we have the four neighbors or detector, and this is the four neighbors or detector. And for this phase, maybe for this phase I have detected the a 104 neighbors has been detector. And for this phase I'm having 84 neighbors or detector 71 enables or deducted. So obviously what you can see is that these are the three phases or the definitely the contenders of the phases. But here, there is a less likelihood that this is a face. So that's the reason. What you'll do is that gender LEA, we will set the minimum labels to some value because A1 event with one feature is detector, you might get that deduction to, but that is, could be a glitch. So that's the reason. What do you do is that just said the sum threshold. Generally it's a good way to set some threshold, anything greater than 88 or 10, anything more than eight or 10, that could be the good number. All right, so now what we have is that like an obey God, the minimum neighbors am set to eight. Now let's look into that. I'm having the three phases now and this other three phases, 10, four, eighty, four, seventy one. So we got the three phases now here. Now step number two, run a loop. Since I'm having the three phases with me. So I'll run a loop here for obviously the first one is x, which is nothing but like in all the x of the image. And y and width and hedge vesicle this were x, y position, width of the face and height of the face. Now let me take four x, y, w, h n phases running a loop. Now, what I'm getting here is that like, you know, I'm getting the loop now. So here what I can do, I might get even the multiple phases. I will, I can, I can able to draw it. So let us draw that. So CV to draw a rectangle. Obviously, I'm getting that image. For this image, I want to draw a rectangle box. And the 0.1 is basically x comma y. And the point 2 is x plus width, I think by the diagonal point plus y plus hatch. Next, the color of the box I want to draw is green column 0 comma five comma 0. So that's it. So we got a thickness of the image as it is. You are okay. You can set the thickness, otherwise you can leave it to set the defaults. So that's it. So now what we have is that we can able to draw the three rectangular boxes on the three phases. Done. And now step 3, nothing just displayed. Display the image. So CV to dot m show, and this is my face detection. And followed by the matrix a, IMG and CV to dot, weight gain of 0 and c v2 dot. Let's try all windows. Now, execute it. Here we go. We have the three phases and we can able to draw the boggy box on top of this. Awesome, right? So just one thing, what do you do is that you should be a bit careful on selecting that minimum number of tables. Generally, it is a good way to select the more than eight. Anything more than eight is also fine, but don't select the less numbers. It might lead to the overfitting that you might end up with the many, many, many boxes. Okay? This is how we can detect them multiple phases using cascade classifier and OpenCV. I'll see you in the next lecture more on object action. Until then, happy learning. 24. Eyes Detection: Welcome back. In this lesson, we will see how to do face as well as eye detection using OpenCV and had a gasket classifier. Okay, so let's take the same image what we did in the previous lesson. That is, let me copy this IMD qualities CV to dot m read and my images folder and friends dot JPEG. And this is what they made I'm using now. And obviously we saw like, you know, how to do the three boxes. And now let's look into the eye deduction to four I detection. The first thing what we do is that we need to detect the face first and then we need to crop the phase. And for that phase we need to apply 11 had cascade classifier, that is I. So now let us see like you know how to do this. And obviously let me repeat the same procedure, like the first one is the phase cascade. And that's going to be called to see V2 dot cascade classifier. Let me load that tagging. And my model is there in the casket classifier and my frontal phase default. Similarly, I cascade it called to see V2 dot casket classifier. And let's load it again, cascade classifier and the name of the casket classy, but I just want to load is had cascade I dot xml. Now let's execute this. The next step, what I wanna do is I just want to detect the face. So let us apply this. The first step is, which is almost similar to that of a deduction. Obviously it is a face detection. So since we already see like, you know, how to do the face detection. So let me repeat the same process. Like the first one is that we need to get the number of deductions and also faces from the detect multiscale. So faces and number of deductions. And this is phase a to phase on the scope cascade. That's going to equal. Dodd. Did tact multiscale two and the image he's IMD. Next one is the minimum number of neighbors. Just please select to eight. Next. What we need to do is that we need to apply the for loop for x comma y comma w comma hedge and phases. Now, just draw the rectangle box seawater dot rectangle. And what we wanna do is that like an all we need to draw the image, one. We need to, we need to provide the image that is IMG and the point 1, the x comma y, and the point 2 is x plus w, y plus hatch. Next is the color I just want to do. The color is 0 comma two comma 0. So that's it. So with this, what I can get is that I can get the face detection. The next step is I deduction. Here you need to remember one thing that is like an O. In order to detect the eye, we need to crop the image first. That is, we need to crop the face of the image first. So as we know the x, y position and also the width and height of the image. The first thing, what we do is that let's crop the image that is phase underscore ROI. Nothing but my region of interest is equal to, let's crop it. Image of x colon x plus w. Okay, we need to start with number of rows. So it is y column, y plus hedge, then x colon x plus h. And this is what basically we are cropping the image and we'll get the face ROI. So this phase alloy we need to apply to our had cascade classifier off I. Let us apply. Step three. A's apply to cascade classifier and bracket. It is i, o, this is obviously this is a reduction in the seas posting I basically these the cropping, cropping the face. Okay, now let us apply this. In order to apply that just we've doubled the same just like how we did for the failed deduction. So obviously you'll get iss comma number of detection of ice. That's going to equal to I underscored cascade dot detect multi-scale. And what we have is that we need to provide the image and the image that ended providers face underscore ROI. Okay, Now we got the eyes and number of deductions. Next step, and the next step what I wanna do is that I want to draw the circle on the top of the eye. In order to draw the circle on top of the eye, what I wanna do is that for e x comma y and e w e hedge basically I x y position and eye width and height In eyes. So you might get the two eyes most of most of the cases, and you'll get the two eyes. So E x E W and E hedge. Since I want to draw the circle and forth article, basically I want the CX is basically the center of the image or center of the eye, could be EX plus W divided by two. And with this, I can get the center position. But again, remember like no, this is just part of the image. And in order to apply to the anti-D made, what they do is that we need to add with x, because that is the x, y position of the face. And with that you're going to get the center of the eye. And similarly, if you want the center of y of l, I, see Y of I, and that is equal to L plus y plus e hat divided by two. And similarly radius could be called to he had divided by two. And with that, what you can get is that we can get center of the eye and also we can get the radius of the eye. Now let's draw the circle, which is CV to dot circle. And what is I made? I want to apply ies IMD. And the center of the image is CX, CY and the radius of the images. The next one is the color and the color of the image. Let me put some different color, 255, 0, 255 and thickness. Let me put some thickness is equal to two. That's it. We can get a circle around the eye. So what are the next step obviously displayed? So CV to dot m Show and thus his face detection. We can get the matrix. And the matrix here is basically the image IMG and CB2 dot weight gain of 0. And see me too dark. Let's try all windows executed. That's it. Now you can see that we have the face detection as well as we have the eye detection also. Awesome, right? Hope you really enjoyed this lesson. I will see you in the next lesson more on optimal detection using OpenCV. Until then, happy learning. 25. Smile Detection: Hello everyone, Welcome back. In the previous lesson, we have seen how to do the phase and I deduction. Now what we will do, we will also do Phase I and also smile detection in one quote. Obviously I'll take the same image. That is my friends that are JPEG, me, let me copy and paste his friends dot JPEG image. And for this image, what I'll do Phase I and smile. We know how to do this phase and also I know let's also apply the AI deduction to it. In order to do that, the code is exactly similar to our previous code. So what I'll do, I'll copy this code and paste it here. Hill. What I would do is that I just want one more classical classifier that is smile. So in order to get us my class get classifier, let's take CV to dot, has good classifier and load the casket classifier which is had cascade underscore smile dot xml. That's it. So we got it. The first step, obviously the face detection. Remember, obviously gonna get the smile on his face. So that's the reason the first step will be obviously that we need to detect the face. And for that phase, what we will do, we will do the reduction and also we will apply the smiley duction also. So exactly the same thing. We will do, exactly the same thing. However, we get here. In here, my next step will be the step number 4, a smile deduction. And that's going to be equal to, I need to apply the smile at action for the face. So that's a reason. What I'll do is that like, you know, applied to this phase DRY since the first step up like the eye. So that's the reason that may not get the correct positions. So that's the reason what we will do, well, let's put this before applying the rectangle box, and now we will copy this. So since what I'm doing here is that I'm just copying this portion to face on those code ROI. Now let us apply. Now obviously. Now obviously you apply this phase underscore ROI to cascade classifier. And obviously this is not step two, and I'll rename this histo step two and step three is smell it action. Obviously, we'll have the smiles comma, number of deductions underscore. Smile, I call to smile and a skirt can scare you dot detect, multiscale to and we need to pass face underscore ROI. Now, the next step is that apply the for loop for Sx means x, y position of a smile. We'll get the mouth and SY and as W, as hedge in Smiles. Now let us draw the rectangle box. It is CV to dot rectangle. And obviously the image is IMG. And the point 1, which is nothing but my x-ray pole position, x plus Sx. And similarly the y position is y plus SY in we got this x y position. The next step is that we need to get the diagonal position of this diagonal position is x plus Sx plus as W. And the y position is that y plus XY plus S hatch. So that's it. So we will get now the box. The next phase provide the color. And this time I'll go for the blue color, which is 0 comma, notice is 255 comma 0, comma 0. And the thickness to two pixels. I think that's enough. Next, let me change this step four, which is nothing but phase I and miles. So with this, hardcore is ready. Let me execute this. Dumb. Now you can see that like an OH, we have the phase reduction I deduction and also the smile deduction, too. Awesome, right? I think now that you guys are ready, You can try with the different phases and you'll get some awesome results. I'll see you in the next lecture on our project, which is face recognition, means like we are recognizing the name of the person. And also we'll see the emotion of the project like an a with whether they're happy, sad, disgust, etc. And next, we'll create a Django web app. And we will create some beautiful website using that and integrate all the necessary functionalities into this. Coming next is very interesting part and you'll love it. I will see you on that. Until then. Happy learning. 26. Face Detection & Feature Extraction using DNN OpenCV What you will Learn ?: Hi, welcome to the section based detection and feature extraction using deep neural networks in OpenCV. In this section, I will teach you how to do automatic face detection, facial key point detection using deep neural network module in OpenCV. Here we will use deep learning models to do this process. Let us look into the output of the section. Consider the image of the girl. For this image, we will do face detection, landmark deduction, that is facial key point. And using those landmarks, we will extract the features, that is 128 vectors. This will be the important for the machine learning model to build a face recognition applications like person identity, gender detection, emotion detection, and many more. Let us get into the section to get more details about this, I'll see you inside the section. 27. Face Detection with Deep Neural Network Framework: Hey everyone, welcome back. In this section we will talk about face detection using deep neural networks. In the previous section, we have seen how to do the phase reduction using violet Jones algorithm. That is using half of each. There are few disadvantages with the half vetoes. It may not work I correctly for the most of the phases. And the modified version of Viola Jones technique applied to the deep learning models and that is widely used phased reduction model. In this section, we will see how to deal with deep learning-based face detection using OpenCV. Open CV also provides a deep learning-based phase two doctors, more specifically, the OpenCV deep neural network DNN phase detector is based on single shot multi box deductive, also known as SSD, which is a framework using a resonant than one CV three-point one plus supports DNN module, which implements a forward pass with the pre-trained deep neural networks using the popular deep learning frameworks such as caffeine, TensorFlow, dot darkness. In this section, we will perform the face detection using pre-trained deep learning phase detector models included in the library. Open CV provides a two models for the face detection. Face detection, FP 16, which is a floating 0.16 version of original cafe implementation and phase detector, you ate also known as unsigned eight-bit in teaser, just 8-bit quantized version using TensorFlow. In each case, you will find the two set of files, the model file and the conflict file in case of CAPM model and this auto following details. You can download the models from the URL available. He'll also, if you want a TensorFlow model, you can also download from the URL available heel. Coming next, we will see phase reduction using deep neural networks in OpenCV, Python. Until then, happy learning. 28. Face Detection with DNN part-1: Welcome back. In the previous lesson, we have seen how to download our models. So make sure you have downloaded the models in their respective folder and also open the Jupyter Notebook. So in this lesson, we will see how to do the face detection using the deep neural networks. This time, I'm using the images that was there in the Images folder and the image that was working on in this lesson, a spacers dot JPEG. So please download this image in the resources. Now let us open the Jupyter Notebook by new Python 3. Change the name of the notebook to face detection and a skirt DNN. Alright, I guess you guys are ready. Let's kill it. First, import numpy as np and also import computer vision library CB2. Import numpy as np, import CB2. And the next step is that let's load that data or amazed that which we want to applying the face detection model. So low the image. So the image is IMT equal to CV to dot IM read. And the name of the image that I want to load a is an images folder. It is phases God, JPEG. Let's display the image. See me two dot IM show and at these faces. And the name of the image is IMT. Let's provide weight key and destroy all windows executed. Okay, these are the three beautiful faces. Let's do the face recognition algorithm to it. Let's detect the faces using deep neural networks. The next step, what we're gonna do is that obviously we need to load our model. Let's load the model. Net a call to see V2 dot. Since the my model lays in the DNN module. And let's use a special module and open seeming that is DNN and dot. Now, what do you do is that load the model using read net from cafe. Since I'm using the cafe model, that's why I'm using the ResNet from cafe. If at all you want to walk on the TensorFlow are taught, use the appropriate function that will read your model. Since I'm working on keeping, just select the cafe. Now, what it is asking is for prototypes and cafe model, let's provide it to it. That was laid my model's folder. And the first one is that two-ply dot-product x dot TXT. Next, provide the name of the model of that is like Cafe model, which is my resonate than 300 by 300 SSD. Select it. That's it. So this is how like, you know, I need to select the model and the load the model. Now, let's execute it. Perfect. Now you have successfully loader your model. Now the next step is pause the image to the model. It is not a pretty straightforward process passing that he made to the model. Instead, the first step, what we do is that we'd extract the blob from the image. So for that we use a special library, DNN to extract the blob. Extract blob. So Blob, a call to CB2 dot DNN blob from MHz. Now, what is the image you want to extract the blob. The amazed that I want to extract the blob is IMG and let's scale factor is one. And the next step is a size at which I want to reduce. Remember, the size you want already use is this. That is 300 by 300 modal will accept the image in the 300 by 300. So what I'm gonna do is that we need to resize the amaze to 300 by 300. So let's do it here. 300 by 300 inside that is a image transformation function resize will be there, that will resize it automatically. The next step, ase mean, we need to provide the means of a BGR. That is mean for B, mean for D and mean for our and blob. We'll basically calculate the subtracted mean images. So let's provide those values. The main four blue is 104, or green, it is 11741774, red it is 123. So that's what we needed to provide. And the next one, a swap RB, open CV, assumes that you have read an image in PDF format. If you read any major in RGB format, then said swap RBA to true, otherwise sets swap out to fall. Since I didn't imagine BGR, I'll set swap RB2 faults, DON executed. So here what we have is that we got blob. So that passes blob to our model. Said the blob as input. Okay, you can send them blob as an input by net dot set input. So what is the input for the network is my blob. Now, let's run it around the model. Net dot forward. Basically we are doing the forward pass operation. Forward path operation means we are not changing any weight to it. What are the ways that was there? We are directly straightaway using that wakes, Not at all changing anything. Obviously, that's the case right now. It's a pre-trained model. It, it will work very great accuracy for the phasors. So let's use the same weights. So for that I'll use as forward and output for that is the detections executed Done. Now you have successfully guard the outputs. Let's look into the output here. Detections dot shape. We have an output in the fourth dimension. Let us investigate this output. 29. Face Detection with DNN part -2: Okay, So I pull up my PPT and you can see that what we have is the detections dot shape and the shape. What we got here is one comma 1200 comma 200. You don't need to worry about this one. Comma one is basically we'll talk about the number of images. So currently we are working on only one image. That's why we got one. And the next important thing we need to understand is this two hundred. Two hundred means that modal has detected the 200 and faces. It doesn't mean that in the picture has 200 faces. It gives a probability that the object that is detected as a face or not, that information is there in seven. In seven, we have seven values. The 0th index is an amazing number, and obviously it will be 0. And the first index is binary, whether it is 0 or 10, indicates that the box, whatever it is detector is not a face and one indicates that what are the box it is drawn and it is indicated as a face. And index number 2 has a corresponding confidence code of the face. And 3456 gives you the coordinates of the face. So you unfold, has a statics and start by means x, y position of the face. And 56 kinds of stock index and NY means X-ray position of the one more phase. Basically these two values, 3456, are the two diagonal points of the bounding box. Using that you can draw the rectangle. So we'll see now how to draw the rectangle on top of the face. Let's go back again. 30. Face Detection with DNN part-3: Now I hope you understand what exactly this detection sees. So let's look into the confidence score of each and every deductions. So for that, let me use a loop for I in range of, since we have detected the 200 and phases, let us see the confidence score of all to our phases. So for I in the range of 0 to deductions, dont shape off. This, provide this to a 100 for that it is a index number 2. Done now confidence equal to detections. Obviously this is a 0 comma, 0 comma, and this is what basically it's consist of another phase number. So let me do the I and the index position number 2. Here, we'll do the convenance code. Let's put two here. Now let us print the confidence score up all the faces. What we got executed, pretty girl, what you can see is that we have a 200 of faces and their corresponding confidence score. You can see the lot of phases has a probability of 0, which basically indicates that there is no face. So I think that a lot of phases out there that has been detected. It is important to note that we need to set some threshold point of the confidence. Generally, it is a good technique to select the confidence more than 50 percent. So that's a reason. What I'll do is I'll select only the phases which has a confidence score greater than 0.5. So a confidence is greater than 0.5, greater than equal to 0.5. Just selected, let's print the confidence. Not executed, hoodie go. What you can see here is that we have the three phases and the corresponding confidence code. Awesome, right? Obviously in our image, what are they made that consider a city phases. And if I said the confidence is greater than 0.5, I got a three phases. There's a really cool right now what we'll do now shall we'd rather bounding box? Let's go now. Bounding box. Okay, So the bounding box information is there from the index three to seven. So now let us take the box a qual to detections. Select the appropriate face I, and now select from three to seven, which will give you the bounding box. But remember, this bounding box, whatever you're going to get is the normalized values, which is a normalized bounding values. Bounding box values means you will get the values which is normalized to width and height of an image. Let's print the values. We can see that the values, whatever we have is this values and all the values in the range of 0 to one, which is normalized to a width and height of an image. In order to denormalize this, what we do is that we need to multiply this with width and height of the image respectively. So let us calculate the width and height of an image. Comma w equal to. Let's take the image shape. And obviously what you'll get is that shape will give you a number of rows and number of columns. Rows will define height of an image, and the columns defines the width of an image. Select, we select only three values, sorry, only two values. So we got height and width. And now what do you have to do is that we just need to multiply with the height and width of this box as whatever we all available here, k. So now what we will do is that let me multiply this With walks into np dot. Arrange. Obviously this is start x, start y. I just need to multiply that with the width and height, and again, width and height. So with that, what I can get is that I can get the de-normalized values. Let me print this. Here they go. What do we got here is that de-normalized values. But remember, open CV will not allow this kind of a float values because image is an unsigned eight bit and visa. So that's the reason what we have to do is that we need to change the datatype two unsigned eight bit integer values. So let us change the data type to a teaser. Before that, what I can do is that Bob say call to box dot, astype, change that to AND's are values. Now let us print the box here. Here we go. You can see that we have the values in the teaser. I guess now you guys are ready. Now let's take the coordinates and let's draw the rectangle box on top of the face. So what we'll do a statics chemostat y and x n y equal to box. Now you got static startling and x and y. And the next step is draw the rectangle. So the rectangle will be submitted dot rectangle. In what he did provide here is that image IMG. Next, startx, then start wine, which is my 0.1. And index. Come in y, which is my point to an X, provide the color which has been green color 0 comma two, comma 0 and thickness. Let's leave as it is. Now That's it. This function will draw the bounding box on top of the face. What we got. Now, let's display our image. Cb 2 dot IM Show. And the name of the image. Phase detect. And the matrix is IMG. Now see me two dot weight key and CB2 dot and destroy all windows. Executed. Awesome, right? You can see that you are deep neural networks can able to detect the face accurately. Shall we put the confidence score on top of this box? As of course we do. Let's do that. So in order to put the convenance code on top of the box, first thing we're gonna do is that we need to put the text. We know that in open CV there is a module called post-tax. Let's use it. Put text and for which he made I want to put the text. It is my image. And what is a text I want to put? Let's put that text at the time being. And or g is basically the origin at which I want to put the text. And origin I want to put the text A's start x comma y, since I just wanted to show you some difference between the box and also the tax. That's the reason I will subtract that with 10 pixels. And the font face is need to provide font. So in CB2 we have the font underscore. Let's select the plane fault. Next font scale is one color. This time I'll select the white 255, 255, 255 and thickness. Let's leave it as it is. Now coming to this text. Text equal to, basically I wanted to print a confidence score. I can get the confidence score from this and just convert that into text using this format and confidence. And what you'll get the confidence in the value from 0 to one. But I just wanted to convert into a percentage. So that's the reason I'll come multiply that with 100. Now I can get the conference and a 0 to a 100, but here I'll get the multiple decimal points. Let me limit that into few decimal points, which is by using column D2 f. So this will basically give you only two decimal points. And before that, what I'll do, let me see it is a phase saying that I have detected the pace. Okay. And after this, let's put the person tell him means that I might get 99.9% age, 80.9% date, something like this. So I think we are ready now, let's execute it. Awesome, right? You can see that we can able to detect the face. And top of that, we have the probability or confidence score of this efface, which is 99.95. And for this, it is 95.80, and for this phase it is 80.42 is really cool. Ride your deep learning model can able to detect the face such a high accuracy. Now you guys can walk on water the images you want and see that like how well and how accurately you on model can able to detect the face. I'll see in the next lecture more on this. Until then, happy learning. 31. Feature Extraction Framework: Hello everyone, welcome back. In this lesson, we will see how to extract the features from the face using deep neural networks. Open Face feature extraction method is one of the most popular way of extracting the features. This is the aggregate picture flow that was used for extracting the features using the open phase method. We will see step-by-step like how this is going to be. Step 1 in the feature extraction is to detect the face. We can apply what are the technic you want like had casket classifier. You can also apply the deep neural networks to detect the face. Once you detect the face, next step is crop, the phase that is with the help of NumPy slicing. Then for the crop or phase, we need to apply a predictor model that will actually identify the landmarks in your face. Basically the facial key point, it'll identify the position of your eyes, nose, chin part the share predictor of the ways is passed with a deep neural network. And that is going to return you the 128 dimension. You need space hypersphere, which is basically the features of the face. And this can be used for the clustering, similarity detection and classification models. Face recognition is one of the application of the classification. And this project we are working on the classification model means we are going to take this features and apply to the classification algorithm so that we can get the face recognition here you can find the reference of the Open Face feature extraction matter and the URL is given there. You can have a look into the official documentation of the open phase. I will see you in the next lecture on how to extract the features from the face using deep neural networks. Until then, happy learning. 32. Facial Feature Extraction: part-1: Hello everyone, welcome back. In this lesson we will see the feature extraction from the phase using deep neural networks. So let us import the libraries that is numpy as np, also import CB2. And this time I'm introducing the new library, which is deliv delivers is the most powerful library, particularly for the feature extraction process going forward. We are not using that daily. We just use in this particular lecture only just to try to understand what exactly the feature extraction process also import face Utils from ion metals. So m from I am adults. Input phase and Oscar utils executed. It is utils executed. Now consider the image which is google.png, IMG equal to CV to dot M rate. And the name of the images gov dot PNG. Done. So let us display this image you can use, you can display the image by using CVD dot m show. And this is the girl. And IMG. Now see we did dot weight gain. Just mentioned 0 and c were to Don and destroying all windows executed. Okay, this is what the image, if you are considering now, for this image, what we will do, we will detect the face first, then we will identify the shape, and we will extract the features. So the three steps are going now, let's start it. So first let's import the models which is shaped predictor. And also import 11 model, which is phase descriptor, which is so shape under scored predictor. I'm using the daily blog every day live dot shape predictor and provide the model to it. The model that I'm going to provide here is in the models folder. And it is a shape predictor underscore 68 underscore landmarks dot DAT file. But this is the model I just want to load into the shape predictor. And similarly for the phase descriptor and the model that I'm going to use is shape. Shape descriptor equal to daily dot face recognition model underscore V1. Now I just want to provide the model, another model to it. So which is face recognition model, resonate model underscore V1. So this is what the I just wanted to provide to this. Done, let me execute this. We have successfully loaded out deep learning model. Now let us start the process by extracting the features from the face. The first step in extracting the features from the phase, a phase detection. So the step number one, ace, phase deduction. There are different ways of detecting the phases. So here what I will do, I will use the simple DB library. And using the library, I'll show you how to detect the face. Alright, let's start now. Now what I will do, let me copy the image, whatever I loaded into another variable, image equal to IMG dot copy. Now, phase detector equal to d live in Dili, we have a default frontal phase detector is available, so I will use tide away in this lecture. So get frontal phase detector. Now faces equal to phase detector, which is from the dealership dot. And the applied to this image, which is IMAP, which is my image. So that's it. So now what I can get here is that like an O, we can get the phases here. We can print the faces and have a look into that. And here you go. What I can see is that like, you know, this face detector is returning the output in terms of rectangles. It gives you that x wherever this is, it gives you the bounding box positions. This is the x y position, and this is another diagonal position to this point. Now let us run a loop and draw a bounding box on top of these using this rectangles. Let's run a loop for box and phases. And what we can get is basically this box is basically consist of the rectangle, even though you might have the multiple phases. So that's the reason I'm running in a loop. So here we go. What we can see is that we got this box. Now let me take this 0.1.2, this is my 0.1 and this is my 0.2. So in order to get this 0.1.2 PT-1 equal to box dot left comma bogs dot top, which is what my 0.1. And similarly the 0.2 will be equal to box dot right? Comma box dot bottom. So that's it. So what do we got here? Is that the point 2, 1 and the point 2. Now let us draw the bounding box on top of this using the rectangle in OpenCV. So CV to dot rectangle. And what it did provide here is this image. Next is the point 1, he's PT-1, and the diagonal one, and another diagonal point is VT2. Next has color. Let me get the green color 0 comma two, comma 0 and thickness. Let me set to default. Now what I will do is that let me display this image using m. Show that says what my girl phase detect. Now the name of the image, IMG, NCBI to dot weight king of 0 and CB2 dot destroy. All Windows. Execute it. Here we go. What you can see is that we can able to detect the face and draw the bounding box on top of this. Cool, right? I think we already made this process. I know that that is not much interesting stuff in this. Now what we will do, we will try to identify the shape of the phase using the shape predicted model. That will be the much more interesting stuff. I will see you in next lecture on that. Until then, happy learning. 33. Facial Feature Extraction: part-2 (Landmark Detection): Welcome back. In the previous lesson, we have seen how to do the face detection using dealership. Now what we will do is that what other phase we have detector, we will calculate the landmarks of the phase using the model shape predictor. So here I'm using this model shape predictor and using that, what I will do is that I'll try to find out the landmarks of the face. Now based on this curve shape, a shape predictor, this is the model I just want to take and shape predicted. What I do is that I just need to pass made. And also on the box of this image is IMG and the box is BOX. That's it. So with that, what do you can get is that we can get the landmarks of the phases, since this is in the dealership format. In order to convert that into NumPy array, what we will do is that we will take this face adults. Okay, so now face underscore shape, underscore array equal to face steals dot shape to and be physically we are converting that into numerical Python. And what I need to do is that I need to provide the phase shift with copy and paste it here. That's it. So now you guys are ready and v God, the landmarks of the phases. Let me print this trend face on this cone shape underscore IRA executed. And here you go. This is what the phase and this and all the corresponding landmarks of the phase, what we got. And remember, these aren't all the points means a 113249 together is 1. So like this, we have like, you know, 68 landmarks or there. What we can do is that we can use as circles and create a circles on top of the face. And what you can get is the landmarks. Now, for knowledge to create a circle, I'll use a for loop for pints and face underscore, shape underscore IRA. And I just need to create some wreck. I need to now I know I just need to create a circle here. So circle is Cv TED dot circle and wanting to provide ease in. And next one is centered on the circle. Obviously this point in the center of the circle. And let's take this point. Remember, this is all the values in the list. I just need to convert that into tuple, a couple of points, which is what, a center of the circle and the radius. Let me take the three pixels and the color. I just want the green color in order to create the green colored is 0 comma five comma 0. And finally, the thickness of the image, thickness of the circle is minus1. Now let me execute that. Here I go. What you can see is that we got the phase and what we got, we got the landmarks of the waves. This is one of the landmarks of the phase. It's a nearly nice, beautiful right? Moral can able to detect the eyes very accurately and the eyebrows, chin, and even the nose positions. This is really awesome thing, right? With that, I think we are really able to get the features from the face. And what we're gonna do is that we just need to convert that into a 128 dimension that we are going to see in the next lecture. Until then, happy learning. 34. Facial Feature Extraction: part-3 (Face Descriptors): Welcome back. The final process in the feature extraction is to compute the descriptors. So now let's see how to compute a descriptor using a deep learning model. So we have another model called shape descriptor, which will basically calculate the phase descriptor. So let me use this now. Let us calculate the shape descriptor, shape descriptor, dot com build phase the descriptor. And here I just need to provide a meat, basically to which he means I just wanted to calculate the shape descriptor and also the phase shift. We just need to provide the shape of the face. And with that, what he can get A's that is descriptive and now executed, done. So what now you can see that lake another phase descriptor. This and I love phase descriptor, which isn't that the Lib format. You can convert that into the array using np.array. With that, we can able to get the phase descriptors. This descriptor is used for the classification model or means in order training a machine learning model. The input for that model are these phase descriptor. And here you can see the length of that eight will be called to a 128. Here we go. We are a 128 dimensions of hypersphere. So this is how we can able to extract features from the phases. I will see you in the next lecture more on this until then, happy learning. 35. Project Phase-1, Face Recognition Framework: Welcome. In this section we will discuss about machine learning based face recognition framework. There are three main modules in the face recognition. Model1, data preprocessing model to train features with machine learning model, Model 3, sale machine learning model. Let us put this in a graphical format for a clear view. For the collected data or the images, we need to do data preprocessing and Ember the features from the phases that is faces simultaneously. We will also do the labeling path. Let us look into the data preprocessing in more detail. There are three parts again, there are again three steps in data preprocessing that are collect data, segregate data, and embedding and labeling. Let us look into the step-by-step, what is its processes about? Step 1 in data preprocessing is collect the data. It is highly recommendable to collect the data by your own, like friends, family, etc. Make sure what are the data or images you have collected has at least a 100 images of each person. However, for general purpose, I collected that data of 15 celebrities like Barack Obama, Donald Trump, Elon Musk, etc. The procedure is same for your own collected images to step 2, what are the data that is collected? The images? Could that in their respective folder, just like this. For example, we can look into my data which is collected where each person's are placed in the respective folder. For example, we can look into the admin, can photos, there are a 100 photos are there, and that is placed in their respective folder of America. And similarly for Barack Obama and etc, etc. Step 3, this is the most important step which is embedding the features. This process is seen as feature extraction, which we discussed in a previous lesson. That is, for each image we need to crop the phase and identify that face shape using deep neural network and represent the data in Harden 28 dimensions, which are our facial features. This is the process we need to do for the data preprocessing. Then we will move into the Module 2. In this module, we will train the machine learning model for the features that we are embedded. Let us investigate that in more detail. With the features are the data that we have extracted from the paces. We need to split the data into two parts, train and test sets. We will train the machine learning model with the training set and evaluate the model with the test set. This process is repeated until unless we got the best hyperparameters of the model. With that, our model will be ready. Now we are in the final module, that is module 3. In this module, we will save the mission learning model. With that saved model, we will make the predictions with the new images. So this is what our face recognition framework we are going to follow in this section and the next lecture, we will develop the face recognition model using phase framework. I'll see you in the next lecture, more honest and to them, happy learning. 36. Data Preprocessing: Welcome. In this lesson, we will do the data pre-processing. Hope you have collected the data appear wound, which is highly recommendable in this course. But in this course, I'm going to consider the data. Celebrities like Hamilton, barackobama, Cristiano Ronaldo, etc. Now let us start doing the data preprocessing by loading the data into a Jupiter notebook. I have successfully loaded my Jupyter Notebook and make sure you create a folder named models. And inside that copy all the necessary libraries that was used for face detection and feature extraction models, which we discussed in the previous section. Now let us create a new Jupyter Notebook and let's do the data preprocessing code. A new click on Python three. Let's first rename our notebook has one data pre-processing. And in that we will do all the data pre-processing. First, import all the necessary libraries that was used in the data preprocessing. Import numpy as np import CB2. Let me also introduce one more library, pandas as pd, which is used for data analysis and processing. Also input O is also import pickle, which is used to save the data. Step lamb in data preprocessing is detecting the face, as we also saw in the previous lecture on determining the phase using deep neural networks, right? Let's use that process face detection model. So let me also load the model here. So let's write load the model. There are two models we are using in the data pre-processing. Let us first load the face detection model. The first model is phased reduction model. Equal to provide the path which is in the models folder. Now select, resonate three hundred and three hundred SSD Kathy model. Now also provide the prototype text which is equal to dot models folder. Now select deploy prototypes dot TXT, which we did in the previous lessons. Let us also provide a second model, which is based descriptor equal to model's folder. Now select Open pays version 1 model. Now we just provide the path in the variables. Let us now load the models using deep neural network module in CB2 detector model equal to, let me use the DNN module in CVD. Now select read from CAPM. Since we are using the CAPM model, That's the reason we are using this. Then we need to provide photo text and copy model. Since we already have in the variables, let me provide the variables, which is face detection protocol and face detection model. Next, also load the descriptive model description model equal to CV to dot DNN dot. This is like dogs model. So let me select and read Ram Dodge. Now we need to provide the model. Let's pass the variable based on endoscope descriptor executed. That's it. Now with this, we have loaded our model successfully. I will see you in the next lecture more on data preprocessing. Until then, happy learning. 37. Data Preprocessing - face detection: Welcome. The next step in the data pre-processing is to apply the images to the model and get the face descriptor from all the faces. Now, let us access the folder using the following commands. For Windows type DIR to get the list of directories to run the line X or.com, use the exclamatory mark, exclamatory mark DIR, and the name of the directory images here. Now the images are there in each folder for the respective person. Alright, let us create a helper function to extract the descriptor from all the faces that was there in all directories. Time being, I will consider one sample image of such intended. For that, I will extract the features. Later on, I Laplace all images by using the same technique. Let's go starting by reading the image selected dot a marine. Take the image of such intense occur in the Images folder. And navigate to such intended curve. And take the image. Due to 000 dot JPG. Display the image using the following command, C V2 dot m show. And the name of the window is such an array is IMG. Let's set weight k2 and provide destroy. All windows. Now execute the command to display the image of such intense Rucker. Here we go. This is what the image we are going to consider it for time being and extract the features of such integrity occur. Later on, we'll apply the same technique to all images. Step 1 in facial feature extraction, phase detection. We already did this process in the previous section. Now start the process by copy the image to IMG. Then compute the height, width of the image has come a w is equal to image dot shape. And select first two values, which is colon to. Next. Compute image blob, IMG blob equal to CV to dot from the DNN modules, select blob from image to image, which is equal to image scale factor set to one, size set to 300. 300. Also provide the RGB means a fraction equal to one. Is it a four hundred and seventy seven hundred and twenty three sets VAB, RB, two faults, and also set crop to false. Next we will set the image to our model. The model that we are going to be working on here is detector model. So let's take the detector model a qual to set input to image block. Next detections, a call to model detector detection model dot forward to get the detection. So this is actually we are executing the deep learning model. Now, considered the majors only when the length of detections greater than 0. Since in the previous section we know that there will be 200 detections and we also got the confidence for all the 200 and phases. My point here is that we had the data with only one phase in each image. So out of 200 detections, we need to take only one detection that can be selected using the competence goal. That is select only one phase with highest confidence score. Let's write the code. I. A is equal to np dot. Take the maximum confidence score. So argmax, let's take the maximum confidence score from the detections. And that's going to be equal to 0 comma, 0 comma. And I just want to all the deductions in that. Let me take the confidence scores. Basically I'm going to be taking the face with maximum conference calls. So this is considered the face with maximum confidence score. So that's what I'm going to do in this case. Now let's take the conference call, a call to detections. Let's take the detections. And in that detection check the 0 comma 0 comma condition comma two. So, but this I can get the phase with the maximum confidence score. Now, what I can do here is that let's take the confidence score, at least the conference correctly is greater than 50 percent. Now, considered that then only what we do is that I just want to draw the bounding box of this. Let's take the box out of this. That's going to be equal to detections. And this time it is, I know we know already did this process, which is I come three colon seven. And I just want to multiply with AND WE dot array since we did this process, because as a normalized values will get and we need to multiply that with the width and the height. Okay? So with that we can get this. And now what he can get put in a tuple. This is the start x and start y star y and x and y. That's going to be equal to box. And just take the convert the type into InDesign. Now, we can able to draw the bounding box just for reference to draw bounding box. Because you're going to extract that properly or not. So that is the reason I'm going to do. So. Am I am generous could draw a coil to take this image dot copy. Now see Richard darker rectangle and take this image and this is what my image and just go dry. Now, my rectangle position statics and start why tank destroyer the diagonal positions. We already know this point 1 and point 2. And this is what my end x and end y. Okay, so let's do some green color. And here it is 0 comma two comma 0, and the thickness is equal to one. Let's do whatever the default is available in there. So with that, what we can get here is that a weekend able to draw the bounding box on top of this. So let's have a look into that by just see V2 dot m show and this is what my Sampling me helices my image and also shows you two dot m Show and draw image. And that's my image IMG endoscope, draw CO2 dot weight key of 0 and CB2 dot destroy all windows. Oh, this is my detections. It's not detect. Just changed into the detections. Now execute that. Now this is what my sample image and this is what my DRI me. So it's okay we can able to detect the phase properly. 38. Data Preprocessing - feature extraction: Welcome back. In this lesson, we will see how to extract features from the face using deep neural networks. In the previous lecture, we have seen how to extract the phase. Now in this lesson we will do feature extraction. Now let us start with step 2, which is feature extraction, are embedding. Let us crop the detected phase, which is I equal to a mage of stat y colon and y comma startx colon and x. With this, I can get the region of interest, which is my face ROI. Now get the phase descriptors. To get the descriptor from the phase, we need to use our torch model, which is a descriptor underscored model. Let us go back to code and calculate the blob from image phase blob equal to CV to dot DNN dot blob from image. And the perimeter I just want to set a is ROI, which is our image. And the scale factor, we need to set 21 by 255 and make sure the size to 96. 96. And then said RGB means a fraction value to 0 comma 0, comma 0. Also set, swap our beta true, crop to true. Now let us pass to a descriptive model, set the input as phase blob. Now vectors equal to descriptor and Osgood model dot forward. So with that we can able to get all the vectors from the face. Let's print that with print vectors. Now, let me remove all this things which is not required for me and executed. Oh, we got an arrow. This is not copy the set 2D crop, just change that to crop. Now let's execute it. Perfect. We got the vector successfully from the image. And the next lecture, I will see how to do for all the images. I'll see you on that. Until then. Happy learning. 39. Data Preprocessing - Helper Function: Welcome back. In this lesson, we will see how to extract features from all the phases that we have. In order to do that, let's create a helper function. Using that we will apply to all images and get features. Let's do it, press tab and create an indentation. Now create a function with the name helper and the arguments into a function is image, but instead the function, let me add one more line to read an image. So seawater dot m read and specify the file name as image path. So with that, we can read any meat and perform all operations like phased reduction, feature extraction from the detected image that it didn't value for this function is phase back dials are phase descriptor. Since I know in my data that is only single phase in eating meat. So I just wanted return the image feature of detector are none if the base is not deducted. So return a vector inside the if condition and outside the condition written, none. Specifying that if the face is detected, then visit n vector. Else we will written none if the face is not deducted. Let me does this helper function, helper of, let me specify the same image bad and execute it. Here we go. Regard output. Cool, right? So with the simple part I can able to extract the features from it. In the next lecture, we will see how to apply this to all the images that we have. Until then, happy learning. 40. Data Preprocessing - Feature Embedding and Labeling: Welcome back. In this lesson, we will see how to apply the helper function to all the images we had and get the face descriptor for each phase. Let's write the code. Step one, put all the folder name in a list folder equal to OS dot list directory. And the main folder name is images. With that, let's print the folder. Print of Folder. All right, we got all the folders in a list. Let us move on to the step two. In this step, we need to take all filenames inside each folder. Let us understand how we take for each filename in one folder. Then we apply to all folders. Let me put comment first. Now, filename equal to 0 s dot list directory. Mentioned the folder path. Here it is a major slash. Let me consider it one folder that is Ahmed Khan and print filenames. Cool, right, we got all file names in the list. Let us apply the same technique to all filenames in a list. For that, I will use For loop for folder in folders. Now filenames equal to OS dot list directory and mentioned the path which is Images folder. And let me insert the values and dynamically for that it is a format and the value I just want to insert ASE Folder. Perfect. We got all images of a meat con, Angelina Jolie, Barack Obama. So on, which means that we have successfully extracted all filenames in an individualist. And step three, we will put all filenames in one list, four, filename in filenames, print, filename. Excellent. We got all filenames and I list. Now let's move to the step four. In this step, we will extract the phase descriptor or phase vector that for all detector phases vector a call to let me use helper function. An argument for this is just provide the file path, which is in the Images folder way dynamically inside the folder name and file name in a format. With that, we can get vectors for each phase. And the next step is we need to append all of hectares and a list. Since in helper function, we have a little vector or none. We only want the vector has to append and skip all the nonce. For this to happen, let us use if condition to append it. If vector are not none, then this condition satisfies. Then we need to append in some list. First grade variable data in dictionary. And we will append all the values into it. Data equal to dictionary of data, equal to create an empty list. And also create another key with the name with label, and initialize with empty list. Now append all values into the data. Data. Provide the key data dot append vector. And let me also append the label, which is data of label. And the label for this image is folded name itself, append folder, which is my label for that image. Since in this process you might encounter the exception errors. To handle those exceptions, we will use exception handlers. Now try what are the code you want to put exception? If there is an error, then put them inside the try and except pass, which means just skip it. Now executed. Usually take 10 to 20 minutes depends upon your data. I will see you in the next lecture more on this. Until then, happy learning. 41. Save data: Welcome back. I completed the feature extraction and leveling process. Now let me look into the distribution of labels, what we have from the data. If you look into the keys, we have two keys are there. One is data and other one is label. We are interested in that label at the moment. Let us look into the label. As you can see here, we have all the names of the phases that was stored in the variable data of labels. Now let's calculate the distribution with a Pandas series and value counts. Pd dot Series of data of label dot valid counts. Here, you can see that. Here you can see the label distribution is almost uniform. Highest number is around 125 and the lowest E Set 95. Cool, right. The next step is save the data into pickle file format. And that was using in the mission learning to train the model. So big L dot dump, provide the object you want to sale is beta. And the file name you want to save is open. Data underscore, phase underscore features, dot, pickle. And the mode of operation is WB, meaning right in bytes. Now executed. We have successfully saved model in the pickle format. Even you can see in their particular folder where you're working on and the size of the data is 891 KB. I'll see you in the next lesson on how to train a machine learning model for face recognition. Until then, happy learning. 42. Machine Learning - Data: Welcome back. In the previous lesson, we have seen how to do the data pre-processing. And also we extracted the features and that readers we have sailed in the pickle file format. In this lesson, we are going to take those features and train with our machine learning model. So let's go now create a new notebook with the name to underscore train underscore machine learning model. Let me open that. So first and foremost, what we need to do is that let's import the three main libraries. That is NumPy, Pandas, and pickle. Let's execute this entraining the machine learning model. Basically, there are four main modules of their model. One is about the data. In Module 1, we will load the data from the pickle file and split the data into independent and dependent variable. Then we will split the data into train and test set. In Module 2, we will train the machine learning model. In Module 3, we will find out the best hyperparameters using grid search method. And finally in Module 4, we will save our machine learning model. Let's get started here with Module 1, which is the data. First and foremost thing, we need to load the data from the pickle format. So let's take the pickle dot load. Here. I need to provide the file in which the data is stored in the pickle. So let me do the file with open. And the name of the file here is data phase underscore feature. And also provide the more equal to read in bytes equal to RB. Well that's it. So let me save in a variable data executed. Let's print it. And here we go, we have the data, and that data is, have a data type of dictionary, which actually we did in the previous lesson. So now what we will do, let's split that data into independent and dependent variable. Let me take the x, which is my independent variable, equal to data, and provide the key data. What we're doing is we're taking all the features and putting that into the variable x. Let me convert that into np.array. This is my independent variable. And similarly, y equals np.array. Data of what we need to provide here is labeled, that's my independent variable. Okay, That's it. So with that, we are able to split that data into independent and dependent variable. Let me look into the shape of x and y. X dot shape and y dot shape. All right, so what you can see here is that we have one hundred, six hundred forty two rows. And each, and every vector is one by a 128. And similarly y we have 1, 0, 0, 0, 0, two values out there. Okay? So this is a third dimension format. And really we, and we really don't require the third dimension, Forman. So what we will do, we will reshape that into two-dimension. Let me do that. X is equal to x dot reshape. And the shape I just want to reshape is minus1 come a 128. What exactly I'm doing here is that minus1 indicates that 1, 0, 0, 0, 0, 0, annuity due. And 12 and eight indicates like No, I'm just simply getting higher-end 28 columns. That's it. That's what exactly I'm doing. Let's look into the shape again. Okay, So we have successfully modify the shape of our data. Now, the next step in the data is split the data into train and test set. In order to split the data into train and test split, let's use SKLearn. So split the data into train and test. I'm going to use scikit-learn. Let's import it from SKLearn, dot model selection, import, train, test split executed. So now let's take the variable extreme comma x test, y train comma y test. That's going to be equal to train test split. And here what I want to do is that I simply need to provide the arrays, which is nothing but x comma y. Then I'll take the train size. I want the training data of size of 80 percentage and remaining 20 percent H should be on my desk sides. So that's what I'm going to consider and mentioned random state to 0. That's executed. Let's look into the shape of my variables. X train, y train x test and y test. So let's do that. Extra dark shape comma X test dot shape, and y train and y test dot shape executed. Here you go. What you can see here is that this one hundred and six hundred and fifty two rows has been splitted into into two sets. One is trained and second one is test. In train set, we have one hundred, ten hundred, three hundred and twenty one rose. And in the test set we have 331 rows are there. Well, that's what we can able to get, split the data into training and testing. I'll see you in the next lecture on how to train the machine learning model. 43. Machine Learning and Evaluation - Logistic Regression, Accuracy and F1score: Hey everyone, welcome back. In this lesson, I'm going to show you how to train a machine learning model. You can use what are the machine learning model? It's not necessary that you need to follow my machine learning model if at all you want to train with the other machine learning models, you can also go ahead and train that with your machine learning model. However, I'm going to show you the three machine learning models to train the face recognition. And that three machine learning models, I will combine them using voting classifier. Okay, so let me take that first. Let's import the machine learning models. The machine learning model I'm going to use here a logistic regression Support Vector Machine and random forest. So let's import that from SKLearn dot linear model. Let's import logistic regression. Let me take one more machine learning model which is support vector machine, which is most widely used machine learning model for training image processing applications. So let's take that from SKLearn dot SVM, a boat. So SVC, SVC. Now also take the random forest from SKLearn. It's an ensemble method. Import random forest classifier. Here I'm going to use a three machine learning model and I will combine them using voting classifier. So let me also import that wasn't classifier from SKLearn dot and symbol import voting classifier. Using voting classifier, I'm going to combine the three models and select outward based upon the OT method. It is pretty straightforward stacking model, since I just want to evaluate my machine learning model. So that's the reason Let's also import the classification report from SKLearn dot matrix. Let's import that from SKLearn.me, import classification report and also import accuracy score and F1 score now executed. Let's start the training process with logistic regression. So let me take logistic regression. So let me take a variable model underscore logistic equal to logistic regression. So this and all the parameters that does commonly used in the logistic regression. But one thing you need to keep in mind is that logistic regression is a linear model and there will not be much more hyperparameters to tune them. However, there is one slack variable sees there. And using the slack variable C, you can tune the logistic regression. But anyway, let me take the, what are the default settings are available? Let me take the logistic regression now fit my model using x train and y train. Let me take that model underscore logistic dot fit and this provide extra comma y train. What you're doing in this process is basically you are training a machine learning model. More precisely, your training logistic regression executed. So done so my logistic regression has trained successfully. Let's look into the accuracy score and also the F1 score for both my training as well as my test set. The reason why I'm checking the accuracy and F1 score for both training and testing is to check whether my model is overfit or underfit. Most of the cases logistic regression is underfit model. Anyway, let's look into that. For that, let's take the y underscore predict, underscore, train, a model on the school logistic jog predict. And what do you do pass here is that we have to pass the extreme, so with the training data and we can get the white trend results. Similarly, y underscore predict underscore test. Model, underscore logistic dot product. Let's kill x test. So with that we can able to get the predicted results for training as well as for testing data. So let's calculate the accuracy score and F1 score, accuracy score for training. So ACC, trained equal to, since we already imported that accuracy score, let's use an accuracy score. And what I need to provide here is y true and y productive. The y true values ease my trained for the y predict train. And with that, I can get the accuracy of the machine learning model for the training set. Similarly, let me take the test accuracy, which is what my accuracy score. And let's pass y underscore test comma y underscore, predict underscore test. Similarly also calculate the F1 score. F1 score is basically the combination of Precision and recall. It is also one of the most important metric and that is widely used to validate your machine learning model. So let me calculate the F1 score. F1 score for trained equal to F1 score. And what they do is that I just need to provide the y true. Y true is my y train for my predicted value of train. And the one thing I need to provide here is average. By default, it is assumed that the data is binary, but my data is not binary. So that's the reason I need to provide some average to macro for multi classification data. So I'm providing evidence to macro, which is generally used for multi-class application data. And similarly, let me also calculate the F1 score for test equal to F1 score. And that's going to be equal to y test. And the predicted value is white predict test. And also provide average to macro. That's it. So we have successfully calculated the accuracy and F1 score. What we will do, let's display friend accuracy. For train that's going to be equal to ACC underscore train. Similarly also print accuracy. Test equal to ACC underscore test. Let me copy and paste it here. And this is accuracy instead of accuracy. Let me put F1 score and Evans code here. And this is not accuracy terrain. This is the F1 score train and F1 score last year. You can get, let's execute that. And you can see here, and what we can see is that like novae God, 73 percent accuracy for the training data and 68 percent accuracy for the test data. Obviously, it's a good result actually with the linear model, you can able to add to the 70% accuracy. It's a good model. What I will do, instead of displaying the so many float values, let me display only the two decimal points. For that I can use Parson tail zero-point to F, which will define, which will display only two decimal points. So let's copy and paste it. Paste it, and paste it. Okay, So dove comma, let me put percentage executed. So with that you can see we got a two decimal points. Since I just want to do the same thing for the support vector machine and random forests, even for me voting classifier. What I will do, let me put everything in one function. So let's select all and put some indentation. Now, what I need to provide here is this is what the gatt report. Okay? The inputs for the get report will be my extreme y train, x test and y test. So this is what basically I need to provider and I can able to get the accuracy train accuracy test and F1 score for train and test respectively. And this is not a logistic regression anymore, and I need to replace that with some model. And let's copy and paste this because that's not logistic regression anymore. Okay, Now let's execute this. O B have some syntax error. Let me put semicolon here, now executed. Got it. Now we can use this get report so that we can get the accuracy and F1 score for train and test. Let's provide model comma x train, y train, and expressed some widest. Let's pull out all the values. 0. This is not model, this is Marlon rescaled logistic. Now you can see that we can able to get the accuracy train. I could as a test accuracy F1 score train and F1 score test. Okay, so we got some results. Let's also do it for support vector machine and random forest. In the next lesson, we will see how to train the support vector machine and random forests to until then, happy learning. 44. Machine Learning & Evaluation - Support Vector Classifier, Accuracy and F1score: Welcome back. Let me also train my faces with support vector machine. Support vector machine is one of the most widely used model, particularly for image processing applications. Let us use a support vector machine and train it. And what do you need to consider is, as we see, okay, Now model and Oscar SVC equal to the model name. The object is SVC. And here are the few hyper-parameters. One is C, slack variable is one other hyper-parameter is definitely used to tune my support vector machine and also kernel is RB of the, one of the most widely used is radial basis function. I really don't want to change that because we can able to twist and turns with an infinite number of dimensions with RBF and one more hyperparameter which I really interested. Gamma. Gamma really plays a very important rule for getting the best results for support vector machine. For timing, what I will do is that like, you know, let me use or what are the default settings that was the support vector machine. Later on in the parameter tuning, we might find out the best hyperparameters. Okay, let me set all the default hyperparameters that was already available. But one thing what we will do that we said the probability equal to true. Now let's train my support vector machine model underscore SVC dot fit. And what I wanna do here is that I need to pass extreme and y train executed. That's it. So we have successfully trained our support vector machine. Let's get the report of support vector machine. Let's copy this and paste it here. And what it did provide here is that I just need to provide the insert of logistic regression, descend model underscore SVC. Let me execute it. Awesome, right? You can see the train accuracy of the support vector machine with a default hyperparameters is 0.84, that is 84%, whereas in the logistic regression it is 74 percent. And the test accuracy is 71%. It is improved compared to the logistic regression. But one thing we can say that the support vector machine is not overcooked it. Now this is how we can train the support vector machine model. I will see you in the next lecture with 11 machine learning model that is random forest. 45. Machine Learning & Evaluation - Random Forest, Accuracy and F1score: Welcome back. Let me also train the random forest and get the report of random forest. So let's take the model under scope, RF equal to the random forest classifier. And obviously there are a lot of hyperparameters that was there, like number of estimators, criteria, max depth and so on. But however, we are not at all considering all these things at the moment. A maybe in hyperparameter tuning, we might consider all those things. Okay, for time being, let me take the random forest classifier and let's train my model. Moral underscore RF dot fit. What they do is that we need to provide moral underscore extreme comma y train. Executed. Done. We have successfully train our random forest classifier. Let us get the report of this. Copy and paste it here. What we will do, Let's replace this model underscore SVC with more than underscore RF executed. And what you can see here is a train accuracy of the random forest is a 100 percent. Where does the test accuracy is 71%? Even though the test accuracy 71%, it is not a good recommendation to go with the random forest right away. The reason because is we can see my model is highly over-fit. So we need to do some kind of a parameter tuning to get out of this. The one thing what you can do is that like hyperparameters, probably the number of estimators. If you reduce the number of estimators in sort of a 100, you can select somewhere between 10. Maybe. You can see your accuracy is reduced, but still you can see it is highly over-fit in nature. That is, strain accuracy is 99 percent date, whereas test accuracy is just 56 percentage. Maybe with a different hyperparameters, we need to check what exactly the parameters we need to consider. Maybe with a different hyperparameters. If you tune that, we might get some good accuracy for time being. So this is what the report, what you can see is that random voters, these highly over-fit and the best model out of these three I can found is the support vector machine for order by logistic regression and the random forest. He's at least even though most of the people will not agree with my statement. But for this data, random forest is not performing really well. So that's the reason, like, you know, if at all I want to do the ranking support vector machine one, logistic regression and random forests, maybe with a different hyperparameters of random forest, we can still able to get the very good results. In the next lecture, what we will do, we will combine the three models using the voting classifier, and then we will do the parameter tuning until then, happy learning. 46. Machine Learning & Evaluation - Voting Classifier: Welcome back. In the previous three lessons, we see how to train your machine learning model with machine learning algorithms. Now what we will do, we will use is voting classified and combine all the three machine learning algorithm. You can use n number of machine learning models and we can combine this. One of the most popular technique using Odean classifier. I'm using the voting classifier and combining the three algorithms, logistic, support vector and random forest. Let me use this. So model underscore voting equal to voting classifier. Voting classifier is one of the ensamble learning technique and we can use it to combine the machine learning models. So here we just provide the estimators. Here we need to provide the estimators. So estimators a way to provide the estimators in our list. So let's take a list. Now let me define the mission learning models in a top of. The first one is logistic regression. And let me set the logistic regression. Logistic regression. Next is support vector machine. I am. And what I need to provide here, SVC. And make sure you said the probability equal to true. And one more machine learning model, a random forest RF and which is random forest classifier. But that's it. So this is how I need to provide the more estimators for malting classifier. And the next analyst I need to provide here is voting method. And the voting method. There are two kinds of voting method is being there. One is soft voting and second one is hardworking. Couple time being that we use a soft voting. That's it. So this is what the parameter settings of voting classifier. Let me execute it. Now let's train this voting classifier model. So take this voting classifier dot outfit. And what I want to pass here is x train and y train. That's it. Let me clear this. Done. So we have successfully trained our voting classifier model. So let's get the report of the voting classifier model. Let me copy this and paste it here. In shutoff model underscore RF. Let me give moral underscore voting now executed. So this voting classifier is basically the combination of three models that is random far as support vector machine and logistic regression. And what we got here is a train accuracy is 94 and test accuracy 70 percent age. And still what I got here is my voting classifier is basically the overfitting model. The reason of getting the award winning model is because of the random forest. That's the reason there is a one more hyperparameter in the voting classifier is weights. Let me provide the weights for each and every model. And the weight I just want to provide based upon the ranking, I need to provide the more way to the support vector machine followed by logistic regression and random forest. So let me do one thing. Let me give you the more weightage. For example, for logistic regression or logistic regression. Let me set 24 support vector machine. Let me set 34 random forest, let me set one. So what I want to go do here is that more than a value you have given means more weightage you're giving to particular classifier. So you can see the index number 2 e, which is which I given the more weightage. That means for support vector machine, I have given the more weightage and for random forest I have given the less weightage. So that's what I'm going to do in this case. Now let me execute this and train the model. Get the report. Here we go. Now you can see that instead of getting the train accuracy for 94 percentage, now we got a train accuracy to 88 and test accuracy to 70 percentage. Okay, but still we can still improve this by using the best hyperparameters. I will see you in the next lecture on that. Until then, happy learning. 47. Grid Search Parameter Tuning: Hey everyone, Welcome back. In the previous lessons, we have seen how to train our machine learning model using different machine learning algorithms. And also we saw how to combine all the machine learning algorithm using voting classifier. Now what I'm going to in this case is that let's do the hyperparameter tuning. That means getting out the best hyperparameters from the each and every models. So here I'm going to use the grid search method for hyperparameter tuning. The first what you do, Let's import the grid search from model selection using SQL. Premise Dillon, dot model selection, import GridSearchCV, cross-validation. Let's import it. Now. Modern underscored grid, a grid search cross-validation. And here I just wanted to provide the estimator for which I just want to provide the best hyperparameters. That estimator, I want to find out the best hyperparameter voting classifier. Let's take this model underscore voting. That's my estimator. And then me to provide the parameter grid. Let me take the parameter grid, but RAM grid. What I wanna do here is that I just want to provide all the parameters in addiction. Let me create a dictionary, and now let's write down all the parameters. Here. My interest is mainly into the models like support vector machine and random forests where there are a lot of hyperparameter, so did for which we need to get the best hyperparameters. Whereas in the logistic regression, a underfit model. So we have only one variable that is slack variable si. Using that we can improve the model accuracy. But I don't want to do anything with the logistic regression. Let me use that because I want the one linear model because not to get overfit. So that's a reason let me use a logistic regression with the default hyperparameters. Now let me take the hyperparameters for SVC and basically the hyperparameters for support vector classifier that I'm going to use. Slack variables. See if you increase the slack variable, there is a possibility that you might improve the accuracy of the model. But there is one problem with that. If you ingress slack variable, your model might also become over fitting. So that's a reason. What I'm going to use is that I'll select some skew slack variable, not too big, not too small. So I'll select some smart slack variable between the values from one to ten. So let me set the slack variables. That is, since it is a SVM, so let me provide SVM underscore, underscore and I'll slack variable si. And what I wanna do here is that I do what are the values? I just want to wander test my mission learning model, just provide here. And the values I want to provide here. Anyway, one is still a default value. I really don't want to test it, but I just want to test with the variables like a 357 and even ten. Because even 10 we can able to get the good results. So that's the one hyperparameter and the next hyper-parameter, I'm interested in a support vector machine. Let me look. Oh, this is logistic regression. So here, the kernel, obviously I'll go for the kernel radius masses function. And a comma E plays a really a great important, let me take the gamma, that is SVM underscore, underscore comma c of y. I am writing this SVM, this hard. This relation indicates that you are using those support vector machines from this variable v to specify this notation to call the particular classifier. That's the reason I'm writing SVM here. Anyway, let's take the gamma. Anyway, let's take SVM underscore gamma. Now, provide the list of gammas. That is from 0.10.30.5. So those three are enough like an uneven if you increase that you, there is a possibility that your model might get underfit. So that's the reason I don't want to increase much. And let me check one more hyper-parameter, what we are clustered. The support vector machine. Okay, I think that's it. So this all the hybrid parameters I really interested in SVM and coming to the random forests, the hyperparameters I'm interested in the random forest. Let me look which obviously the number of estimators I really interested in the number. Because if you increase the number of estimators, there is a chance that your model might get overfitted. But that is might be the reason like random forests caught or feature. So let me take this. What I'll do here is take the call RF underscore, underscore n estimators. Let me call this an estimator from the random forest. Estimators. Let me send the list like 10, 20, 30, adding event that there is a possibility that you might end up with overfitting. So let me give five here, 510. And one more hyper-parameter is IRA. Underscore. Underscore is max adapt max step plays a really important here, even though the random forest is basically the full-grown tree. But till whenever your model is overfitted, then that is might be because of the max depth. So that's the reason you said the max depth Les values like maybe you select only the max depth is equal to phi or three. You can use a war fitting the model. So that's the reason that we select the max step 2, 3, 5, 7. You can do any number of values you want, but it will take lot of time for doing the parameter tuning. That's the reason I'm selecting only the values. So let me check any hyperparameters. I'm going to be interested here. The one thing, the hyperparameters, you can choose A's max features that is also its own, your own you can choose or what are the hyper parameter Yuan and also the criteria ease, Jeannie and entropy. There are two hyperparameters. And based upon the algorithm, there is a possibility, but I really don't think that really affect my model. So that's the reason that I'm leaving that part to you. If you really want to check, you can check that. Okay, Now coming to this, so voting classifier itself. In voting classifier there are two kinds of voting on it. One is soft voting and second one is hardworking. What I will do, I'll use this also one of the hyperparameters, soft and hard working. Let me take voting. And the hyperparameters are soft and hard. That's it. Those disorder two values. I just want to test ethanol, which is good at a software thing is good or hard voting is good. So this is how the parameter grid I just want to test with and just want to extract the best hyperparameters out of this. All right, So and the next, and the grid search method parameter is coding and how you're going to evaluate your model. I just want to evaluate my model using accuracy. So let me provide the accuracy. That's one thing. Next, cross-validation CV, you can set what are the cloud cross-validation you wanted a good number is between some three to ten. I'm going to select some cross-validation is equal to three. That's enough. If you want to increase the cross-validation, it's up to you. You can increase the cross validation and test your model. So I think we are done. Now what you can do is that let's set the number of jobs is equal to one. Suppose if you are working on very good computer, then you can set to minus one to run all the models in parallel. But a high, highly recommendable to go to n jobs is equal to one because I just wanted to step-by-step and not to lose all the information. That's the one reason I really want to go for n jobs is equal to 11. More parameter I just want to specify is verbose. Let me set verbose is equal to two. What it is going to get is that we can display the output during the process. Because it will take lot of time in order to find out the process where exactly I'm, we were both will be extremely important. Now what we will do, our model underscore grid is ready. Let's fit the model. Model underscore grade dot-dot-dot, hit x train, y train. Okay, The output of this we are expecting a is to get the best hyper-parameters. Let's execute it done. Now you can see that we have total 216 combination of hyperparameters of debt. And the total, the model is going to fit, 648 models is going to fit. So it would take quite a while and please be patients. Do not stop this. Browsers are the devices you need to do it again. So that's the reason don't stop it. At least it'll take some five to ten minutes. Please be patient while it is running. I'll see you in the next lecture. Once this process is done, until then, happy learning. 48. Save Face Recognition Model in Pickle: Hey everyone, Welcome back. I complicate the grid search process. It took almost 10 minutes to complete this process. And you can, here you can see that we have 216 candidates and 648 bits. Out of that, we got only one best parameter, which we got the very good score. Let's look into the best hyperparameters. So let's take the model underscore grid dot best estimator and now execute this. And here you go. You can see that this is the parameters of the best estimator for SVM. We have c is equal to 3 and Gamma is equal to 0.5. And similarly for random forest we have maximum depth is equal to 7 and number of estimator is equal to 30. So with this, we got the best hyperparameters and the voting. What we got here, a soft voting. So this is what the best hyper-parameters what we got. So let's say this model, which is model underscore, best under scope estimator equal to this. Let's look into the score of the best estimator. What we got. For that, Let's take the model underscore grid dot best score. The accuracy. What we got for this happened parameters is 0.71. That remember this, the cross-validation score, it's not a symbol accuracy score. What we got is a cross-validation score. The cross-validation score, 0.71. It's a really good model. It's a very, very stable model, means you will get the good results out of 10. Your model can able to detect seven correctly. That's really good. That's really not bad. If at all you want to still increase accuracy of the model than what you have to do is that just increased the data. As you take more and more data, there is a possibility that you will get more and more accuracy. That's what, you know, the power of machine learning. And that's what the good thing about the machine learning to. Now what we're going to do here is that let's save our best estimator in pickled format. So let's say the model, which is pickle dot dm. And here the object that I want to dumb A's model best estimator. Let's take this model best estimator. And the next is file, where I just want to mention the name of the file, which I just want to say, Okay, here I just want to save my file in the models folder. So let's provide the path of this. Let's create a open and provide the path which is in the models folder. And the name of the model that I want to save here is machine learning. And this one is face Parson identity. Ok? Dot py KL is a pickle file. I just want to say next. I just want to provide the mode of operation, which is right, which is right in bytes. That's it. Let's execute it. Now we have successfully saved our model in the models folder with the name issue learning phase underscore person identity recognition. Let's go to my homepage and have a look into that. This is what the models folder, and you can see that we have saved our model successful lead with the name shall learning underscore phase person identity dot py file. It's very small size, you can see it is just 1.83 and be awesome right. Now this is how we can train any machine learning model. I'll see you in the next lesson more on this. Until then, happy learning. 49. Facial Emotion Recognition Get the Data: Hey everyone, welcome back. In this lesson, we will see how to train the facial emotion recognition. So the data that I'm going to collect from the Kaggle, and you can find the data from this competition. I am considering the data from this challenge where you can find the data in the Data tab. There you can see if you scroll down, I can find the data of the facial emotion recognition. And one thing you need to remember here is that data consists of 48 by 48 images of only phasors. It's not like in the previous section. We have get the phasors and then we extracted the emotions, right? It's not like that because that data already consist of faces. So that the one thing you need to keep in mind. And secondly, this data consists of seven classes, like angry, disgust, fear, happy, sad, surprised, and neutral. So we're having so many measures of day with me. You can even download that directly, that data, but you will get the data in the CSV. And from CSV you need to convert that into images. You can also find the data in our resources where the images in a CSV is directly converted into the JPEG format. You can use that even directly. And third, third, we need to remember is training facial expression or emotion recognition is extremely difficult. Any deep learning or machine learning model. Even you can look into the later books as of today, the current accuracy, what we got here is 71 percentage means very difficult to achieve such a high accuracy. We may not get the accuracy nearly equal to 90 percent x. Doing that is extremely difficult. And even if we look into the top of the results, it's comes under the 30 percentage means even 30 percent accuracy of the model. It comes under the top 50. So my point here is training this is extremely difficult to do this. That is a reason what we're going to use here, that what are the model we build? We use this model to get the probabilities of each and every emotions. For example, we got the seven probabilities and we all going to just give you the probability of each and every facial emotion. For example, for any given phase, I'm going to look into the top, highest probability. For example, let's say it says smile. Then I'll just want to show you the smile. Um, how we can able to see some 30% smile in this phase. If you can really able to build a model with such a high accuracy, I recommend to submit your model to the Kaggle competition at least world can see you like, what do you have achieved? We will continue in the next lecture on data preprocessing and training our facial emotion data. I'll see you on I will see you on that. 50. Data Preprocessing: Welcome back. In this lesson, we will see how to train facial emotion. And first thing, make sure you download the data from the resources, or even you can download the data from the candle competition, but you need to do some bit amount of data pre-processing to make it clean. I already did that process and those thing is being saved completely in the emotion data. And you can open that and you can see there are seven folders or they like angry, discursive, fear, happy, neutral, sad, etc. Inside that you can find a bunch of images are there, which represents the respect to emotion, for example, this is angry. You can see all the angry photos are there here. And similarly, you can also find the happy fear, et cetera. So what I did Exactly, I prepared the data just like we did for the facial recognition. Now, let's open the Jupyter Notebook and we will work on data pre-processing and training the machine learning model. Let's open Jupiter notebook. Okay, now I have opened my Jupyter Notebook. And this is what the notebook structure what I'm having with me. And remember that we have the two programs is already created and one data preprocessing. This is for facial recognition and to train machine learning model. This is also used for training the facial recognition data. The data preprocessing technique, what we're going to use, same as we did for facial recognition. So that's the reason what I will do. Let me check this box and click on duplicate and click on Duplicate here. Now we can able to get the duplicate program of data preprocessing because we don't want to write really, because all the program is written by us, so we just make use of this. Now, check this box and click on Rename. And just rename this as three data preprocessing and name it as a motion to specify that we are using for the emotion data. Now let's open this Jupyter notebook. Alright, so we have all the code structure is already there with us. So let's use this code and do some minor changes to make the code happening. The first step is obviously we need to import all the necessary libraries like NumPy, CB2, pandas 0 is and pick up. And then also we will load our face detection modal. Please execute this. And here it's not the images folder, it is the emotion folder. Basically it is the emotion underscore data folder is where my all that data is present. And if you look into the structure, that emotion data here you can see the directories like angry, disgust, fear, everything is there with us. In order to check out path is correct or not. Let's read the data. It's not images anymore now, it is emotion data. Now select anyone. Anyone emotion, something like angry. Now select any one image out of this, probably 0 dot JPEG. Now execute it. Here we go. This is what the image we have, and this represents the emotion angry. So, okay, our path is ready now. Now we have created the helper function. Let me also execute this helper function. Now, create the data here which consists of label and this. And here we need to do beat amount of changes. The first thing we need to understand is that all my images or they're in the emotion data folder. So what we do here is that just changed that images with a motion data, that emotion underscore data. And similarly change this into a motion and a score data. And what you can get is the respective folders and that respect to folders, what we can apply this to the helper function. And please change that into this also into my emotion underscore data. And what you can get here is the vectors and effect are, is not none, don't append it. Otherwise we need to append this into the data and label. That's it. Let me execute this and extract the features from all emotion data, whatever we have. Alright, my program is running. I'll fast-forward this process and we will see the next process. Okay, I completed the process. It takes me some 15 to 20 minutes to complete this process. Now, let's look into my keys and also let's look into the distribution of the samples. What I had for neutral, I'm having to 92 rows, are they for sad? I'm having to 60 and so on. You might wonder that we have so many images in a folder, but we are unable to extract the feature. The reason is quite simple because the size of the image is very small, which is 4848 pixel. And extracting the features from that is sometimes it is difficult and model unable to extract landmarks out of this. So that's the reason we can't able to extract the features for most of the majors, but at least we got few images where we can able to extract the features. Okay, done so once we extracted the features, now the next step is save it. So this time let me rename that face features and it is my emotion. So I have saved my data successfully. I'll see you in the next lecture on training the emotion data. Until then, happy learning. 51. Train Machine Learning Model: Hey everyone, welcome back. We have successfully 0 date in the previous lecture, that is data underscore phase feature and Oscar emotion dot picker. So now what we're going to do, we will make use of this data and train our machine learning model. Our code is almost ready that in the previous lesson we already did this code. So let me take this code to train machine learning model. Let me click on the checkbox and click on duplicate and click on Duplicate again, we can get the duplicate of this. Now rename this as four. And exactly same thing. Just remove this copy one to emotion. So now we have this program with me. Let me open this program. All right, we build all the code in the previous lesson. What we will do just change the data and execute our program. That's it. First, obviously import all the necessary libraries executed. Now in the data equal to pickle dot load, what I need to just need to do is that I just need to change this data to data. This is my face features, emotion, stock, picker. Now that's the one thing I just want to save now, now executed. And let me also split the data into independent and dependent. Then let just look in the shape and here you can see like an OB How 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0. So let me reshape that into minus1, come a 128. Then we will split the data into train and test and execute this, execute this, execute this. And now we have successfully split the data into training and testing. And here you go, You can see like, you know, 80 percent training. So here we have one hundred, one hundred and thirty majors for train and 283 majors for test. Let me use the same machine Learning combinations what we did in the previous lessons. So let me execute this. And first let's train or logistic regression and look into the report of this. Obviously, as I said in the previous lessons, like we, you all going to get very, very low accuracy with this. You can see the train accuracy is 31 percent A's and test accuracy to enter the percentage. But that's obviously expected because like, you know, it's very difficult to train such a data. And let me also look into how my support vector machine is going to be trained. Let's execute this. And you can see, look into the result. And you can see the test says, the accuracy is very low. 3d 180 is attuned to a percentage with my logistic regression and support vector machine almost saying that the level of test accuracy and chemical random forest, let's execute this for number of estimators is equal to ten, and now execute this. And what he can look into the result is that we have theocracy. What I got here is 47 percentage. The one thing you can remember that 47 percentage of test accuracy is really good actually, but if the model is not overfit, then this is really, really very good result. I tried with a different deep learning models like convolutional neural networks and applying the different techniques like kernel, PCA and convolution neural networks, the maximum accuracy for the test data, what I occurred is nearly equal to 60 percentage, not even 68 is less than 60. And doing the deep learning model and deploying the deep learning model in the Cloud platform is beyond the scope of this project. So with the mission learning, we will take what are the accuracy we had God, we will take the accuracy and our main intention of using these emotion model to only give you the probability of whatever the emotion we got. For that sake only I'm using this model. Let's combine all the models using the voting classifier. Let's execute this and execute this. Now let's get the report of the model. Okay, here you can see one thing again, see the orbiting is reduced. We have the test score of 40 percentage. What I can do here is that like radios as much a row or pitting as possible, and that will be the good thing. So let's say with the parameter tuning, let's see what we can do in this case, I'll use a same param grid hand try to get the best parameters, whatever I got, high cross-validation score. Let's execute this and execute the grid search and execute this. Now, let's fit the model for 216 candidates. It will take a time, I'll fast forward this process and continue after this. Okay, I finish all a process of training a machine learning model. Now, let's take the best estimator and also print the best score. And what I got here, psi got some 32 person is what the cross-validation, I think it is better like 32 percent compared to my support vector machines and overfitting. The cross-validation score is 32 percentage. Okay, it, It's not that great model, but it's okay. So what I'll do, I'll use this model and I will save this model now. So what exactly? I just want to chain the name mission learning, and this is a person identity. I'll replace that with face, emotion, dot pickup, but that's it. So this is how we can able to train the model and save the model. Let's execute it down. That's it. I'll see you in the next lecture on how to pipeline the model until then, happy learning. 52. Load all Face Recognition and Detection Machine Learning Models: Hey everyone, welcome back. In this previous lessons, we have seen how to train our emotion recognition model and face recognition model. So in this lecture, what we're trying to do is we are trying to build a pipelining the models. Means you are combining all the machine learning models and deep learning models, whatever you used here, like face detection, extraction and even the face recognition model and emotion recognition models. So we are combining all the machine learning models and deep learning models and build one pipeline models. So that's what we're going to do in this case. And also we will test the model with the sample data I'm having with me with a few images like Joe Biden, Trump, Obama. And we also test this image to the Angelina Jolie and Leonardo DiCaprio for that, Let's see, like in all what is the emotion and the base recognition that my model is going to be work here. So that's what we're going to see in this lesson. Okay, now you're going to work on new Jupyter Notebook. Let me open the new notebook by clicking on new Python 3 and rename this as five pipeline the models. Okay, this is, we are working on the pipelining all the models. Let's import the necessary libraries that was really required by pipeline all the models. So one thing, we require the NumPy because it's a dependency elaborate. And we want a computer vision library, we want a scikit-learn because we train our model in the scikit-learn and we also want the pickle is to load our machine learning model. The next step in the pipeline in the model to load all the models. So we have the four models that we are going to use in this blended models. One is face detection and the second one, feature extraction. Then based recognition model. Next is emotion recognition model. Okay, Now let's load all the models one by 1. First is face deduction model. So let me name it as phase detector and Oscar model equal to, since it is a deep neural network and we load using CB2 dot DNN, Read net from the CAPM model since it's a cafe model. So we're going to read NADH from the cafe model. And what we provide is a prototype test. And we know that where exactly these models folder and deploy dot-product x. And similarly also provide my coffee model, it which is in the models folder, and the name of the model, a rest net, 300 by 300 ssd. Let's select this next feature extraction model. So Face feature underscore, underscore model equal to CV dot DNN. And this is a tach models. So let me load the top swallows ever read NADH from DOT and just provide the name of the model, which is the models. And it is open phase and then small version 2. Okay, that's it. This is my feature extraction model. Next one is we need to load the page recognition model that is detecting the identity of the person. That is my face recognition. And Osgood model equal to, remember, this is what my pickle file and I load using the pickle file. So pickle dot load. And to provide the file here, the name of the file is the model's folder. Let me open that. So open. And the name of the file is models. Now he's Mitchell learning phase, person's identity dot picker. So this is about my file I just want to select and the type of mode is read in bytes. And finally, we'll also load emotion recognition model. So emotion recognition model, a call to pickle dot load. And it was my open. And the name of the model is in the models folder. In the name of the model here is Michelle learning, phase, emotion dot picker, and read in bytes. That's my mode. Okay, so done. So with that, we have successfully loaded all the machine learning and deep learning models which are used in the pipeline model. 53. Automatic Multiple Faces Detections: Now the next step is we now going to build a pipeline model. N pipeline model. We did already all the process like detecting and feature extraction and face recognition, image recognition, we need to combine all the models. That's it. That's the part we need to do. So what I will do, I will again write the code again for face detection feature extraction because I need to do some minor changes. So that is a reason I'll rewrite the code again. If you want, you can even copy the code even from the previous lessons. All right, So for the sake of simplicity, what I will do, Let me take one sample image. And to that sample image, we will do all the necessary things. Then we'll create the helper function that is pipeline the model. Okay, now let me consider the image from the test data. Image equal to v2 dot m read. And my image is in the IMB data folder to some attached images. I'm going to take this test amaze dot JPEG. Let me show you what exactly these images. So Civitas dot m show. And this my image. Now IMG and CB2 dot weight gain of 0. And see me too dark. Let's try all windows executed. Okay, So this is the image of Angelina Jolie and Leonardo DiCaprio. Let's see whether our recognition model and emotion model can able to detect the face and recognize the emotion. For time being what I will do, I'll copy this IMG to image the coil to IMG dot copy. Next step or what I'm going to do here is I just want to know the height and width of this image. So hedge comma w equal to IMG dot shape. Select first to dump. The next one we need to do the face detection here is deduction. What you're doing here is that we are going to use this phase detector model. Before applying this to the phase detector model, we need to calculate the image blob that's going to equal to CV to dot DNN and blob from image. And here is to provide all the settings like images I am. And the scale factor is one and sizes 300, 300. Next means a fraction value is we just need to provide the RGB mean, which is my 1, 0, 4, 177, come a 123 Next. And it should provide the swap RB to false. Next also crop equal to false. So with that we get the image block. Now we need to set the input for the phase detector model. So this is my phase detector model and set the input and input is going to be equal to image underscore blob. Next we'll get the detections equal to face detected model dot forward. So with that, what we can get is that we can get the deductions here. And remember, we already know that the number of deductions you're going to get here is 200 deductions. But we make sure that we have some deductions. So that's the reason what you're going to do. Just specify my length of detection should be greater than 0. So length of detections should be greater than 0. So then only I need to enter into the loop. Now next one is we have the 200 detections are there. And out up to a 100 detections, we will select the detection with a confidence score greater than 0.5. In that case, what we need to run a loop like for i comma y comma confidence. And basically you're getting the Conway comma competency. Let me take the enumerate. And what you can get is detection. So any rate will generate the I and detections. We can extract the competencies in order to get the confidence it is 0 comma 0 comma colon comma two will basically get the detections here. So now we got the competencies. Next step, we need to set the validation, like just select only the phase only if you have a confidence score greater than 0.5. So that's the reason. If confidence is greater than 0.5, then only use specify that it is as a face. Now, once we got the confidence, then we take the box generally will get the bounding box here and check take the bounding box from the detections with 0 comma, 0 comma. And this is my ith confidence. And let me take the bounding box from three to seven. Next, we need to multiply this with the width and height of the image to denormalize it. So let me multiply it with np dot array and just need to multiply with width, height, width, and height. So with that I can able to get my bounding box. So next let me extract is it is the statics start y and x and y, that's going to be equal to, I'm going to consider the box and change the datatype to integer values. So with that, I can able to get the static start y and x and y. We got the data points with me and what he can do first, let's detect the face here. So for the face detection, let me draw a bounding box to this IMG. So let me take this CB2 dot rectangle. And now I'm going to take this image and the name of the image IM, Ultimate take this image and the points are startx and start y. And similarly, my one we're diagonal point here is and x and y. So the next part, when it just need to provide the color here and the color is lipid, take the green color, it is 0 comma five comma 0. So with that, I can get my rectangle box. Let me display this. So instead of IMG, let me display this. And this is what my pipeline. So model. Okay, let's execute this. Oh, we got some error. Not invited his end white. Okay. Alright, so we can able to detect the face of Angelina Jolie and Leonardo DiCaprio. Perfect. 54. Combine Predictions of all Machine Learning Models: All right, Now the next step, what are you going to do is you need to extract the features from the pace. Let me close this. Now, what I wanna do here is feature extraction. We know how to do the feature extraction and we are going to use this phase feature extraction model to extract the features. All right, so first one, what do you do is that we need to crop the face. So that's the reason let me drop the phase in order to grab the face. Let me take phase underscore ROI equal to, let me take the image IMG, now crop it like an expedition I want to use here is start x, start y and x and y. Let me start with the why. So stat, wine, colon and wind comma. We are going to take start x, colon and x. So with that, we can be able to get the face ROI. Now with this phase ROI, we are going to extract the blob. And that blob you're going to set input to my base feature extraction model. So let me clarify, calculate now. So now let me calculate the blob here. Phase underscore blob. Let me use exact settings which are used in the data preprocessing for the settings that are using data pre-processing distributed dot DNN. And it is a blob RAM image. And what entered to take here is phase RY. Now the scale factor, I just use this one by 225 next day. The size I just want to use here is 1906 by 96. Let me take 96, 96, 96. And the next one, we will take the mean subtraction RGB to 00 comma 0, comma 0. Then we will set up IRB to true and crop to true. So let me set swap RB to true and crop also let me set to true. That's it. So now we got to the place VOIP. The next step is that we need to set the input to my base feature extraction model. So this is my model. Let me take this model.py, that metallic set input. And here the input is the phase block. Okay? So with that we can able to get my set input. And the next step is take the borrower and get to my features. Now vector equal to face feature model dot forward. So with that, what I can get here is the vector here. So this is more the peaches I'm going to get for this phase. Now, the next step you are going to do here is we are, we will predict with machine learning model, will predict the features with the machine learning model and get the face name and the emotion him. So let me take that. Now. Face name. We can get the face name that's going to be equal to. We will take this machine learning model here. That is, the machine learning model I want to apply here is face recognition model dot predict. What I wanna do here is I just need to provide my vector has. So that's it. So with that I can able to get the vectors. Let me also calculate the probability means a score of the face. So let me take that phase col, equal to face recognition model dot. Just need to provide the predict probability. And with that, we can able to get the probabilities of each and every phase. And what exactly I want here is that I just want to take the maximum out of this so that maximum, He's what the face, the probability of the face name. So with that I can able to get the face. Let me print this value. So print phase underscore name and also print phase underscore score. Sprint. Now execute it. And here you go. What you can see here is that we got Leonardo DiCaprio. The probability what we got is 81 percent age and Angelina Jolie, and the probability what we got 0s, 58 percentage. Okay, but what is Angelina Jolie and what is delay in our DiCaprio? Let's see. What is machine learning model able to get this? Let's look into that. For that, what exactly we will do. We will put the text here. Let me put the text using submitted dark for text. And here I just need to provide the image for which I want to put the text which is image, in order to set the text here, we need to provide this text here. And as you can see, this is getting in an array. So let me take only the first value, which is 0. So with that I can able to get the like No Leonardo DiCaprio here. Now, let's take the next year. Let me put this text. The text is going to be equal to 4 timing. Let me put the texts or get taxed underscore phase equal to, let me create some string. And here I'm going to insert that. And also let me also insert the probability score out of this. Okay, for that, let me take the format and let me insert the face and a scholar named phase underscore score. So now what I can do here is that this face name, it comes here and this phase coil comes here. And in order to get the values in person day, just multiply that into percentage. And this one here, let me mention here is percentage here. But in order to get the two decimal points, what I will do, Let me take colon and two. We can get the two decimal floating points or one decimal floating point out. You can put 0 decimal floating point, isn't there? The integer values. Okay, So with that, I can get this one. So let me take the text face and where exactly I just want to display is horizontal. Let me take the statics and the start. Why? That's my artisan. It is start x, start y, or my origin. Next one, I just want to take the font face. Okay, let me take the bond pays to basically what kind of font I just wanted to give here, electorate exhibited dot font. And I'll take plane. Next one is to put text is Font Scale. Let me take two. Next color. Here. I'm going to use some white color, 255, 255, 255. With that, I can get the white color. Next is thicknesses to pixels. So that done so with that we can able to put the text on top of the image. Let me execute this. Okay, now we can see that it's a perfect, That's Angelina Jolie. Jolie with probability score up 59 percent age, and Leonardo DiCaprio With the probability score of 82, 8%. That's really good, right? It's a good model, but I'm still, I just wanted to mention you that what are the model we built? It's still not perfect, but we can improve the model with some other techniques like deep learning. Anyway is similarly, let me also display emotion. Emotion. And that's going to be equal to, in order to get the emotions, I'm going to use this emotion recognition model. So let me take this emotion recognition model here and simulate just like we applied to the predict the mission learning just like that, we'll take the emotion recognition model here to get them ocean, take the predict and pass the vector 0 to get the emotion. And next what we can do here, we can get the emotion. That's it. So with that, we can able to get like, you know, the emotion here. So more precisely that make you Emotion name. In order to get those core of these are probability score of this, let me take a motion score equal to emotion recognition model dot predict crop a and a to provide a vector here. And take the maximum out of this, which can able to get the emotion score. So let me also print this emotion and name and also brand emotion score. And, okay, and here you can see that we got for Leonardo DiCaprio, we got the motion is neutral. Okay, That's a really cool. And the probability we got he's 22 percentage and bottle Angelina Jolie, their motion what we got is happy. That's correct. Okay. Let me display on top of the page here. It can display on top of the phase. Let me use the same, exactly the same thing, text-based. And let me also take the m. This one is text am motion. Now here I just want to replace base name with emotion name and face code with emotion score. With that, I can get this. And also let me take this put tax year and the text introductory text place. Instead of this text phase, replace