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 Ill. 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, lets. 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 she’ll 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, lets. 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 lets. 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 lets. 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 we’re 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].