1
00:00:00,090 --> 00:00:01,080
Hi and welcome back.

2
00:00:01,170 --> 00:00:08,700
So in this section, what we'll be doing will be creating our very own facial recognition lookup app.

3
00:00:09,270 --> 00:00:16,020
So what it does, you have a directory of images of people and then you can input a new image and match

4
00:00:16,020 --> 00:00:19,860
that image to one of those persons who we have in our database.

5
00:00:20,370 --> 00:00:21,590
So let's get started.

6
00:00:21,600 --> 00:00:23,550
It's quite simple and quite interesting and fun.

7
00:00:24,060 --> 00:00:30,390
So just download some of the file and to just a cascade classifier that we'll be using.

8
00:00:30,420 --> 00:00:32,550
I'll explain to you why next?

9
00:00:32,550 --> 00:00:37,830
We just create some major function and load some libraries, namely the open CD library.

10
00:00:38,280 --> 00:00:43,230
And the reason we've loaded that up and see the library is because of what we're going to do.

11
00:00:43,680 --> 00:00:48,510
We're going to take the faces from this directory of people.

12
00:00:48,930 --> 00:00:52,770
So we have faces like J.Lo and Lady Gaga.

13
00:00:53,950 --> 00:00:58,920
And what we're going to do is we're going to use OpenSea, these horror cascade classifier for face

14
00:00:58,920 --> 00:01:02,700
detection and crop just to phase out of these images.

15
00:01:03,900 --> 00:01:10,770
That's because the face is trained only on images of faces, so we need to get as close as possible

16
00:01:10,770 --> 00:01:13,620
to adjust the face of the person for this to work well.

17
00:01:14,460 --> 00:01:17,360
So let's run this and what this does.

18
00:01:17,370 --> 00:01:24,510
This creates over directory called groups of faces with just a face of these four images, so it's just

19
00:01:24,510 --> 00:01:25,680
a small database for now.

20
00:01:25,680 --> 00:01:26,610
Just for images.

21
00:01:26,610 --> 00:01:29,090
Here we'll be using and you can see this.

22
00:01:29,100 --> 00:01:31,320
These are the cropped faces that had extracted.

23
00:01:33,770 --> 00:01:35,390
So let's get going.

24
00:01:37,640 --> 00:01:38,660
We don't need this.

25
00:01:39,920 --> 00:01:41,240
So what do we do next?

26
00:01:41,360 --> 00:01:43,040
You've seen you seen this before.

27
00:01:43,070 --> 00:01:49,700
This is all of the cool in one block here where we're creating the big, fierce network of functions,

28
00:01:49,700 --> 00:01:56,060
loading on modules here and then loading the weights onto the network and then getting the scripts and

29
00:01:56,060 --> 00:01:56,990
model out of it.

30
00:01:57,560 --> 00:01:58,490
And that's it.

31
00:01:58,580 --> 00:02:00,380
So we have a we need more model.

32
00:02:00,650 --> 00:02:05,390
We need more descriptive model model in this case, though, so let's run that.

33
00:02:07,490 --> 00:02:07,940
There we go.

34
00:02:07,950 --> 00:02:09,260
So the model has been loaded.

35
00:02:09,860 --> 00:02:11,980
Now we can test it with a webcam.

36
00:02:12,050 --> 00:02:18,320
So this is only going to work for me unless what you could have done is in the people there.

37
00:02:18,320 --> 00:02:24,680
Actually, that's those who initially upload a picture of yourself here and then this will work.

38
00:02:24,800 --> 00:02:25,860
So let's take a look at it.

39
00:02:25,940 --> 00:02:32,240
So this is some code here, some Python code that allows you to take a picture up from your webcam.

40
00:02:32,330 --> 00:02:33,290
So let's try this.

41
00:02:36,300 --> 00:02:39,750
And no, we have to run this clock to get the snapshot.

42
00:02:41,910 --> 00:02:47,970
All right, so that's me and my messy bedroom in the back and my drum kit behind me.

43
00:02:48,690 --> 00:02:50,350
So let's take a picture.

44
00:02:52,620 --> 00:02:58,170
Not the best picture, but it is what it is and know what we can do.

45
00:02:58,770 --> 00:03:01,500
We can take, we can what we're doing here.

46
00:03:01,950 --> 00:03:03,270
We're going to go through.

47
00:03:03,270 --> 00:03:06,250
Our group's offices are actually here.

48
00:03:06,270 --> 00:03:10,890
So we're going to go get all the model predictions and embeddings out of it here.

49
00:03:11,520 --> 00:03:15,210
So we stood out in this dictionary called all people's faces.

50
00:03:15,930 --> 00:03:20,790
And that says, and we print out seeing all the representations have been retrieved successfully.

51
00:03:21,420 --> 00:03:22,680
Then what do we do?

52
00:03:22,890 --> 00:03:27,810
We create our cosine similarity function, which we've done before, and we take the photo.

53
00:03:27,930 --> 00:03:30,480
The photo from the webcam that's called photo here.

54
00:03:31,500 --> 00:03:37,110
And then what we do, we extract a face from that photo, just a cropped face as well.

55
00:03:37,710 --> 00:03:41,580
And then we pass it through the similarity function here.

56
00:03:42,330 --> 00:03:45,120
The cosine similarity function to get the similarity score.

57
00:03:45,720 --> 00:03:50,820
And then if the score is less than this point tree five threshold, which we defined here, it's probably

58
00:03:50,820 --> 00:03:51,020
not.

59
00:03:51,020 --> 00:03:55,380
That's to put the hardcoded number here can probably put a variable to store that.

60
00:03:56,070 --> 00:04:03,510
And then we just draw the face rounded ones that recognize and put the person's name on the face as

