Placeholder Image

Subtitles section Play video

  • what's going on, everybody.

  • And welcome to another facial recognition video in this video we're gonna be talking about is doing facial recognition on video and then kind of expanding our our logic and code a little bit from there.

  • So just to do something a little more interesting So where we left off, we were basically just We're doing this on images and we had this known faces during the unknown faces turn unknown faces is where the images were that we wanted to do a facial recognition on see if hey, do we know this face?

  • So now we want to use video instead of the Unknown Faces directory.

  • So what?

  • I'm gonna go ahead and do just comment that out, and we actually aren't gonna need the unknown faces director anymore because really, it's gonna be our video file or video source that is going to be the unknown faces.

  • So the next thing we want to do is actually load in that video.

  • So I'm going to say video equals whoops.

  • I'm going to say video equals C V two dots video capture, and then here you'll specify either kind of an index number for that video.

  • So it's either video 012 and so on.

  • In my case, that will be a video to Otherwise, you also could Could put in a file name here as well.

  • And later on, we are gonna use a video file.

  • But for now, I just want to use a video feed.

  • Since I think a lot of people were interested in that as well.

  • Plus miles will show both.

  • So Okay, so now we have our video feed, we're still gonna load in our known faces.

  • That's fine.

  • And then the only other thing that really changes is here.

  • So instead of saying for file name, we're actually gonna put this in a while.

  • True loop.

  • And then we don't need file name anymore.

  • We don't have the thing that's gonna replace image now is going to be reading from our capture.

  • So instead, we're going to say, actually, it's gonna be Rhett and that image, and then we're going to and that's just, like, return image.

  • And then it's video.

  • Don't, uh what is it?

  • Is it capture?

  • I think I always forget this video.

  • Yes, we do.

  • Okay, so s o video read.

  • Now we have our image on.

  • Then we do it locations and coatings on.

  • In this case, we're actually already using, um, open CV to get the image So we don't need to do this conversion anymore because it's already mpg are.

  • In theory, you might need to do the conversion before the encoding sze I suppose, or even locations.

  • But it seems to me through playing around the face rec works no matter if you're using be gr rgb so I don't know how big the impact color is playing.

  • If anything, it might even in the back end become burning things to gray scale.

  • For all I know, if you know, let me know.

  • I actually do not know what they're doing at.

  • Like I said, I wouldn't be surprised if they convert to gray scale at some point.

  • Okay, so then we show the image.

  • Wait, can we no longer need a wakey?

  • And so we want to do is have this running kind of indefinitely.

  • So instead, what we're going to say is, we're gonna throw in that kind of if cv to dot wait key one on and then this is the code for and zero lower case X capital F F vehicles warm que Basically if the user presses the cuchi, we want a break And then because I'm on ah boon to I guess destroy window just is what does not work on a boon to So So one thing that Daniel was saying was one way around this is you could just try and accept So you can try CV to destroy window except pass and just be done there because I guess for some reason I have been to that, this function just does not work so very interesting.

  • Okay, with that, I think I think that's everything.

  • I've got my trusty Web cam here and let's see if that works.

  • Let's pull this up.

  • Python.

  • I've renamed this file to be video face rec Example that pie.

  • Let's go ahead and run that it's gonna load in our known faces, which really is just my face.

  • And as you can see, that works decently.

  • Well, obviously, as the face starts to come up a little bit more, you start to, like, lose Thea the face, but not bad.

  • Okay, so let's go impress Q.

  • And that should be everything you want for video from a video either a video file or a video feed.

  • The same thing is goingto work.

  • You'll have your known faces.

  • You'll look.

  • But to me, that's a little boring, because that was like three lines of code.

  • So now what I want to do is taken Orwellian turned, and I'm going to say from our video, either video capture device or a video file, because I don't really have lots of people passing by and said, What I want to do is I want to start labeling, giving people i D.

  • S.

  • So imagine you running like an office building or a school or something like that where, you know you have a bunch of people that are commonly coming through that area.

  • So it's very common to see common people.

  • But it's very uncommon to see uncommon people.

  • And then there's other places where it's a little more rare to see common people, so think about like any place where travelling.

  • So if it's not an employee or something like that, seeing like, let's say you're at an airport seeing common people that have no good reason to be there commonly that's a weird thing, right same thing if you depending on your office building, right.

  • There's some places where you might have a bunch of employees that you expect to see commonly.

  • But then, if there's some new face that has no reason to be there, commonly you've got a problem.

  • So these are kind of typical security issues that are faced by businesses and stuff like that and even government buildings kind of the same thing.

  • So what can you D'oh Well, using face rec, we can actually do this.

  • Quite simply, we can find out either we can find out both of those questions.

  • Who are the common people who are the uncommon people?

  • And any time an uncommon person shows up, for example, we can find out, like, instantly.

  • So, um so, yeah, so what we're gonna do now is, rather than using the video capture, because I'm the only person in the room right now, we're going to use a video file that I created, So I will do my best to share this file if I forget someone just remind me.

  • But it's basically just me holding up my cell phone and swapping through photos of various individuals and actually I think I don't know how many total we have made.

  • Five.

  • We got Obama Trump.

  • Uh, Ellen Mosque.

  • I think maybe they're sworn with.

  • I thought there was a Joe Biden one.

  • So, yeah, there's their biden.

  • Any way you could do this with an infinite number of photos if you wanted.

  • This is just a quick example.

  • I just made it purely for debugging purposes.

  • So now what we're gonna do is rather than the loading in the the webcam I'm gonna load in that video.

  • So face face was face rec video video dot mp four.

  • So that's all you have to do because that video file is local tow tow.

  • What?

  • Where I'm working.

  • The next thing is, we want to actually, rather than doing really anything else.

  • What we're trying to do is a sign, Um, assign i d.

  • S to, uh, to people so we don't really care about names anymore.

  • We're gonna be working on I d.

  • S later.

  • If you wanted to actually name these individuals, you just have a dictionary that maps ideas to names.

  • But that's not really what I'm going for the moment.

  • So instead, what we're gonna say is we're gonna We're gonna load in known faces and known names.

  • Ah, the other thing we're gonna do is because we're working in I d s so known faces right now has names, but soon it's gonna have I d s.

  • So instead, what I'm gonna dio is I'm actually gonna make a copy of known faces just in case.

  • And then I'm actually gonna tow everything in known faces.

  • So right now we're starting a clean slate, but later, this will have ideas in it.

  • So, um, gonna minimize this and inside those ideas rather than having images now, we could save an image.

  • So when you grab the location of the face you could do it's our ally.

  • I can't rember his region of Inter.

  • I think it's region.

  • Whatever it is in CVI to it's our ally.

  • You could grab that and then save that in the directory that way Later.

  • If you are doing like some debugging or something, you could see, um, you could see, like, who is this person?

  • Actually show me a face of this person and then later you could compare that that face to a known database of people.

  • So again.

  • If it's an office building or something, you've got headshots of all the individuals for their I.

  • D.

  • S.

  • Or whatever the case, you could very quickly label all those individuals when necessary.

  • S o.

  • We don't need the image anymore.

  • For now, though, do that.

  • The encoding, and instead, we're gonna do now is we're going to save the encoding, because again, we don't care about the image so much.

  • So having the image that encoding the image just kind of makes the upstart time take a while.

  • So instead, we're going to say is encoding Rather than Equalling that Russia going to say encoding equals on, we're gonna import pickle.

  • I don't think we have yet.

  • Yeah, import for pickle.

  • And we're gonna dio is for pickle are encoding Eagles Piggott load and then we're going to love the open of file name, Open file name.

  • Um And in fact, it should be, uh, for named Noah.

  • Stop, lister file name and office.

  • Alistair.

  • Um, I shouldn't be.

  • I guess we would actually really see four name.

  • Uh, Okay, so four file name and then we will say is name, file, name.

  • So we're gonna open the file name.

  • I'm pausing on that for a second because I'm pretty sure I've used just open file them.

  • And that worked.

  • Which is odd to me that pickle would do that successfully.

  • Anyway, I have to come back to that.

  • That's how rich your work.

  • And that doesn't make any sense anyway, so we wanna open that file, Uh uh, and we want to or be so that will be our encoding object.

  • And so I'm gonna comment that this one out as well.

  • Okay, so now we have the encoding, and what we want to do is they known faces.

  • We haven't had the penned the encoding on here.

  • No names.

  • We depend the name, which again, in this case is going to be an I d.

  • Then what we want to do is right now we're starting clean Senate slate, but eventually we're probably going to start with at least some ideas.

  • So what we're gonna say now is we're gonna say if Len, uh, known names greater than zero.

  • So if we have more than one arm or what do we want?

  • So what we're gonna say the next idea that we're going to sign is able to max known names because we'll just be a list of I.

  • D s plus one and then Max of known names.

  • I can't really decide if I encoding this might also need to be an end.

  • Now that I'm thinking about it, I think we'll do that.

  • Let's say we get away with that, um and then else lt's next I d will start at zero.

  • Cool.

  • So now what we're going to dio is we load in yet All this stuff comes in, we're iterating.

  • And then basically the only thing that really now needs a change is if true, we made a match.

  • If we didn't, right, where is a else?

  • What we need to really know is, you know, what's the next idea?

  • So we're gonna say match equals string next I d.

  • And then we want to say next I d plus equals one.

  • And then, like all this stuff, this stuff we actually just want to do regardless, right?

  • So we're actually gonna untapped over all those things.

  • Um, and I think the rest of this remains so I'm trying to think here if we screwed anything up, but I think the easiest way to find out is to just run it.

  • So let's see what happens.

  • Surely we get at least an error.

  • U Um Okay, so where is our CV to daytime show?

  • Here is so and so we'll just make this empty, empty quotes.

  • This is the video title, by the way.

  • And we were putting file name there because we wanted to show for the unknown faces file name, but we don't want to do that anymore is we don't have unknown faces.

  • We'll see what happens this time.

  • Okay, so this time we are getting constantly a new i d every single time for that face.

  • So let's go ahead and quit.

  • And ah, what we What we did not do is what we need to do is upend right.

  • We need to do way more things here.

  • So the other thing I don't think we saved any.

  • So we have We've got a lot of things.

  • I don't know why I thought that was ever gonna work.

  • Um, okay, so we do the next i d.

  • But then what we need to do is known names we're gonna do dot upend, uh, match.

  • Not next.

  • I d otherwise, we continue raising that up.

  • I just need a lot more coffee this morning.

  • No names on then known underscore faces dot a pen, Um, in this case for face.

  • So this would be facing coating.

  • So we'll save those two things.

  • And then what we want to do is save now that we've got this new encoding and it's only when we have a new encoding later you could save more and I'll talk a little bit about some of the logic I thought of toe like add more faces.

  • But for now, we're just going to save the first new face and coatings or insane known faces upend face and coating, which also might be kind of slop.

  • You almost might wanna wait a little bit, because the first face that finds its like a sliding face in this example, for example, uh, and that's probably not the best face for encoding, but anyway, known faces upend facing coating.

  • Uh, now we're gonna do is os dots make Duerr.

  • And again I'm using F strings.

  • I did ask So people had a good point about the backslash, but does not.

  • I always thought the Ford slash still worked in python for me on windows.

  • Like if I was giving forward slash file names, I have to go back to Windows and see if I'm incorrect there.

  • But anyway, if you're on Windows, I guess use the backslash, I don't know.

  • And actually, it would be the double bags left.

  • Okay, Known faces, dir slash Let's not make there.

  • And then we have a new index, which is gonna be the match.

  • So we make that directory, and now what we want to do is actually save save that encoding.

  • So that would be pickle dot dump.

  • And then, um we will say is like, this apparent example of why I like height.

  • So So now, now it's not there for me.

  • I always forget the order.

  • Like, do you dump the file name first?

  • And because I'm pretty sure in numb pie, you save the file name, then the object I could I could be wrong on that as well.

  • But I always forget which one comes first.

  • And it's just super useful tohave kite here to tell me.

  • No, it's the object first, right?

  • So yet again, another shot out to kite.

  • Um, the best auto complete ever so object file.

  • So, uh, too busy being enamored with with right now.

  • So we're gonna dump the face and coding, and then the file name is going to Earth file.

  • Rather is going to be open and again, we're gonna just do it F string for known faces, match blue.

  • And in this case, I think what I would say for the file name, you could just say match.

  • You really could, like, use a match dot p k l.

  • And then what will say is W b.

  • But I think what I want to do is prepare us for the possibility later of saving multiple encoding.

  • So what we're gonna do it says we're gonna import time.

  • They were to come down here match and I was a dash.

  • Uh, the value of time dot Cool.

  • So really long file name.

  • But basically, all we're doing is we're just saving the match in the time off.

  • When?

  • So the matches encoding And when was that?

  • And that's it.

  • So Okay, so we've got all that pickled dump.

  • So now we have saved that we've attended it and I think we're ready.

  • Let's try again.

  • We could either review our code or just run it and fix the ears as they come.

  • Okay, This time.

  • Okay.

  • So Obama is I d zero.

  • No, real surprise there.

  • Let's wait a moment.

  • Okay.

  • We've got a new person.

  • New face, I d one.

  • It will be interesting to see what happens as we have, like two people together on so on.

  • Luckily, we're still constantly.

  • My biggest fear was the first time we see like, his face.

  • It's as if the thing is slightly look out fast book.

  • So now you can see even here Obama is mostly zero, but sometimes he's getting a five.

  • Trump is mostly three now, but he's also four.

  • This is clearly Obama again I d zero and then try to think who else were okay?

  • We still gotta Biden coming in, and then we still have ah musk coming in.

  • So most of these air pretty good faces.

  • So I guess they're getting a good thing.

  • So So as we're kind of waiting on this one, a couple of things I was thinking about was first off of face.

  • Okay, so here we are.

  • I think this is our first seeing of Ellen must.

  • So Ellen is I d nine and always I d nine.

  • Hopefully, I haven't seen it change yet, but we could actually have some output or something.

  • And then now Obama apparently has a new okay, So figure once I can't once it comes into focus is like, Okay, it's zero.

  • And then Biden is an 11 apparently.

  • But every time it goes out of focus, Obama's like new people.

  • That's interesting.

  • Hold on.

  • Let me close this and I forget what our tolerance was.

  • What we said that is 0.5.

  • Let's try to set.

  • Let's let's do let's give it a little more room, say 0.6.

  • So make it a little more tolerant at recognize, because look at this, we got 17 I d s.

  • Let's let's close that.

  • Um, so one option we have it is you could you could either increase or decrease the tolerance.

  • So let's let me let me explain.

  • Let me run this while I explain So one option we have is to have a pretty open tolerance.

  • So let's just see how much this changes, how many ideas we wind up getting.

  • You see if this actually is popping up at risk of pulling up O B s an infinite thing.

  • No.

  • Cool.

  • So, uh okay, so So so far, We just have the 20 You can't even see it.

  • The two ideas.

  • Now, can you see it?

  • Yeah, Um, so we just have that to ideas.

  • That seems to be doing a little better at least, So that's good.

  • But we actually got a few new ones now those areas, like, moments in time.

  • So one of the things I was thinking of is the face detection aspect of fate of the face recognition kind of package.

  • The face detection is really good.

  • So what I was thinking about was could we use some logic to say, Hey, this is this is this face like, as this face is moving around, the face cannot change, right?

  • Like just logically, the face can't change.

  • Okay, so we should be able to logically assume that this is always I d zeros face.

  • Okay, It will never flop around.

  • So especially as you're building this database and now we're still only on five.

  • I think by now we actually were a lot deeper.

  • So this seems to be better Thio make the tolerance will give us a little more tolerance.

  • So anyway, one option we have is you could actually set the tolerance quite low and then have knowledge that these ideas should not be changing as time goes on.

  • And then every time you see a new face or a new version of the face also just as note with the tolerance at 0.6, we can see we're having really no trouble identifying either of these people.

  • Is that well, Biden bounced around a little bit, but it least did a better job and same thing here.

  • So I think before we had 17 total Heidi's.

  • Now we're nine.

  • We just got another new one.

  • Let's see if we end up with 10.

  • Doesn't look like it.

  • Okay, Um, cool.

  • So that's pretty interesting.

  • So now, as you've gotten is, you get a new face you would be able to recognize Hey, this is a new face or not.

  • So basically, every time you hit, uh, this this else that's a new face.

  • So if you wanted to do some sort of handling for an uncommon face, you could same thing here if you wanted to handle for head.

  • We're seeing this face a lot.

  • You could, so that's also pretty interesting.

  • Fairly Orwellian.

  • I think of a few bad use cases, but yeah, so pretty cool.

  • And like I said, I think you could add a little bit more logic here and be way more accurate.

  • So another idea I had two was like, You know, with you could have tolerance when you first you have to Tolerance is right.

  • You could have a tolerance for you have, like, two versions.

  • And then any time there's a disagreement, you could have a little more logic trying to figure out like What is this face?

  • Because chances are the same person is likely to have a few ideas in your system.

  • So maybe later you could run through.

  • Those are from time to time, kind of merge certain ideas because you could probably figure out, especially if they were all together in the same frame.

  • And that was just a moving face.

  • Chances are, hey, that's the same face, right?

  • So then what you could do?

  • You could merge those two.

  • So any time you've got ideas bouncing around like we've just seen what you could Dio is you could through logic, you could say, Hey, that was always the same face Which one of these faces is the more common face and like, Hey, let's make that the main i D.

  • But what we'll do is we'll add one more face encoding to that face so we could just merge the two together.

  • So I think, using some pretty simple logic.

  • And maybe if you guys were interested in that part, three could be me doing that.

  • And so as we see a new face, but yet it's on the exact same frame that that face could not have changed.

  • Hey, here's a new encoding for this face because apparently that was a hard to recognize example.

  • So hey, let's throw that one in there and then hopefully over time make this much more robust.

  • Eso it would only get better over time.

  • So, uh, anyway, there's ideas like that, and there's a few others that I had floating around in my head to make this much, much better.

  • But you get the idea.

  • So Okay, I think that's everything.

  • If you've got questions, comments, concerns, whatever.

  • Feel free to leave them below in this video is sponsored by me.

  • If you guys are interested in learning about neural networks at a very low level from scratch in python, learning how they actually work rather than up employing or applying whichever one you want to go with on the script, that's fine.

  • Um, how to actually how these normal we're actually working rather than doing like cookie cutter models and pretty much just solving things that have already been solved for you.

  • Chances are, if you've ever tried to work on a real world problem, you've seen that real world problems are much more challenging than like m nist or classifying dogs and cats or, you know, whatever.

  • And if you want to kind of level up your knowledge of how neural networks work and how to actually make something work on a problem that hasn't yet been solved, definitely worth checking out the neural networks from scratch book.

  • You can go to know when I was from scratch, which is N N f s dot I oh, uh, and you can preorder the book now, and eventually the book will be out and you could buy it.

  • If you do pre order it, you get access to the draft, which is live right now, and you can comment, ask questions in line with the actual document itself.

  • And currently, at the time of my recording, that's hopefully over time.

  • They will be much more information there.

  • It's about, I think, 180 pages or so.

  • We've got everything from building the model to training back propagation and all that.

  • So it's off to a really good start and really happy and seeing all the community engagement in the document itself like that.

  • So anyway, check that out if you're interested.

  • Otherwise I will see you guys in another video.

what's going on, everybody.

Subtitles and vocabulary

Click the word to look it up Click the word to find further inforamtion about it