Hi and welcome back in this lesson, we'll take a look at a very cool project, which is using a pre-trained,
fig faced Siamese network and using it in cameras to recognize faces.
So let's get started and we do a number of things in this lesson.
Let's just recognize faces, but we do facial similarity, as well as taking a clip from the Friends
TV show and recognizing the characters on screen.
So it's pretty cool.
So let's get started, and just for your reference, we're using the video fierce model fist.
Yeah, this model that was published by these Oxford researchers in 2015.
So if you want to take a look at the paper, you can take a look and learn more about this model.
So firstly, to get started with this lesson, we have to download the test images that we'll be using
for this experiment.
So just run this module here for.
Run it and import our libraries, which you will do as well.
And then what we do here, we define the fierce model architecture.
And you can see this looks quite familiar to a big architecture, and that's why it's linked to video
device.
It basically is a copy of that network with all the stacked convolutional layers here.
But however, we don't output to the classes that we want to classify.
We output to a one by two six two two vector, and that's a fish embedding.
So when we when we pass this terrorist network, it produces that output vector embedding.
But how do we get that up?
But embedding houses was were trained well.
This network was previously trained on those 2.6 million images, which you saw in the paper and in
the slides I mentioned.
So what we do?
We don't know.
So none of you have downloaded the widths.
You can now load those weights onto the model we defined above here.
So we just do modeled off load weights and into the path to what within weights we downloaded.
And that's the name of the file that we downloaded here.
No bits from director Rupert and just run that and it attaches to weights to the network.
Next, we're going to define a cosine distance function as well as a pre process image function.
But this function isn't too important to just a simple function that takes the image.
We sizes it and converted into a array so that we can pre process it or process it with our CNN.
So what we have here is a cosine similarity function.
What this does, this takes two of those vectors.
Remember the 26 22 size vector?
That's the embedding for the face.
It takes two inputs of two phases two pieces that have been converted into the into data embedding and
outputs the cosine similarity score between them.
And finally, we just have a little model.
You'll find this is a funnel model that outputs that vector, so you can see how we create a model here
with specified inputs here and the outputs and just create this model function that's across TensorFlow
for function to combine everything together.
And we get our final model that produces a big first descriptor.
So know what we're going to do in the first experiment is we're going to implement visual similarity.
So we're going to find a similarity between phases.
So let's take a look at this function.
So firstly, epsilon is our threshold value.
Whether if this is similar or not, depends on if it's more or less than this point for.
You can see that in the bottom of the code here.
But for now, this is quite simple.
Let's take a look at this network.
So we have two images as the input arguments to this function.
Then we have a visually descriptive model, and so we do that model don't predict and we just passed
some images to it.
So we have the image one here specifying right here and this is just a path that we're attaching it
to.
So we get the image one representation from that.
Secondly, we get the second image here.
Image two.
We get its image representation.
That's the embedding vector for it right there.
Then we can take these two representations and passive to or cosine similarity function to get the cosine
similarity score.
And then what we do, what we do is just create some subplots here so we can plot the images side by
side.
So let's run that function.
And now let's run a few tests.
So these are two pictures of my wife.
And you can see let's see if it tells us if the same person loops script is not defined.
That's because we didn't run this block of code.
Let's go back to it now.
Let's run this.
And you can see it give us a very good, very look similar to a school, meaning that it's the same
person, so let's zoom in slightly and you can see the resemblance.
Yes, obviously, because they are the same person.
No, let's try some more images of her.
So these are two of the images here.
Now look at this one.
These are two images of my wife, same person.
However, the similarity scores point five.
So it says they're not the same person.
Remember, if it's less than 0.4, it's considered the same person.
And if not, it's not the same person.
So this image these images here are apparently two different.
She looks two different than them for an official photo of our fidgety face similarity score to actually
hold up.
So let's try to compare to J.Lo or Jennifer Lopez.
And we can see, expectedly, they're not the same person.
And of the similarity score is slightly lower than this one when it was the same person.
Now let's and J.Lo and Lady Gaga, and rightfully so.
They're not the same person.
So we'll stop there for now.
And then the next section next video lecture, we'll take a look at facial recognition with one submitting.
So in this lesson, what we do with this have a database of pictures.
And then much of this, according to that, the database set that we have.
So stay tuned for that.
Thank you to.