Hi and welcome back.
So in this lesson, lesson 41, we'll be taking a look at using the Python library called deep deepfakes,
which is a very cool and useful library for extracting things like age, gender expression, as well
as performing facial recognition with a number of different models they have built in.
So let's get started.
Let's take a look.
So open notebook 41 and we'll begin.
So firstly, we have to install deepfakes here and also uses deliv as well.
So let's install both of them.
Actually, they don't need the.
But I use the elevators to test and demonstrate a couple of the facial landmark activities in this lesson,
because in this lesson, what we're doing, we're first doing facial landmarks.
Then I'm age, gender, emotional expression, ethnicity, using deepfakes, and then we're going to
perform facial similarity as well as facial recognition.
Also, we do have to change the RAM to Hiram, which I forgot to mention this firearm by default.
So that's good in this notebook.
So deepfakes has been installed so we can continue with listen.
So this is this is just so immature function and we look at all libraries here.
Next, we have to download our facial landmark library because in case you missed it before you skipped
that part of the course which delivers facial landmarks section, I'm just going to go over it quickly
in this section here.
So what we'll do next is download all our test images that we'll be using.
So let's do that, and now we can demonstrate the official landmark project.
So this is quite simple here.
So to demonstrate the official landmark project, what we need to do, we need to have a detector and
a predictor.
The detector, basically the text office and from an image, just a bounding box around office and a
predictor signs and landmarks onto that fire.
So we have 68 landmarks here.
So you used have just specified a path to this to deliver predictive facial landmark model.
And we have a detector and our predictive lodo image grayscale it.
Get the faces out of it here.
And then for the faces in that image, we just passed that face that cropped face to the predictor and
then we draw the bounding box around it.
And then we just draw circles, tiny circles around to represent each facial landmark.
So that's one that I we'll take a look at the output.
Now there we go.
So you can see, here's my face here and you can see we have all the landmarks around my eyes, my nose,
my lips, a little lips a bit off.
That's because it's a sight on view.
Also this I'm not sure this is supposed to be all around at first, but it cuts into motion a bit.
But it's pretty good.
I mean, it works best with a full frontal and face, but this is pretty good too.
Captured my eyes, my eyebrows quite well, quite well.
So now what we're going to do, we're going to use deep fears to do something very cool.
We're going to get each gender, emotional expression and ethnicity out of it.
So the reason we have to download all models is that sometimes at least the last time I tried it and
deface it supposed to download the models automatically.
But links were dead for some reason.
So I had to capture them and then download them and put them to my Google Drive so we can use them here.
So let's download all those models.
It doesn't take very long because Google's backend has a very fast connection, as we could see here.
Even though those models are quite big, they're about 500 megs each, which is quite large.
Actually, you can see that the way these models can't work in embedded devices like cell phones, they're
just way too big.
And this is our race model, gender model, age model and tiny one is the facial expression model.
OK, well, maybe maybe it might work, let's try it.
I'll fix this error for you guys afterward.
Let's see if devious models are there anyway.
And I believe that all because this looks like it's running.
Yeah, it's downloading the model anyway, so we didn't need to do that, so they fixed a bug where
it was and downloading these models before.
So apologies for that.
OK, so it took roughly just over a minute to download all these models from the deep Facebook GitHub
repo.
So now we can use this, so what we're going to do.
We're going to get the emotions.
We're going to run this and get age, gender, race and emotions out of the deep face module.
So to do that, we just load an image using open TV here.
So we have the image and then we can just actually don't need an image for your face.
We just need an image path, which we declare here.
And then we just specify what we want to analyze in this area here, this list, and then we can get
our object and then use it, returns a dictionary with some type of file and then we can just use pretty
print to print the results.
So let's run this and take a look at the output.
OK.
So this is pretty cool.
You can see how much information it gives us from this feature.
Yes, I'm still here, club.
So you can see dominant emotion is sad.
Even though she's inside here of dominant races.
Asian, she's Arab Indian emotion.
You can see the attributes different scores that each emotion can see attributed the most to, said
the neutral.
That gender woman is quite right.
You can see the different races here.
So Indian did get a high school as well, as well as Latino has spent Sponeck, which she does have
some in her as well.
So and then you can see this is a region, this is a bounding box for the face as well.
So let's create a simple function that can display these results on the image, so we wouldn't have
to keep looking at this just on File Hill.
So let's take another image and we'll input it into our deep office analyze and we can get a nice little
descriptor like this sitting on efforts to edge happy Latino, Hispanic and serious not to correct but
close enough anyway.
So you can see this is quite good, though it's quite useful, isn't it?
You can do a lot of analytics with deep face.
So now we can what we can do.
We can change buttons and you can see they have several different backgrounds here for deep face.
And they may have more if, if, if, if because they're constantly updating this library so they might
have more packages available.
So what we can do, we can switch beckons here so you can set up using, we can use SSD, we can use
open OpenCV, dylib NTSC, MTC and what you've seen before that some FirstNet, as well as a new one
you're unfamiliar with that's in office.
So we'll demonstrate the results here with SSD.
So let's take a look at that.
So it hasn't dealt with the model, as you can see here.
And then we get here, so we get territory inside.
I'm actually a bit older, so this is quite complimentary.
Let's try a different model now.
Let's try MTC, CNN.
There we go.
So, again, territory neutral Indian, so you can see this is looking quite good.
And you can experiment and mess with different modes and see which gives you the best results, although
they generally all have strengths and weaknesses, so it depends on your data sets.
So now what we're going to do, we're going to perform facial similarity.
So deep is has a verify function that compares images here and returns a result.
So the result is is verified and result here.
So that is verified.
True means that you're the same person verified.
Being false means that there are different people.
So let's take a look at the results.
So again, we have to don't lose the weight, so again, apologies for the way it would.
This might just be about 30 seconds or so.
OK, so we've got a results here, and you can see it verified its true meaning that the two images
are compared with my wife that you are to see in person.
And you can see some of the metrics they use that are trash values was point for obvious Fiji faces
a comparison which we've used before, and Kerry's similarity metric was Hussein and Verify being true.
Final results here.
So that's pretty cool.
So what if we use different facial metrics you can use cosine Euclidean?
So let's do Euclidean comparison on the same images as well, and you can see verified as true as well,
but you can see the threshold has changed.
Now it's 0.6 and still within the threshold.
However, they do change values according to which metric you use, and you can see these are two different
metrics that are available here.
We have Cosine Euclidean and look at Euclidean L2 norm.
So let's try that as well and get the results.
And they're all at least for these images here.
They're all giving us the correct results.
So that's pretty cool.
So I don't think I need to do this.
This in defense mode seem to be downloading well.
So let's perform visual facial recognition.
So what we're going to do, we're going to keep using a deep space DVR.
Sorry.
That's fine.
We have an input image here and then we have a directory of images here called Trading Spaces.
That's what we downloaded initially and we've downloaded some set of files.
So we have a bunch of faces here.
We have what six pictures of my wife Maria, one of J.Lo, one of Jennifer Aniston, one of Lady Gaga,
and what is going to what we're going to do?
We're going to get a nice little output data frame where we have the cosine distances for each one.
And we're going to use the SD backend for this experiment.
And you can you can feel free to try different experiments and you can see obviously this is the same
as this one.
So the cosine distances minus 10 to the minus 16 Mexicans.
See all the images with area have gotten very low scores, and the one with J.Lo got the Louis.
So this is pretty cool.
So.
So let's now try it with a few different models here so we can actually know loop through all of the
different models.
So we have PGD fierce, isn't it?
Open, fierce, deep, fierce debate.
OK, fierce of dylib.
So we have a ton of different models we can use in the deep Phastos Find module.
So what we do, we just specify the model in here.
The detector back in is what we use to detect office so we can use SD or we can try dylib for change,
and it's going to basically give us a similarity scores now for each one.
So let's take a look at this.
So it may have to download some models here because we didn't download all of the models that we'd be
using.
So the first one to download it was that to deliver predictor for landmarks that are downloaded, FirstNet
was here.
OK, so there we have all these vast results, so let's take a look at what's happening here.
So it took a while to run, took about three minutes because we had to download all these models here,
the ones we downloaded, the models, actually, the inference was quite fast.
So you can see what we're doing.
We're comparing the input image here, which is the new on the score one, and we're comparing it now
to all of the images in the in the directory.
So we have an idea of four, three, five six two and so on.
And you can see the reason why it is no none of the other JLU images.
Unfortunately, it is because our first detector did not detect them.
So let's try SSD, and hopefully that gives us some more detections.
And you can see, yes, so it got the global one there, but didn't get it for the others.
But regardless, let's see how we interpret this.
So you can see this is a model of being used here.
This is the same distance we've seen before.
Again, this is not the first, and it's called cosine.
You can see the distances here for each one for open fields didn't get any results for some reason.
Similarly, 50 percent divided.
But for obvious, we got the results as well.
So you can see it says in the video.
One is the closest, which makes sense because that's the original image, and you can see that in order
similarity.
So it's it here.
So you can see they all have slightly different ordering.
One five four three one five six.
This is one four five, so it's one in five do appear quite similar.
So let's take a look at what one in five or six does seem to be the most similar images.
OK, so I guess those do look a bit similar to me, although, I mean, they are all of the same person
anyway.
So that's it for this lesson is a very cool tutorial in how you can build your very own MongoDB facial
recognition engine using deepfakes as well, so you can check it out.
And that's it for this lesson that what we'll do next will start an object detector lesson.
So we'll go through some slides of the material for the different types of networks, types of object
detection, and then we'll begin the many lessons we have on object the detection.
All very cool.
So I'll see you then.
Thank you.