AI on the Jetson Nano LESSON 40: Training Facial Recognition Models in OpenCV

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello guys this is Palma quarter with top tech boy comm and we are here today with lesson number forty in our incredible new tutorial series where you are learning artificial intelligence on the Jetson nano I am going to need you to pour yourself a nice big mug of iced coffee and today I will also be enjoying a nice cup of hot coffee yes it's gonna be one of those double coffee days and I will need you to get out your Jetson nano gear and as you're getting your gear out and booted up as always I want to give a shout out to you guys who are helping me out over at patreon your support is an in current incredible encouragement to me to continue to produce this nice easy-to-understand material for you to learn from those of you who are not helping me out yet look in the description down below there is a link over to my patreon account think about hopping on over there and hooking a brother up but enough of this shameless self-promotion let's jump in and talk about what we are going to learn today if my memory serves me correctly and usually it does I do believe in lesson number 39 I left you with a homework assignment and what the homework assignment was was to come in and further train your program so when we left off in Lesson number 39 I believe that we had trained our system on I believe let's see let me get out of your way it looks like one two three images we had trained it to recognize Donald Trump Nancy Pelosi and Mike Pence okay and then what I had told you to do was to go in and train it for the rest of the known images and so if we go to face recognizer demo in images and our known people it looks like we have one two three four five six seven seven images and so you were to go in and train it on all of those seven images and then once you had done that play around and see in the unknown images how well it did on facial recognition so I would imagine because usually I know what you're gonna do before you know what you're gonna do and so I'm gonna predict what you guys did you guys probably came in and you took one of these little training sessions where it's a load and a recognize a load and recognize you know kind of load determine the encoding slow determine the encoding sand you kind of pasted it for all of those known images you can do it that way but that's not the best way to do it and so what I'm gonna do today is because you see the problem if you do it that way if you change those images every time you change those known images you've got to go in and you got a reprogram and then you haven't looked at it in a few days and you're all confused so I'm gonna show you a little pro tip about a much better way to do it and so we are gonna come over here and we are gonna go down into our face recognizer program we are going to create a nice fresh new program which I think I will call hmm face recognize recognize and then I believe we're at three dot P Y okay hit enter ah I touched my face can't touch your face I'll tell you this corona virus pandemic it's just like I keep touching my face I'm gonna try not to touch my face I got to develop that habit okay but if your nose it just what do you do if your eye itches what do you do okay all right so let's jump in I will give you a better view here get that out of your way make sure that I'm mindful that you can see things good might need to move that up just a tad just a scotch okay do you guys know what a skosh is what a tad is very small amounts all right so let's see a better way to train this model the command is the same the commands are the same but we're just going to do in a more clever way okay so what we're going to need to do is we are going to need to go ahead and import face recognition okay face recognition we're going to import CV to and we are going to m cv to and then we are going to import OS you are not expecting that one were you yeah OS is an operating system that's going to give us some commands it's gonna let us kind of automate or more automate the training where we're kind of training it on our known faces and then just to be good I like to always print out my seat my CV to underscore underscore version just to make sure that I'm operating on the version of open CV that I think okay now when we train these when we train on our known faces we're going to need to have an array that we put those encodings into and so we are going to create an array of in codings and it's going to be an empty array now this will be an array of arrays because an encoding itself is an array so the first position in encodings is going to be the array of the encoding of the first-known and then an array of the encoding of the second note in an array of the encoding of the third okay so you can kind of see an encoding is an array that's sort of the training data for one person and we're gonna have more than one person so we're gonna need this array and we'll put the encoding for all the unknown people in it and then we need to know who they are so we'll put in names okay and that's going to that's going to start as an empty array too so we're going to have the person's encoding and then we're gonna have their name and then the next person encoding in their name in these two things so we'll just be populating this thing now we need to tell it we need to tell it where our known images are okay where our known images are and up on these paths very hard to do without making a mistake so I'm going to come back over here and I'm going to go to our demo images right that is let's just start back all the way at home and we know that we've got a desktop and then we know we have our PI pro folder and then remember we created the face recognizer and then we have the demo images and then here is known ok here is no I want the path to that so I'm gonna say properties and then under parent folder well I'll have to add known to it but under parent folder let's see if I can grab that select all if I right mouse click I can select all right mouse click again I can select copy that will take us to the parent folder and so we'll go ahead and do that and I'm gonna say that my image directory image dirt image underscore Durer is equal to and then I will just ctrl V paste in that path and then the actual folder was known okay so now I have a starting place I'm gonna look in that known now you're gonna learn something new what would you like to do in node you would like to walk your way through every file in known and as you walk your way through every file in known what you would like to do is you would like to load the file and then you would like to do the face encoding and then you would like to get the name and then you would like to fill in these encoding 's and these names and so you would like to be able to do that in a for loop right instead of having all these things that you manually enter it you would like to step through so let's see how we would step through we could say 4 okay and the way this works is it's a new command called walk where you walk through well what it's gonna do is it's gonna return to you the directory that you're in your home directory the directory that you're starting in and so for us that would be our known directory ok and so it's gonna it's going to start there root okay and then it's gonna give you the directories and then the files okay so you think the directory that I'm starting in that's the root then a list of all the directories that are inside that folder for us we don't have anymore and then a list of all the files and how do we do that well you say in OS OS that's that library we look we just loaded in the command is walk okay and you got to tell it where do you want to walk through well image directory so what this is going to do is it's going to start in this image directory and then it's going to walk through all the files and it's going to walk through all the directories and then it's going to walk through all the directories in all the directories and all the directories and all that right and so it's just gonna walk through your entire file structure so this thing is way more powerful than what we're doing because really we've got to put in the route the directories and the files but really the only thing that we're gonna be walking through is the files cuz we don't have any folders inside of this known but we could walk through much more complicated structures than this and so this the route is not going to change the ders or the directories are gonna be empty because there's no directories inside of our route in our route is this known folder here okay but what it will do is it will walk through the files that is going to be pretty cool okay now what I am going to need to do is is that so this is going to give me all the files so so this image directory this is going to give me not one file but it's going to give me a list of all the files that are inside of image dirt and that will be my route so this files is going to be an array and it's going to be an array of all of the files in image dirt and let's just see that okay let's just see that so let's just say print files let's just see what that does run Python file in terminal I apologize this takes Oh what I'm still on Python 2.7 frame of mine you got to use parentheses in 3.6 okay so let's try this and guys I really it's it's kind of sad but this takes a long time okay look at that so this is inside my known folders my known folder and it returns to me all the files okay you see all these file names well what do I want to do now I have all these files now that I have all these files what do I want to do well I want to step through them so for an individual file in files that's that erase so I'm going to step through that files array and then what am I gonna want to do well I'm gonna want to create the actual complete path with the file name so I've got the path and I've got the file name but what do I need to do well I need to say that the path which would be the path with the file name appended is going to be equal to o s dot path dot join and then what do I want to join I want to join the root and the file okay now let's see if this makes sense what is the root the root is going to be this but what is missing the slash in the file name well the file name is in here so as I step through the first time through it is going to append Palma Quarter to this and then chase to this and so let's go ahead and print that out so now what we are going to do is print and let's just print path and this should now give me a list of the full path with the filename if I'm thinking about this right this is very powerful you guys spend some time you want to understand this you don't want to just copy what I'm doing you want to really understand it okay look at this so what we started with I'm gonna let you see a little bit bigger of this okay so what we started with was a list of the file names we step through those file names and we add the path to it okay so now I have the full path with the file name that is pretty cool so what can I do now well I can get a name okay the name is gonna be O s dot path and then what do I want to do dot split text of file okay and then what do I want I want the first position and what this should do is this split text should give me remember file is just something like Paul space McWhorter dot jpg I am going to do a split text on that and then I'm going to take the first position that should just be the name without the dot jpg so if I print this what this should print is this should just print the name without the dot jpg so you can see now when we were training that's why I put the proper name as the file name because now we can get those names for free so let's try running this does that make sense what we're doing we're trying to build this thing whoa oh I've got a name is equal to o s dot path dot split ah those crazy guys made split text with one T it's a shared T let's try this you guys following along okay look at this so now it will print the full path to the file that you want and then it creates the name for that person by stripping the name off the file name so we can see that this is the path with the file and then this is the person you see this is gonna be we're in the process of automating this training okay so now what do we really want to do now we want to we want to load that person we want to load that image okay so person and remember we're doing the load with the facial recognition library not with the opencv library so we're gonna say that the person is face recognition okay and then what do we want to do we want to do dot load image file load underscore image underscore file and then what do we want to load do we want to load the name or the path we want to load the pet okay because that has the full path and the filename so now I'm actually loading the picture does that make sense I hope so now what do we want to do well we want to encode it so encoding so I'm going to have the encoding is going to be equal to face recognition face underscore recognition dot face encoding and then I want to include who the person that I just loaded and then if you remember this actually returns an array because it's looking for multiple faces and so since this just has one face it's gonna still return an array and so we want to just go ahead and take the first one and then that will just make it just a normal a normal array not an array in an array if that makes sense okay and now what do we want to do well we we have these encoding where we want to have the encoding of all the people that we know and so I need to go in code dings the array dot append I want to put this new I want to put this new encoding into my main training array which is called encodings and similarly I need to keep track of who's who so I need to do names dot append and what excuse me what do I append here name okay so it's the person's name in the names array and then the that person's encoding in the encoding array and do you see how it's two arrays but the positions are all lined up okay so now we have that and well you know what I think that now I should have this whole thing trained let me just print now names and this should be the array with all the people's names and look at this okay run Python file internal guys on programs like this it's good to put these print statements in and check them as you're going and that way when you have something that doesn't work you can kind of you're going step by step and you can go back to the last thing that worked in so as we go through this I want to make sure that each one of these works all right now that we're doing these encodings this thing is but running a lot slow because it's loading the picture and then it's chewing on it learning who that person is and so that is taking a little bit longer to do that okay and then who did it learn palma quarter chase Donald Trump Ronald Reagan Nancy Pelosi Charlton Heston and Mike Pence okay so now this model is trained it knows all the people who are in the known folder if you want to learn more people you put more known people in the known folder and you name your you name the file that person's name okay pretty clever huh so now what we need to do is we need remember we're gonna have to do a little bookkeeping here remember later on we're going to put a label on the people so we need to go ahead and setup a font now before we go into our loops and so our font is going to be equal to cv to dot f ont uppercase underscore h er s H ey underscore s impl DX now you can play around with different fonts this is just a pretty simple one okay now what image do we want to study our model is trained what image do we want to study well I think I'm going to do a test image is equal to face recognition dot blowed image Wow okay so we're gonna load an image now we're gonna load a known or an unknown we're gonna load an unknown because we've already done the notes that was training now we're gonna look at a picture we haven't seen before and see if we can figure out who it is again I love copying the path because it's just too hard to try to tap them in right so we're gonna go to desktop we're gonna go to PI Pro we are going to go to face recognizer we're gonna go to demo images and then do we want known or unknown we want unknown and then let's look at this number twelve here okay I think I am going to do number twelve and I'm going to right mouse click on it and properties and then I'm going to point here at the parent folder right mouse click select all and then copy and just remember this is unknown twelve you twelve okay so if I come here I'm gonna paste I'm going to put paste inside of a semicolon and then I'm going to paste and that gets me all the way to the unknown folder and then I'm just gonna go that was you twelve dot jpg so that is the file that we are going to study so I've loaded it once I've loaded it what do I need to do well I need to find the faces in that picture so I'm gonna say face pose this shuns why is face positions plural because there could be more than one face in there and it's going to return to me an array of the face locations of the first face the face locations of the second face the face locations of the third face okay so face positions plural and K face positions is equal to face recognition dot face underscore locations okay and then I want to find the face locations in which image the one I just loaded test image all right so now this isn't recognizing anything but it's just saying there's a face here there's a face here there's a face here so it will give me an array of those corners of the boxes of where the faces are okay and so now I have those locations all right and now what I want to do is I want to go ahead and I want to do the learning I want to find the encoding on each face okay so this is gonna be all encoding x' why because this command will give you the encoding inside of each one of those boxes okay so all in codings is equal to face recognition dot face in codings okay and then you've got to send it what file do you want to look at test image and then you've got to send it to face positions okay face positions all right now let's think about this face positions is an array of the face positions I pass it that and I pass it the image and it looks in each one of those locations and it generates an encoding okay and then it puts all of those in codings in this array which is all encoding does that make sense okay I hope that makes sense now we're done doing the recognition work and we're going to want to print this image out later we're gonna want to show it do you remember that the face recognition load image file do you remember that that is in the RGB color space and our friends at OpenCV decided to use the BGR color space so since we're going to be displaying these things using open CV we need to go ahead and we need to get ready for that by saying test image is equal to C v2 dot C V T uppercase C olor so we're going to convert color of test image to cv to dot all uppercase C olor underscore we're in RGB and then to BG R so we're just taking test image and converting it to BG r so now it'll be all happy when it's working inside of open CV okay so let's see that all looks pretty good that all looks pretty good so now what do we want to do well we want to step through that image test image and for each face we want to see if it matches something that we know okay so we want to we want to compare those all encoding x' we want to compare those with our training encodings so in order to do that we can't just do it once because there could be multiple phases we've got to step through okay so we're gonna step through four and we're gonna go top comma right comma bottom comma left because that's the order that that's the order that the facing coding is going to be in so we got to go top right bottom left okay and so those are the positions and then also face encoding all right in and since we're stepping through kind of two groups we've got to do a what do you member from last time we got a zip is the command that allows us to step through two things and we want to zip what we're stepping through face poses shuns plural right face positions we got up here all right face positions is an array we're gonna step through that array and that's going to give us top right bottom left and then we're also going to step through what we're also going to step through all in codings okay so the all encodings go with the face positions and we're going to step through them so each time through i'm gonna have a position and that positions facing coding okay so now we'll put a colon there and now we come back so what do we need to know well you got to remember that it might not recognize anyone and if it doesn't recognize anyone you still need to put a name on it so i'm just going to say name is equal to unknown unknown person okay now most of the time it'll recognize something and when it does it'll change name but if it doesn't recognize anything at least we have a name unknown person and then what we are going to want to do is let's see here we're gonna want to look for matches wow that was really bad okay so now we've set the name there now we want to look for matches okay and matches is equal to matches is going to be equal to face recognition do you remember this from last time and what are we going to do we're gonna compare faces okay and what do we want to do we want to compare the things we know all the things we know is encoding with what that last that last encoding that we did which will be face encoding now this face encoding is one face from the unknown image so here we're stepping through the unknown image and the face that we're on will be in face encodings so we're we're comparing all of our known faces with this particular face in our particular unknown image that we're studying okay if this doesn't make sense go back and look at it from the last week okay so that will find the matches and now we got to see were there any matches well we want to see if there's any truths in matches okay so matches will tag true when it sees that one of our what it sees if our face position if our face encoding from the present face matches any of the faces that we know which are in encoding it'll tag it so if true is anywhere in matches then what we want to do is just say first match index first match index is equal to matches dot index index true so like what position in the list did it find it true we're putting that in the match index and then what we're gonna do is now we're going to tag the name we're going to grab the name because it will be at that same position name its names okay of first match index so now in this unknown picture that I'm looking at and this unknown face that I'm looking at if there is a match I get the index and then I grab that name from our names array because it will be at that same index because we've got kept things lined up it excuse me so now I have a name well what do I want to do well I want to draw a rectangle now see v2 dot rectangle I want to put a rectangle where on test image and then where do I want to put it well I want to go left comma top and then right comma bottom are you guys noticing that face recognizer uses like top right and bottom left and then OpenCV does top left bottom right and so that's why these things are a little bit in a strange order but but OpenCV has top left and bottom right to where if you looked up here I believe where was it somewhere up above what you'll find is it's a little bit different order when we when we go through things with with the face recognizer you see it goes top right bottom left you'll get some strange results if you don't understand that those are going in different orders okay so top left top right bottom and then we need to give it a color well let's give it a red so that would be zero blue zero green 255 red and then let's give it a line weight of two okay now we need to put a label on it so we'll say see v2 dot put text put text all right and then the text that we're gonna put we're gonna put it on test image and then we're gonna put the name on there and then we're gonna go to the position left and then top minus six and so it would be left and then top minus six would move it up and so the label doesn't go over the inside of the box which is kind of nice and then we got to tell it the font which we defined above and then we've got to tell it the font height our size which I'll put it point seven five and then we got to give it a font color I think I'm gonna try like an aqua and that's going to be like ant I think I'm gonna try yellow which would be 0 comma 255 comma 255 and then I will give it a width of 2 kind of a font heaviness of 2 all right so now we can go ahead we've got the image we put boxes around the faces and we've labeled those boxes so now can do a CV to see the to dot I am show and I'll just say picture and then comma test image because that should be all ready to go now and let's go ahead and be good and say CV to dot move window and then we will do a move the picture window if you don't do this open CV has a way of putting it in the strangest position so we'll move it always to zero zero and now we got a see is if cv 2 dot wait key is equal to zero or CV wait to of 0 is equal equal to the ORD of q and so this it'll show us the image and then we hit Q it will go ahead and drop down and then what this will be is it'll wait for input and then when it gets it it'll see if it's a cute and if it is a cute it will be do see v2 dot destroy all windows ok no this we're gonna go ahead and run and it should load it should train itself it should load in the unknown image it should find all of the faces in the unknown image it should encode the faces in the unknown image and then it should compare each face to all the ones we know next face to all the ones we know and then for all of them it'll box it for all of middle box it if it doesn't know the person will put unknown and if it does know the person it will put their name what's the chance this is gonna run hold your breath there's no way I can hold my breath because it's got a train itself but hopefully it won't crash do you think do you guys think this is kind of clever how we can do this walk command and what's really cool is if you want to train on a batch of new images all you got to do is put them in the known folder and name them according to the person who you know there would be a good reason that you would already know who those people are because you're putting them in an own folder okay it's going through the training learning everyone giving a list of the names that it knows Oh face positions is not defined what is this nonsense in line twenty eight face positions face positions does not have a tea did you guys see that okay over run Python file in terminal found it pretty quickly though that was good hopefully you guys were yelling at me man I I tune in on the premieres with you guys and you guys are pretty sharp you find those errors when I when I do it and so that's really good I don't have the nerve to do something that's complicated as a live stream because you know it's kind of hard to fake your way out of something if you got an arrow that you can't find so we might try it one day just for fun okay test image ah where is that 1:35 another an extra t-test and it should be an uppercase I I do believe okay as these are just simple little mistakes you can be patient with me right but man do you guys see how powerful this OS dot walk command is because there's so many times that you just want to walk through a directory structure and have all the folders and have all the files and then have them in a smart array where then you can kind of do what you want to and then as you change your directory structures you change your files it'll always kind of update itself and work okay whoa oh man wait key is uppercase K we were so close to having something really good i we made it to the end of the program so now the program should run without errors but of course the real question is the real question is going to be whether it actually pops up the window and shows you the faces it's training learning all these cool people the training is done it's now looking at our test image boom do you see this facial recognition uh-huh double chest bump look at that Charlton Heston and Ronald Reagan two for the price of one do you see that is that like really really really cool and if you look at it the picture of Charlton Heston was really kind of it was not real similar to that let's look at the Charlton Heston picture that we trained on we'll go to desktop we've got a PI Pro I shouldn't kill this one too I should just leave it open and then known images the the picture of Charlton Heston was when he was a young man in in Ben Hur and here he's a much older man but man that is pretty cool and then let's look at Reagan let's see what we trained on this and it recognized that and that is pretty darn good so let's go back okay so I'm gonna go ahead and I'm gonna quit out of this let's try a different one let's look over here at knowns and ah let's see let's do this you eleven okay let's do this you eleven we're gonna come where was that up here we're gonna change that to you eleven okay run Python file in terminal and we're gonna see what it does with that one okay it's going through the training [Music] training is done boom look at that three count them three thrice recognized we have Mike Pence we have Nancy Pelosi and we have Donald Trump okay let me let me try one more let's see I want to try you four okay why am I using politicians because I want to be real careful with copyright and these are public domain images and they're people it's both public domain and people you would recognize so it's not that I like them it's not that I don't like them it's just that I don't want to get in trouble with copyright or get you guys in trouble with copyrights so we're trying to be real careful here so it's going through the training and we will give it a second to go through the training training is done it's looking at the image it's trying to figure out who is who all right boom okay look at this now this is kind of interesting I find this really really interesting so oshu Murr here Oh shoo Murr he's an unknown okay this blurred-out person it's interesting it recognized that as a person but unknown Schumer is unknown this person is unknown Nancy Pelosi it recognized unknown and then it didn't recognize this guy it didn't recognize this as a face okay but that is pretty darn impressive now let's just go ahead and try to see if we could train on Schumer now it's kind of hard because he is really not looking at the camera and so a picture like that is really pretty hard too it's pretty hard to do but let's go ahead and just see if we can do it I don't know how to spell his name shoo shoo Murr Chuck Schumer SH s CH u in ER okay let's see if we can find out maybe we should say Chuck Chuckie Charles okay this should be he photogallery how about that we need a picture preferably with just him in it he needs to have an official portrait as what he needs to have wow that looks ok this is gonna be pretty hard guys this is gonna be pretty hard let's try this one ok let's see if I can maybe that is going to be a known image right so we're going to go to demo images and known and then let's see if we can drag-and-drop that I believe that worked now we need to rename it because he is known renamed Chuck how did we decide to spell his name s CH um er alright so that looks good I have no idea whether this is gonna work or not because that that one picture of him the unknown was really almost a profile so I don't know I don't know how well it's gonna like that or not okay it's starting the recognition and I think I did leave it set on that I mean I did leave it yeah on the u4 that's the one we won't look at let's see if it can recognize all Chucky making our way through the recognitions Chuck Shumer it's learning whoa what is that nonsense line 18 it doesn't like maybe it didn't recognize him as a person you think I'll wait a minute DUP would that in the wrong one no demo images no where did I put that am I going insane oh there he is let's see that is a pretty small image and so probably yeah that probably it didn't grab him as a face because the image was too small so let's try to see if we can find a better picture of him and let's get rid of that one we will move to track it's kind of good when these things happen because you can kind of see what to expect so let's see how about Oh fish oh poor trip Chuck Shumer I can't believe I'm spending this much time looking for pictures of Chuck Schumer okay okay let's see this this is probably gonna be bigger okay I'm gonna get like the 800 pixel okay that looks good let's see if we can drag that over here it looks like it went okay our friend the Wikipedia is always a good place to get pictures because they're pretty much you can find a lot of public domain pictures there so we are going to rename Chuck Shumer okay so hopefully this time it will recognize him as a human being that would be nice so we're gonna come here we're gonna right mouse click in run file in terminal yeah I think that it didn't find him as I face and because it didn't find him as a face it errored out when it tried to do the encoding because there was nothing there hopefully it will work this time we are stepping our way through stepping our way through because where are we gonna go next with this Chuck Shumer don't crash don't crash don't crash please don't crash please don't crash we're thinking I think it's thinking longer this time so it could be good oh do you see that Wow look at that it's found Chucky we found Chucky okay it's this like I don't want to find that guy but unknown unknown Nancy and Chuck and this is really not at all like that picture that we trained on it so this is pretty darn good okay pretty darn good all right you know what now what is the problem so there's all these there's all these oK we've trained we've stepped through all of these knowns but then what do we do if we if we want to look at an unknown we have to kind of load it change the program load it change the program let's see if we could step through these okay let's see if we could step through the and so what I am going to do is I'm going to see if I can change up this program and add some stuff to it and have a step through the unknowns and show them show us the unknowns one at a time and that way you could have one group of knowns and then your unknowns you could just step through and then you could find your matches all right so this is going to be a lot like what we did before but now this business this loading of the test stuff we're going to have to put that in another one of those walks okay so let's make sure one thing is that I am going to need a counter and so I need to go ahead and put in a J equals zero and that will allow me to kind of count through the pictures later on so we ought to go ahead and do that and then we're going to come here and we're gonna print the names and then we're gonna set up our font okay just like there we're gonna set up our font but now everything from here on down I think maybe I can be clever okay maybe I can be clever I hate it when I try to be clever because a lot of times it doesn't work okay so I need to go ahead and I need to set up a directory for where I want to walk through again just like up here I said image directory well I want to set up image directory again that I want to what I want to walk through but this time what do I want to walk through I want to walk through unknown okay does that make sense I want to walk through unknown okay now what I'm gonna do is I'm going to need to step oh that was not good okay now I'm going to need to step through okay what am I gonna step through well I'm gonna do the walk so it's gonna go it's gonna give me the route it's gonna give me the directories which the route is always just where I started there's not going to be any directories but I got a a spot there for it and then step through the files okay and then in what OS dot lock and what do I want to walk through image derp for image directory okay so I'm gonna walk through that okay now I've got to create that okay but now okay so now what I have is I have a list of files so now I need to walk through those files so so root is always going to be root there's not any directories but I got to put a place there and then what I okay and then what I've got to do is I've got to catch all the files so I'm gonna have an array of all the files that are in that unknown folder well I need to step through those files now so I'm gonna say for file singular in files the array okay and I'm going to go ahead and print the route just to make sure this looks good and then I'm gonna print the file so I can see where I am just would help me in doing it and now I am going to have you know this I'm going to load this test image now so I'm going to tab this over so it's inside that second for loop so now I tap it over so that I'm going to be looping through the images but I don't want to rewrite all this code so the test image is going to be face recognition load image okay okay but what I need to do is I need to create that test image now all right so test image path I got to tell it the path to the test image and that's going to be again Oh s dot path dot join root and file okay now that is the path that is the path to the image okay now what do I need to do I need to load it let me just call that test image okay so the test image is joining the root with the file and that should be that long path that goes all the way to the file and now that I have that I should load that instead of loading this specific one I will load that one that we just grabbed okay so this is test image if I'm thinking about this right so test image I create the name and then hmm this is this is pretty poor this is not the image this is the path okay that's the path to the image test image path and then I load it into a picture that I call test image hopefully I didn't confuse you too much there okay I just loaded it all right so now that I have loaded I now have an image so now what do I want to do I've got a test image what do I want to do I want to find the face positions so now I'm just going to tab this over I'll find the face positions in test image right and now I need to encode it so I'll find the encoding so you see this is just what we've done before but it's now inside of a loop okay it is now inside of a loop all right so now all encodings and let's make sure test image and face positions and I got face positions now I need to take that test image and I need to convert it back to something OpenCV will be happy in so a lot of this is just kind of tabbing over for right now if I'm if I'm careful now what so now at this point I'm stepping through the files now as I'm stepping through the files I also have to step through the faces in a given file so this will need to be tabbed over inside that for loop and then this and then this and then this and then first name needs to be inside the if names needs to be inside the if and then here I just do that inside the for loop so most of these here were tabbed over twice just make sure you're doing your tabbing exactly the way I am okay so now what I want to do is I want to tab this over once and twice this over twice this over twice and this over twice okay I think there's some chance that this would actually work unless I like changed a name in there somewhere but let's right mouse click and let's go ahead and run Python tile in terminal so guys hopefully you could see that I was tabbing twice to get underneath the right four loops okay it looks like it's training going through the trainings okay boom the first file that it looked at was an unknown picture of Donald Trump and it identified him it's Donald Trump now if I if this is behaving the way that I think it should I should be able to hit Q and then it should come up with the next image it recognises Donald Trump double bump double chest bump okay I hit Q again Mike Pence Nancy Pelosi and Donald Trump q okay you guys see that like this is like on a big image this is running slow so that next image was was big but it does recognize Mike Pence that was slow because it was a great big picture it took a while to find the face so you can imagine where are we going next with this well the direction we're going towards is live recognition in a video and we're building up to that but you can see that we've got it working good but we're gonna have to play around and get things running a lot faster but to begin with we just want things to run okay Donald Trump Nancy Pelosi do you see I tried to get kind of like a diversity of pictures and it's really doing a good job with the diversity of pictures and actually recognizing the people that we trained on ah mr. Palma quarter-cup tech boy calm with one of my students here and it recognized chases Chase and me as me even though it's kind of a little bit of a fuzzy picture there and we're waiting Mike Pence Donald Trump very good okay Nancy Pelosi that looks a lot different than the other pictures and so that's pretty good and then Nancy Pelosi very different picture than what we trained on that's good and then we're gonna come up to Donald Trump might Pence and Nancy Pelosi very good we're at a hundred percent so far Charlton Heston Ronald Reagan that's really good and now look at this this is the first error that it made it found the four faces it knows that it doesn't know him doesn't know him recognize Mike Pence but it mistook me for Donald Trump happens all the time I'm often confused with Michael truck with a with Donald Trump but that is really peculiar because that I just would not think that it would have picked me over Donald Trump but nonetheless that is what happened and then let's see if there's any more in here we'll just have to kind of wait for it to show us that it's done okay we got Chucky the unknown person the unknown person in Nancy and this is this like Dennis Hoyer or someone like that I don't know and it doesn't recognize him as being a human being but it does recognize Chucky and Nancy okay and then let's see if there's any more in there and that's it the program is done okay so you see you can go in now this is so exciting is it just me or is this really exciting you can put your known people in the known you can put your unknown people in the unknown and then all you got to do is be sure and label the known people correctly with your filename having the label and then you can just go to town with this is this not neat okay guys I am having a lot of fun with this and like I say you can see that we're moving towards having live recognition with why video but the hardest part we've already done that then moving forward is going to pretty easy I do believe okay guys if you guys are enjoying this give me a thumbs up make sure to subscribe to the channel hit the bell so you'll get notifications to my new videos that are loaded and again really really really want to thank you guys that are helping me at patreon you're really giving me a huge encouragement and keeping me motivated to keep making these videos okay this is palma quarter from top tech boy calm I will talk to you guys later
Info
Channel: Paul McWhorter
Views: 7,807
Rating: undefined out of 5
Keywords:
Id: 2G_9LM4OVpM
Channel Id: undefined
Length: 63min 34sec (3814 seconds)
Published: Sat May 16 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.