61
00:04:03,510 --> 00:04:03,870
well.

62
00:04:04,350 --> 00:04:05,910
Once we have recognized it.

63
00:04:06,090 --> 00:04:14,340
So we put the name in the text by running this here, and it's extracting name from the database directory

64
00:04:14,670 --> 00:04:15,460
to group of cases.

65
00:04:15,470 --> 00:04:19,920
Sorry, because remember its name, it's face on the school name.

66
00:04:20,250 --> 00:04:28,050
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

67
00:04:28,290 --> 00:04:31,200
image, but it did work successfully.

68
00:04:31,260 --> 00:04:31,710
Awesome.

69
00:04:32,670 --> 00:04:33,480
So that's great.

70
00:04:33,510 --> 00:04:37,770
So hopefully you can try this on yourself and see if it works next.

71
00:04:37,950 --> 00:04:42,570
What we're going to do, we're going to do the same thing, but we're going to run it on a video.

72
00:04:42,810 --> 00:04:46,320
That's the TV to Friends TV series.

73
00:04:46,950 --> 00:04:49,080
We'll just take the images here.

74
00:04:49,260 --> 00:04:51,660
So those are deep characters here.

75
00:04:51,660 --> 00:04:57,360
We just take give them one sample each and then what do we do we?

76
00:04:57,390 --> 00:05:03,780
So one thing I forgot to do in the previous minute was deleted the stored files in a directory because

77
00:05:03,780 --> 00:05:06,240
it because it causes this code to crash.

78
00:05:06,750 --> 00:05:11,970
So just run this line here and this will remove all these stock data stored files that MapQuest creates

79
00:05:11,970 --> 00:05:14,040
when compressing files, unfortunately.

80
00:05:14,790 --> 00:05:21,300
So if we run this code, know what it does, it crops the images of the friends of characters.

81
00:05:21,300 --> 00:05:25,890
Here you can see it's actually quite blurry, but these are pictures from the actual video itself.

82
00:05:26,580 --> 00:05:28,410
So that's why it's not the best quality.

83
00:05:28,590 --> 00:05:30,690
Does it all for friends characters?

84
00:05:31,570 --> 00:05:33,000
Now what do we do?

85
00:05:33,030 --> 00:05:35,020
We do the same thing that we did previously.

86
00:05:36,540 --> 00:05:42,090
We just take a look at grabbing the faces from a video file, so we're going to play a video file and

87
00:05:42,090 --> 00:05:42,870
each frame.

88
00:05:43,260 --> 00:05:49,020
We're going to grab the faces and then put the names on that frame as well and then write it back to

89
00:05:49,020 --> 00:05:49,560
the video.

90
00:05:49,770 --> 00:05:55,140
So you would have seen a lot of this code before and above, as well as this part of it would have been

91
00:05:55,140 --> 00:05:57,180
in the open series section of this course.

92
00:05:57,390 --> 00:06:00,870
This is how we create videos and open and open TV.

93
00:06:01,530 --> 00:06:09,180
So you can actually download the video after and look at the look at the annotations that a facial recognition

94
00:06:09,180 --> 00:06:10,860
app has put on the faces.

95
00:06:11,430 --> 00:06:17,100
So let's run this, and the cool thing about this is that it outputs the images right here.

96
00:06:17,550 --> 00:06:18,480
You can see it slowly.

97
00:06:18,480 --> 00:06:19,620
It's going to a good start.

98
00:06:20,040 --> 00:06:22,860
So we can take a look at them as they go through.

99
00:06:22,890 --> 00:06:25,140
So you can see got Chandler and Joey, right?

100
00:06:25,620 --> 00:06:26,320
That's good.

101
00:06:26,410 --> 00:06:27,070
They got them right.

102
00:06:27,090 --> 00:06:28,650
This is frame by frame of the video.

103
00:06:28,650 --> 00:06:31,980
So that's why it's not moving that quickly.

104
00:06:32,320 --> 00:06:38,540
But if you leave it here and I'll speed this up after for you guys, you can see it work all the way

105
00:06:38,550 --> 00:06:39,000
true.

106
00:06:39,450 --> 00:06:41,760
So that's it for this lesson.

107
00:06:41,760 --> 00:06:43,020
I hope you enjoyed it.

108
00:06:43,440 --> 00:06:48,420
Facial recognition is very cool, and they have some very good networks like features you face out there.

109
00:06:48,960 --> 00:06:53,360
Next, we'll take a look at FirstNet and what what will pay to watch.

110
00:06:53,370 --> 00:06:59,160
And then after that, we'll take a look at a very cool library of deep fees that allows you to utilize

111
00:06:59,160 --> 00:07:04,560
a few different deep learning facial recognition packages very easily within Python.

112
00:07:04,710 --> 00:07:05,850
So stay tuned for that.

113
00:07:16,350 --> 00:07:21,910
OK, so that's it for this short clip will be you enjoy this less than anybody can see and hear.

114
00:07:21,930 --> 00:07:25,830
Actually, it's still running, but you can see it's getting all of the faces here.

115
00:07:25,830 --> 00:07:28,350
Sometimes it drops how it feels just like that, dear.

116
00:07:28,710 --> 00:07:33,270
That's when it falls below the point three point three five threshold that we've set.

117
00:07:33,870 --> 00:07:40,020
So I'll stop this lesson here, even though this is still running, and I'll begin the next lesson,

118
00:07:40,020 --> 00:07:44,670
which is also the next lesson, which is to PyTorch first that chapter.

119
00:07:44,850 --> 00:07:45,930
So I'll see you there.

120
00:07:45,990 --> 00:07:46,440
Thank you.
