Hi and welcome back.
So in this section, what we'll be doing will be creating our very own facial recognition lookup app.
So what it does, you have a directory of images of people and then you can input a new image and match
that image to one of those persons who we have in our database.
So let's get started.
It's quite simple and quite interesting and fun.
So just download some of the file and to just a cascade classifier that we'll be using.
I'll explain to you why next?
We just create some major function and load some libraries, namely the open CD library.
And the reason we've loaded that up and see the library is because of what we're going to do.
We're going to take the faces from this directory of people.
So we have faces like J.Lo and Lady Gaga.
And what we're going to do is we're going to use OpenSea, these horror cascade classifier for face
detection and crop just to phase out of these images.
That's because the face is trained only on images of faces, so we need to get as close as possible
to adjust the face of the person for this to work well.
So let's run this and what this does.
This creates over directory called groups of faces with just a face of these four images, so it's just
a small database for now.
Just for images.
Here we'll be using and you can see this.
These are the cropped faces that had extracted.
So let's get going.
We don't need this.
So what do we do next?
You've seen you seen this before.
This is all of the cool in one block here where we're creating the big, fierce network of functions,
loading on modules here and then loading the weights onto the network and then getting the scripts and
model out of it.
And that's it.
So we have a we need more model.
We need more descriptive model model in this case, though, so let's run that.
There we go.
So the model has been loaded.
Now we can test it with a webcam.
So this is only going to work for me unless what you could have done is in the people there.
Actually, that's those who initially upload a picture of yourself here and then this will work.
So let's take a look at it.
So this is some code here, some Python code that allows you to take a picture up from your webcam.
So let's try this.
And no, we have to run this clock to get the snapshot.
All right, so that's me and my messy bedroom in the back and my drum kit behind me.
So let's take a picture.
Not the best picture, but it is what it is and know what we can do.
We can take, we can what we're doing here.
We're going to go through.
Our group's offices are actually here.
So we're going to go get all the model predictions and embeddings out of it here.
So we stood out in this dictionary called all people's faces.
And that says, and we print out seeing all the representations have been retrieved successfully.
Then what do we do?
We create our cosine similarity function, which we've done before, and we take the photo.
The photo from the webcam that's called photo here.
And then what we do, we extract a face from that photo, just a cropped face as well.
And then we pass it through the similarity function here.
The cosine similarity function to get the similarity score.
And then if the score is less than this point tree five threshold, which we defined here, it's probably
not.
That's to put the hardcoded number here can probably put a variable to store that.
And then we just draw the face rounded ones that recognize and put the person's name on the face as
well.
Once we have recognized it.
So we put the name in the text by running this here, and it's extracting name from the database directory
to group of cases.
Sorry, because remember its name, it's face on the school name.
So we have two names here, so let's run that code and let's see if it works out and tested it on this
image, but it did work successfully.
Awesome.
So that's great.
So hopefully you can try this on yourself and see if it works next.
What we're going to do, we're going to do the same thing, but we're going to run it on a video.
That's the TV to Friends TV series.
We'll just take the images here.
So those are deep characters here.
We just take give them one sample each and then what do we do we?
So one thing I forgot to do in the previous minute was deleted the stored files in a directory because
it because it causes this code to crash.
So just run this line here and this will remove all these stock data stored files that MapQuest creates
when compressing files, unfortunately.
So if we run this code, know what it does, it crops the images of the friends of characters.
Here you can see it's actually quite blurry, but these are pictures from the actual video itself.
So that's why it's not the best quality.
Does it all for friends characters?
Now what do we do?
We do the same thing that we did previously.
We just take a look at grabbing the faces from a video file, so we're going to play a video file and
each frame.
We're going to grab the faces and then put the names on that frame as well and then write it back to
the video.
So you would have seen a lot of this code before and above, as well as this part of it would have been
in the open series section of this course.
This is how we create videos and open and open TV.
So you can actually download the video after and look at the look at the annotations that a facial recognition
app has put on the faces.
So let's run this, and the cool thing about this is that it outputs the images right here.
You can see it slowly.
It's going to a good start.
So we can take a look at them as they go through.
So you can see got Chandler and Joey, right?
That's good.
They got them right.
This is frame by frame of the video.
So that's why it's not moving that quickly.
But if you leave it here and I'll speed this up after for you guys, you can see it work all the way
true.
So that's it for this lesson.
I hope you enjoyed it.
Facial recognition is very cool, and they have some very good networks like features you face out there.
Next, we'll take a look at FirstNet and what what will pay to watch.
And then after that, we'll take a look at a very cool library of deep fees that allows you to utilize
a few different deep learning facial recognition packages very easily within Python.
So stay tuned for that.
OK, so that's it for this short clip will be you enjoy this less than anybody can see and hear.
Actually, it's still running, but you can see it's getting all of the faces here.
Sometimes it drops how it feels just like that, dear.
That's when it falls below the point three point three five threshold that we've set.
So I'll stop this lesson here, even though this is still running, and I'll begin the next lesson,
which is also the next lesson, which is to PyTorch first that chapter.
So I'll see you there.
Thank you.