How to Create a Custom Object Detection Model with TensorFlow

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey you welcome backspin again today we're taking a look at training our own custom objects for a tensor flow object detection API so if you watch my last video last time we set up the tensor flow object detection API to work on our computer and on the cloud using Jupiter notebook today we're going to be looking at how to make our own custom data set using a custom object so we can detect any object that we want to so let's get started with it okay so right now I have what we were working on last time which is our object detection folder with has our models from the tensorflow repository and all the work that we did so we're gonna put this aside for now for a little bit and we're actually gonna work on a new folder so this is gonna be our new folder I named it mass since I'm going to make a custom on detector that detects types of face masks because if you know anything that's going on the world right now that might be useful and I just thought it'd be fun to try so we're just gonna use masks for this example so the first thing you do is create a new folder so this one I just named masks you can name it whatever you like I just called it masks that's what I wanted to call it and inside we're gonna need three folders so I just like to make them all at once so I don't miss them later later sorry we're gonna need data images and training and so inside of images you're also going to need two more folders called test and train so in images as you can probably tell we're gonna be putting in image files in there and then training is where training data is going to eventually go and data is a bunch of other stuff that we're gonna need it has in data so before we get to going to our actual images we need to get a program called label image so what we're gonna do actually I'm gonna go back to my label image so I can start from the beginning with you guys so let's get rid of that and I'm just gonna open up a command prompt I'm just on my D Drive here but it doesn't it shouldn't matter where you put it so I have my D Drive here and what we need is we need to go to the label image repository right here I'll link it down below this is what it looks like so basically we use this to annotate our images so right here they show the example of highlighting people so basically this lets us do is that it tells the program or the object ection program hey this image right here this is a person this is a dog cat whatever so we can choose specific objects in the image because it cuts down on training time and it makes the model a lot more accurate so what we need to do is that we need to install this so what we're gonna do is that we're just gonna copy the URL and I'm just gonna clone it right into my D Drive so I'll just get clone that and we should be getting label image that might take a second but we do that I'm also gonna open up anaconda and I'm going to use the same environment that we use last time okay believe I named object activate was it object yeah that's probably it should be fine I can always update if we need to okay so this is done don't want this anymore and so let's see the we have installation so for I'm using Windows and on ik and akanda so we're gonna use this one instead so we're gonna need Conda install PI cute t need QT 5 okay 55 hopefully that works should work again Conda just using Kannada install makes things so much easier pip install with pie cutie did not work so well for me but if you use Conda and makes your life a lot easier so then we just need to run this command right here file does not exist I probably need to be in the correct directory let's go to D oops I think it's correctly D and what I call able image so now we should be able to run this okay believe that's all we need so now we just gotta say python label image cannot import name entry oh we might need to install xml again let's try that whoops tip install it XML Oh XML let's see if it's gonna run import error that's fantastic let's see if we can try to fix this so let's start let's just try doing pip install pi qt5 maybe it might work a little better for us I know I just said it the other way around but we can we can see what happens let me pull up my note sheet again to make sure we're all good okay come on Conda you can do it it's also open up the folder so we can see what's going on so yes you can see after we cloned it we got label image right here so this is the current directory that we are inside of Oh looks like this has taken a little while too so well this goes in the background let's move on to getting our images so since I'm just gonna use face masks I just did cloth face mask and I put up a bunch of images over here so the you probably don't want to have to download each image individually that's gonna take a really long time so well I recommend using is this extension that's named for fat con fact I'm not exactly sure but basically lets you batch download images off of Google and you can put it right into a folder which is really helpful so I have that installed and I opened it up and as you can see it just grabs all the images on the page so we just want to download it let's see do not select a square to save oops I need to change that real quick download so you just need to turn this off a square to save between before each download otherwise every image you ass is gonna say save here save here safe here so we just want to skip that altogether so let's do download and then let's do download image okay I probably did the wrong folder by I did not choose the folders that's my own fault well I guess we'll see where these and open a second we can see all down here we're getting all these images it's trying to save it here okay did he calm down let's see shell unfold a okay so in my downloads they just made this new folder for a cloth his mask which is what I had searched so we have all of our images in here that we need great so now what I'm going to do I'm going to take all of these images and I want to put it and where is it so we want to go back to masks and we want to go into images and we want to dump all the images into here or you can keep them where they were too but we're gonna be moving them around anyway so we might as well put them in here so they all have a bunch of funky names but that's okay for now let's see I think Conda might have froze or I just did control okay let's see if that works I don't know what's going on with that exactly see thank him I went past it python label image cannot import name Eitri you know you think you you plan everything out correctly and it still doesn't work so let's see what we can do for this okay so I just had to fix label image real quick whoops I'm messing up my command prompt here so if your label image does not work like I do is PIP uninstall pup some spelling it wrong I'm in stall xml l XML Alex and Mel creates problems sometimes because the import error comes from there so he's got to reinstall it so so and if we do that we'll just run our commands again that we got from hey which commands this one and then we can just say python label image in there we go so that's what we're looking for right here so this is we're going to be annotating all of our images so we're just gonna open up the directory that we're gonna pull the images from so where did I put that it was here we got masks images so it's this full day so here we go we can see that the images start to pop up this is kind of a bad example but there we go it's a bunch of images so once we have these images we can start annotating them before we do that I'm gonna change the save directory so the save directory I actually want to be the same place so which is why it's okay if you want to have these folders in two different places gonna make some bit confusing because basically when we do the training anyways we need the original images and the data we get together so we might as well keep them together at the same time so we're gonna save to the same folder that we're reading from which would be fine so to create the images or the annotations I got to do is click W you can either use W or you can use you can click the Box on the side over here so now we have W you can can line up the arrows you have or the little lines and then you can just drag and there you go your the box so now over here is gonna ask you what you want to label it as so if you haven't done it yet just create what you want so we're just gonna actually I'm gonna call this one a cloth mask so there we go it's now up here it's saved and it's highlighted so you just gotta click ctrl s for save and then you can move on the next one let's move on to the next image you can just click press D so you can use the a and D keys to move back and forth I don't actually like this picture I need to I have intimidated or not this one's okay ideally you don't want to skip the pictures when you go through them because it's might mess a few things up so actually what I'm gonna do is close this and let's go to our images we don't need this because I just want you guys to be able to do it also images because some of these images are really bad so you can see right here we have the original image that we had and then we have this data file right here which is an XML file so oh yeah a lot of these images are really bad so let me clear something out for a second okay so I've gotten through been deleted most if not all the images that are bad or that we don't want I also forgot to mention it before but you need anywhere from 100 to 500 images per category or per object really so for the face masks I have about how many do I have 226 items in this folder so that should be plenty for what we're doing so now that I've reorganized this a little bit better let's open up a label image again just seeking a little bit better idea what it looks like let's open the directory so we want this one and save directory is this one okay so again we can just start by highlighting some boxes and we want I don't know if it saved my mask let's call this yeah what did I call it before cloth mask yeah suits cloth mask so let's save it and then so basically it's a lot of this and this takes a long time to do it's gonna be tedious it's gonna be tedious progress also for each image you can have multiple boxes in each one too so if you have to like this one so there's multiple masks in here so we can highlight each one although these are all the same like masks you can tell I'll do it anyways let's do a couple of them and try to have I didn't do a good job on this one but try to keep it to as close as you can so I'm not gonna do all these right now so I can just show you guys that steps but I will finish going through this for the next step in the project just so you guys can follow along with me so it's also a good mix to have them in a good variation of location so this one's on someone's face where loans were just on the screen like this one so again you can those ones we got multiple in here so so grab all these and your name you're not required by any means to get all of them in every photo but you see since these all have different patterns it's good for the varieties so it'll start to pick up on things are similar like the shape and the size and like the strings that come out of them and all that and you know there's different types of masks so eventually I might do one where we show how you can have different types of objects you can have multiple objects in your data set because right now we're going to have it detecting for one which is fine so okay so now that we've done this we can move on again so we're not we don't have all the images but we have enough to work with right now and I will go back and do that so you can see in here we have the XML files to go with it so now what we need is another file call it XML to CSV let me pull that up here so this is from another person on github called debt data train that turnout I'm not exactly sure you save so they have really good XML to CSV file and another file we're gonna need I'm sure you could use multiple of these files like or different kinds but this is just the one that centex uses and people probably want to follow along with that so that's what so we do need to make a couple edits to this one and I actually have the edits already so it's right here it's in the main you basically just have to change this to work with the paths and the directories I'm not exactly sure what the original was the original is not quite what you need because we're as good as we're going through these two directories and we need to save them so I'm just making sure image path yeah so I have the setup for our images folder and we're going to be saving the labels to data so you can change this if you need to for yours again you probably should if you're following along unless you're doing exactly like me then it should be fine I have the updated file somewhere else let me pull that up real quick ah where did I put it you know it's probably right here from my own things yeah so I'm gonna grab both of these files right now actually explode need these I will put these up on my github and/or I will link to them in the description so we have the XML to CSV file now I don't believe we need any special commands I could be wrong I write this stuff down because I'm good at forgetting I believe weed you only need to run it so let's just do that we're a mime in label image which is not where I need to be I need to be in what others do oh okay I forget where we were working out of then then your models yeah oh no no we're on the desktop oh my gosh II keep forgetting okay I thought I didn't need to go that far okay I'm sorry guys and we're in the desktop because we need masks now that were in masks we can should just be able to do I say should cuz you never know XML to CSV and there we go so six successfully converted so if we go into data we get our test labels and our train labels oh that's right I forgot I missed a step my bad that's why I was confused about that so inside of our images file you should take about 10% of 10% of your images to put into test and the rest into train so since we didn't do a ton I'll just only put one in there so you want to take both the image and the file that you get with it so will actually take I could highlight them these four and we're just gonna copy them and put them in test and then we're gonna go up to here so we basically want we didn't go that far uh I'll just hand get them tu-tu-tu-tu-tu-tu these copy those in the Train so again you would have a lot more images in here okay I missed this one you'd have a lot more images and files in here which is fine again this is just for the purposes of doing it so for you you'd probably have all these so now that we have all that we should be able to run this again and now that we run it it should look a lot better so if we go into train we can see these so basically this is these are this gives the program the annotations that we made in those boxes we draw so these are just coordinates on the images that we had themselves in the class that they were so that's basically all we need to do for that so that's nice and easy let's look at the notes again so now we need to do the generate TF record which is what the tensorflow uses to help detect our objects so let's look at generate TF record so the only thing we need to change in here is the name of the model so right here is where you would take the what's for the label map since we're making label maps right now so when you do is this change this I was doing a project with Legos before I think I was the object I was using but this one we said cloth mask cloth mask or cloth masks let me make sure you gotta make sure it's the same otherwise it's gonna get a little wonky cloth mask 1k cloth mask okay actually I don't want to save it in here either since this is not the right one but that's all you got to change discard this let's go into here this is the right one open with bhaijaan just change that so this was cloth mask and that should be that and now there are some commands we have to run so there's two commands we had a run there's one for test and there's one for train hey I didn't even know I got this one is for the test one so whoops I accidentally pulled in the not the decimal the bullet point but every call so it's gonna run that specified module could not be found oh no all right so something some problem with the TF record and basically I couldn't figure out exactly why Kondo wasn't making it work but by pulling it into pycharm and just running it through here it does work so again I've some reason why I recommend pycharm since you have the built in terminal right here and I'm sure those dependencies mixed up with like the kind of Python I have I might have different versions of Python which is messing it up so if it doesn't work in one tread in the other so I does open up the terminal down here I'll run it again actually so this is the Python generate TF record and this is just the so these show where the data is gonna go so the labels so let's just run that I'm gonna take a second so I've created the TF record so now that's in data as you can see in here we have trained out record which is great and now we just need commands over here we need the test one so we're gonna run that and there we go so now we have it up here so that's all we're going to do for right now since the next step we're gonna be looking at getting the model that we need to train the new object detection and we're gonna show I'm probably going to show how to go over on google collab if you don't have a GPU on your system and I'll also be doing it on my local computer and we're doing to be going in we're gonna be training and we're gonna be testing but for now that's where we're at and I'll finish getting the rest of those labels set up so I can be at the same spot as you guys other than that that's gonna be it for me today if you can leave a like and subscribe and I hope to see you again next week [Music]
Info
Channel: Lazy Tech
Views: 96,337
Rating: undefined out of 5
Keywords: tensorflow, object detection, custom model, custom object, object detection 2020, tensorflow object detection api, opencv, labelimg, AI, deep learning, machine learning, artificial intelligence, computer vision, object detection api
Id: C5-SEZ_IvaM
Channel Id: undefined
Length: 20min 25sec (1225 seconds)
Published: Wed Jul 15 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.