Train YOLO to detect a custom object (online with free GPU)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi welcome to this new video tutorial I'm going to create in this video a custom object detector which detects a koala but of course you can choose your own object we will see this in three steps first we're going to see how to prepare the images to be trained with Yolo second we're going to upload all these images online on the Google servers so that they can be processed for the training so you don't need a powerful computer or GPU because all the processing will be done online using the Google cloud GPU for free more detail about Google co-op and Google cloud GPU for free I will give them in the second step and finally after we have set up Google collab and three in our model we will test our model to see if it really works well this is all for the moment let's start first of all let's prepare the image data set the image data set is going to contain a lot of images where it is the object that you want to Train so for example here I choose a koala and I downloaded around 350 images of koalas you can see them here so you have to download many images of your own object the more you have the better I will suggest to have at least as a minimum of 100 images and if you have 400 or 500 is even better so for example let's see the example of the images I have so here is the koala here is also the koala and it's important that there is your object inside but it doesn't matter if it doesn't take all the image for example here I have a big image but the koala is really small and also you can have more objects so you can have a color there can be other objects that you are not interested in because later we're going to select what is our object so if I go on this is an example of data set so here for example we have two koalas one and two and we're going to select them all our goal once we had the image data set is also to tell in which exact position is our object we cannot just give the images and say nothing else we give the images so for example here we have two koalas and this koala is placed in this position first kala and the second is placed in this other position so the disk we are going to use a software which will make this operation really simple for us and we have a free software which is called label mg and is available for Windows Linux and Mac also here you don't see the Mac but it's also for Mac I will put the link on the block in case of the Mac now as I'm using Windows I will go with the one for Windows and we're going to download the software and then we can open the software so Windows and then label oMG let's run this one now here is the software we are going to use the software to select our objects in all the image data set so first of all we have to open the directory where we have our images and this is my directory so I'm going to copy this then I go to open directory you can of course loop for the directory on your computer I will just copy here the path and open this directory and then I press on select folder once this is done we have to set something else on the software then for example where we want to save our files and we put the same directory where our are our images and we select the folder then we change here the format we have two formats we have Pascal and then web yellow as we're going to Train yellow right now we want to save it them in the yellow format once we have done this first operations is the time for us to select our object so I press on create rect box and we can start selecting our object and I'm going to select deco ala for all the images that I have so I start with the first one the label is a koala and okay then we save this and we go to the next image and this one okay I didn't know I had this one on the data set anyway it's still a koala second image okay save this then this one this one is really chilled on the tree create red box and then koala and save next and we do this for all the images that we have so I'm going to pause the video I will do this for all the three onion plus images I have and then how we'll be back and here we are again after we are done with the selection your data set will look like this we have the jpg image and then we have a txt file with the same name associated so if I open this file here is simply telling us the position of the koala on the correspondent image so for example zero is the class we have only one class so we are going to work only with one custom object then we have the center X of of the color the center Y of the color so the image is 0 to 1 so at 0.4 there is the center y 0.46 they started there 0.4 it is the center X 0.46 the center Y here is the width and then the height and the software that we used to select our custom object does this for us you don't really have to know what's inside I want to just to show you how this works then on the folder where we have all of them we do one simple operation we select them all a press ctrl-a and we're going to put them into a zip archive so add to archive and then zip format and let's call this one images dot z images dot z and please remember use the same names I'm using so images dot deep must be images of zip and not any other name so not qualitative or something else and the reason why is because I prepared the code that later will look for images sleep so if this is of different name it will not work so that keep that in mind so I created images dot zip which should be now at the end of the file so here images dot zip and so if I open this it will look like this we have the image jpg and then associated we have the texture file for all our images and at the end of this operation our dataset is ready so we can now switch to the other part of this tutorial where we will see how to use this data set to be trained for our custom object detector once our data set is ready some once we have the archive images dot zip with the images inside in the txt file we the position of our custom object we can now switch on to Google collab Google collab is a service offered by Google so they give you ready to use a free GPU they give you a Python editor and Ubuntu already installed ready for the use and if you are wondering about what GPU do you get so free access to GPUs if we go on Google Cloud GPUs and we check here accelerated computing here we can read deep learning physical simulation and molecular modeling are accelerated with NVIDIA tests like hey Eddie pit for tip for p100 and V 100 GPUs you are getting some of these GPUs each time you connect to the collab you will get at different settings most of the time you will get a test like 80 which is the cheapest one but still really decent GPU so the range of the cost they go from 1,000 euro the Tesla 80 which should have around 12 gigabyte of RAM or 24 gigabyte of RAM because you get half of the GPU for this one then increasing we have the P 44 P 100 which is around 5,000 plus year and then the V 100 which is 20,000 plus Europe most of the time you will get tests like it sometimes I got the P 100 so they are really great GPUs to use what are the advantages of google collab and the disadvantages of course advantages that you get a free GPU which is really expensive so you can just work with your lot top and a disadvantage that you have access only for 12 hours after 12 hours you get disconnected and you lose all your files you can use again Google call app but you have to start everything from scratch we can stop somehow this problem connecting our Google Club with Google Drive so we're going to save the file on our Google Drive so that even if the club get disconnected we will still have our files on Google Drive let's start from Google Drive so you go on Google calm / Drive then go to Google Drive if you have an account we are going to login if not just make your account I have an account so I'm just going to again I enter the password and here it's my Drive it's in Italian I can I don't know how to change the language so for this parts it will be Italian we're going to create a new folder and I call this yellow v3 and just follow what I'm doing exactly stop create the same father because my notebook which will do all the work is made in order to work with these specific folders so just call this yellow v3 all lowercase letters and inside Yolo v3 so we enter in the folder we're going to put our images dot zip file so I take this one and images dot zip it is going to be here inside and let's wait that the upload finishes and then we can continue I'm going to post the video waiting for the upload ok now the file images that zip has been uploaded and in the meantime I was also able to switch the language with English now we have my drive and then we have a folder Yolo v3 which keep in mind must be all of it three capital letters and inside images dot zip inside images dot zip you need to have the images dot jpg and the txt file now let's go on Google collab so collaboratory schedule google.com and then sign in and we need to use the same account we used to log in on Google Drive and here we're going to upload a notebook so upload and this notebook is on my blog so you can download a notebook and then you can upload it and I have it right here so here I downloaded the notebook then I upload this notebook and here we have the file so let's do the first steps first we need to enable the GPU on Google collapse so we go on edit not good settings then runtime Python 3 this is by default and then other accelerator you select GPU and then we press save now to make sure that our GPU is enabled we go on the first-called box and we press Start so nvidia sm i this one and it takes few seconds so now it's connecting and initializing the notebook and here we see our configuration of the GPU now I got the Tesla p4 so here is the GPU that you got here is the memory it's 8 gigabyte of memory of RAM and here is the RAM that you're using still 0 because we're not using it here the percentage of using of usage weren't using it yet then second step we need to collect our google collab with our Google Drive so we go on the second box and we press run now it is asking to our permission to access to Google Apps so we need to go to this URL accounts.google.com account and we're going to allow Google app for Google file stream and we select allow and here is the code that we need to copy so we click here to copy the code then we go back on our Google Club in here it asks for authorization code and we can paste here the code and then let's press Enter okay our drive has been mounted so we see collab notebooks and Yolo v3 which is the folder that we created before from now on we don't have to do anything anymore for our training because all the code is written here so what we do we just go on run time and then run all and I will explain step by step now it is download in the darknet darknet is the framework which we used to train Yolo once we download the darknet we need to compile the darknet compiled an arc net in order to work with the GPU so here what I did I changed the settings to be to enable open CV so open CV is enabled the GPU is enabled and also see you the nm which is a configuration of the nvidia gpus is enabled and now this step is still in progress when we see this it means that it is still doing the compiling of the nvidia of the darknet with nvidia GPU and we can go all down to see it slowly the next steps after the darknet has been compiled we can see we have to configure the darknet to work we all have it Redford with 3 for the training and here is what the code after is for so here we are configuring the Yaffe 3 file to work with just one class so keep in mind that all these would work with just one class so for example only one single object to work with more objects you need to change a few settings so that's not the case for this keep in mind choose only one object and so all this code is for the configuration then we go to the number four number four is going to extract the images that we put on images zip and it's going to put the images into the darknet so that this images can be processed later these images will be inside the darknet folder and then we're going to create I mean it is automatic in this section of the code it is going to take all the list of the images and putting all the names of the paths on the 20 X 10 which is all the images that our custom detector is going to use for the training so we're going to use them all and this is probably the slowest step when it is downloading now the model the starting model that we are going to use to Train Yolo v3 this is really slow you see just 5% because the connection of the website were three is this file is quite slow so I'm going to pause the video until this file is downloaded I let this running for around three hours already and if we check our current situation 1385 iteration has average lost 0.15 it's of course better if you leave it as long as it is necessary so even a few more hours but already some really low value of average loss can be a reliable result for our testing so I'm not going to test it to train it even further because it's not necessary but if you have the chance keep and leave it going as it is so I'm going to stop the training right and as we are waiting that we stop the training we can see 1389 iterations average lost 0.14 now it's the moment for testing the model so where is our model well our model we can find it easily on our drive so we go back on our Google Drive so my drive yellow version 3 we open this and we see now two files new y'all of v3 training 1000 and yellow v3 training last weights this is our model this is the last model that we got and this was the model after 1000 iterations so most likely your model will be at its best after and the last training so after all iterations so what you should be supposed to use is this one which update is updates the iteration each 100 so this one was after one thousand three hundred iterations and of course you get also the backup for each 1000 iterations of the training so you get one thousand two thousand and so on we just need this one so if you don't want you can remove that one you can also try all of them to see which one works best so I'm I'm now going to download this one you all of you three training and I'm going to put this one on a new project where we're going to run Yolo from the computer with open CV so I downloaded already a few of them so I will just change the name I will call this with the number three after and as I'm waiting that these downloads I'm going to explain how we can train the new object detector so I'm going to open the new project I developed this code to load a lot of images so that we can test it in real time with many images this code is a small about adaptation of the code I released on my tutorial on YouTube regarding detecting object with y'all and OpenCV so let's check how to use this code I'm going to increase the size so that everyone can see it we have only to edit these three lines and all the rest you have to leave it as it is so all these is the detection using the Euro algorithm and OpenCV and on the first line we have to load our work train model so web to load the weights that I'm just downloading right now that we got all of v3 testing CFG this one I'm going to put it as it is so you you can download this one with the code so CFG is already on the file the classes here you have to put the name of your class so I detected color so I will put koala if you detect it another object you can put the name of the object you detected and this is going to work with only one class so you cannot put more classes just one class this image is phat here we're going to put the path where our images are located so that we can test our model so the same folder that we had before with our images we can use it now for testing our model so I'm going to copy this path copy and I'm going support right here and this way so it is going to take all the images which are inside the folder and that's also I'm waiting that the models the model is downloaded so I'm going to check if it's already downloaded so here we have already the model you all know field three training last three so most likely you have just Yolo b3 training last I downloaded them also before so that's why I call it with number three and let's test it so I run this one so call on the first image is detected correctly let's go on Kohala koala what this one didn't work you can see that except in just one of them it works in general really well with the detection and of course if I left it training few more hours it will work even better so even probably the one that wasn't able to detect it could be detected with a better model but already after just three hours of training you can see that we were able to build a model okay this one will small cannot see the column I think this is enough you can find more detailed instructions and this code that I just used to test our model on my blog so you can just click the link below in the description this is all for this tutorial hope you enjoyed and see you in the next video
Info
Channel: Pysource
Views: 107,640
Rating: 4.9489756 out of 5
Keywords:
Id: _FNfRtXEbr4
Channel Id: undefined
Length: 27min 56sec (1676 seconds)
Published: Thu Apr 02 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.