Train YOLOv7 Object Detection on Custom Dataset in Google Colab | 4K

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
this video is sponsored by  Altium more on that later i'm going to show you how to train YOLOv7 on  a custom data set so this tutorial is based on   the official YOLO v7 repository by wong kin  Yiu and alexi ab so let's go through all of   the steps that we're going to be covering in  this tutorial so if you look at our first step   which is to install YOLOv7 dependencies next we're  going to load our custom data set from roboflow   and this is in the yellow v7 format now let's take  a look at the data set we're going to be training   if you click this link over here it will take you  to this page right up here and if you click on   health check this is a really cool tool  for checking the quality of your data set   now from here we can see that we have around 6 000  images and in total just under 7 000 annotations   now this feature is really cool this shows you how  balanced your classes are we have just under 6 000   annotations of trash and just over 1 000  annotations for not trash which you can see   is severely underrepresented getting back to our  collab once we imported our data set from roboflow   into the collab we then gonna be running our  yellow v7 training once the training has completed   in step four we are then going to be evaluating  the performance of our model in terms of our f1   and precision recall curves then in steps 5 6 and  7 we're going to be running yellow v7 inference on   test images video as well as webcam now before  we get started we are going to be launching a   course on yellow v7 which is going to be a really  comprehensive course now just note that before we   get started with this tutorial we are going to  be launching a full course on YOLO v7 now this   course will cover running and training yolo v7  not only in google collab but also on windows and   ubuntu operating systems i'm going to be showing  you everything that you need to know including   yellow v7 with object tracking using pi track  deepsort and norfair object trackers and then   from there we're going to be building eight more  web applications using YOLOv7 so you don't want to   miss this if you want to get notified of the YOL  v7 course you can click this link over here to   get started with yellow v7 and then you'll be  notified very soon of when we'll be launching   the course right so let's get started so in  order to get this notebook what you need to do   is to head over to the project store you can click  this link over here and it will take you to the ai   project store now the ai project store is where  you can get a wide variety of projects from heart   rate measurement using yola r to number plate  recognition determining heat maps mass detection   parking space detection measuring objects using  yola are and much much more now the project that   we are interested in is this one here which is  training yellow v7 in google cola so you're going   to click get project and it'll take you to this  link over here so you can click this link here   to sign up and you'll be given access to this file  over here called train YOLOv7 dot ipython notebook   you're going to download it upload it into google  drive in any folder that you want and then you can   double click it to open up this goal app notebook  so let's open up this tab over here we're going to   be needing to see all of the files that we're  going to be downloading into our google drive   over here and with that open we're going to click  play over here to run our first line of code and   this will link our google drive into google collab  so if it prompts you with this click connect to   google drive you can sign in over here you're  going to scroll down and say allow and then we'll   wait for the drive to mount by the way if you ever  wanted to implement computer vision on a jet nano   but can't really find one maybe it's due to the  chip shortage or something like that well i've   got great news for you because there's a company  called octopod where you can find just nandos   and raspberry pi's amongst many hai hardware  octopath is like the google for electronics parts   but integrates seamlessly into optium and  this allows you to design custom printed   circuit boards so if you are into designing custom  hardware for your computer vision enabled cameras   then ultim design is the most reliable software  for your company or project you can get access   to a free 15-day trial of ultim designer  and access octopod in the links down below   cool let's move on to 1.2 which is installing our  dependencies so let's run it over here so i've   created a forked version of the official yellow v7  repository mainly because if they change something   on their side we don't want it to affect the  code on our side we're going to be installing   our requirements from the requirements.txt while  also installing roboflow so this will take a while   so you can just let it run okay cool it seems our  dependencies have been installed now let's scroll   down over here now if it shows red don't worry  it's not all doom and gloom everything is still   fine keep calm now it is asking us to restart  our run time make sure you don't go over here   and restart otherwise all hell will break loose  and you'll have to start all over again so click   here to restart the runtime say yes and then  we'll look over here to see if our runtime has   been re-initialized okay cool now we can continue  next up we need to get our data set and this is   the trash data set that we spoke about earlier  from roboflow so you can use this link here to   open it up you can either sign in if you already  have an account with roboflow or otherwise you   can create an account i'm going to just sign in  and then once you are signed in you can click on   this link over here to download the data set it's  going to ask you to export in a particular format   we're going to select yellow v7 by torch of course  and then we're going to say show download code now   what you're going to do is copy this part over  here this will include the api key from roboflow   which is very convenient in my opinion now you're  going to copy this over here now before we paste   it into our call lab i just want to mention that  i've already installed roboflow so we don't need   to copy this line of code again so just copy this  straight as it is and then we're going to paste   it right over here otherwise you can just get  your api key and then paste it right over here   i'm just going to paste this whole code over here  and my api key should be populated right back over   here cool so once we have that we can run the  cell here to import our data set and while it is   importing i just want to bring your attention over  here to g drive and then if you go into my drive   you'll see that we have a folder for yolo v7 if  you open up this folder you'll see that we have   all of the files and folders for yellow v7 to  be trained as well as to run it and then once   our data set has been imported you'll be able to  see our data set in there so i'm not sure how long   this will take you can pause the video right here  wait for the data set to download and then we can   return back to this video a few moments later  alright so we have our data set downloaded from   riverflow you can find it right over here  called trash five you can see that our data   set is organized into folders of test drain and  validation which in my opinion is very convenient   cool so let's get on to running the training for  yellow v7 first thing we're going to do is to   change our directory to the yellow v7 folder  which is this one over here right and now we   can decide to train whichever model we want in  the YOLO v7 range so from yellow v7 x w6 e6 d6   and e6e i know it sounds quite complicated but  you have the whole buffet of YOLO v7 to train from   so i'm going to train the normal YOLOv7 which is  this one over here however if you want to train   another model of your v7 all you have to do is  just uncomment this one and you can comment that   one right so let's download our weights cool that  has been done let's move on to point 3.2 which is   to start our training now there's a number of  parameters that you can set in order to get the   optimal performance from your yellow v7 model we  won't be going through that now in this lecture   we'll be going through that in the course but for  now we'll just use these standard parameters which   we can go through right over here so first  up we're going to ensure that we are still   in the yellow v7 directory and then we're going  to run python train.pi with the patch size of 16   we've got our config files and over here we can  specify the amount of epochs we want to train so i   specified around 55 epochs you can decide whether  you want to go up to 100 or maybe a thousand   or maybe 10 000 or million or i'm just kidding  we can just rental 55 epochs cool and then we   specify our weight which is yellow v7 dot pt now  this waste valve must correspond to the weights   that we downloaded right up here now to use one  of these other models we first have to download   them before specifying them in this command  over here so for example if you want to train   YOLOv7x then we can just put that over there but  we'll just give it to YOLOv7 for now and then   device zero means that we will be training this  on the gpu and then over here we'll be specifying   our device that we'll be wanting to train our  YOLOv7 model on and in this case it will be   the default collab gpu now just note that colepro  will train much more faster than the free version   of golab and mainly because the paid version of  golab gives you access to faster gpus as well as   longer inference times if you are on the free  tier just note that your runtime will restart   a lot of times and by a lot i mean many times now  when that happens you're going to want to restart   your training which can be quite annoying but when  you do you're going to change this from YOLOv7.pt   to the last weights that you've trained  it's going to be here in runs train exp   underweight and then you'll find your last weight  over here so as you can see in my case the last   checkpoint that i drained was 54. so when you are  ready and feeling brave you can click this button   over here to start your training now i'm not going  to go through the entire training process because   this can take many many many hours now i'm not  going to sit through hours and hours of training   because i've already trained this before i'm  going to be using my last save checkpoint which   is epoch 44 you can use the same if you don't  want to train it on this particular data set   and you can do this by going back to the ai  project store back to the same project which   is training your v7 detection in google collab and  i've added the last trained weight right over here   so you can download this and upload it back  into the google collab environment you can   upload it anywhere you want so you can click on  this dialog here to upload it to google call app   now because i already have it here in google  collab i'm not going to re-upload it what i'm   going to do instead is move on to step 4 which  is the evaluation so once your model has been   trained you'll find that our model has generated  the f1 curves the precision recall curve as well   as our confusion matrix this you can find over  here in YOLO v7 runs train exp and you'll find   these images right over here so this is the f1  curve pr which stands for precision recall curve   and then we have our precision curve recall  curve confusion matrix and so on and so forth   so as you can see we have our f1 confidence score  curve right over here so basically this tells you   how well our detector performed so if you don't  understand what f1 is we will explain it in our   YOLO v7 course and then we'll be posting a comic  which will be talking about how do we measure   accuracy in terms of all of these parameters in  plain and simple language cool then we have our   precision to recall curve we have one for the  trash class which as you can see is performing   really well especially in contrast to our not  trash glass this thick blue line shows the   overall performance of both classes ideally we'd  want our curve to be as close as possible to the   top right hand corner over here as in the case of  our trash class if you want to analyze it further   you can check out our confidence matrix so did  we predict trash in the case where they actually   was trash or in the case of not trash did we not  pick up trash in the case where there was no trash   so we would want these numbers to be close to one  as possible so in this case the predicted trash   was very close to one which is good and we got  about 87 percent for the not trash class which   could use some improvement great next we move  on to section 5.1.1 where we're going to run   inference of our custom YOLO v7 model on a folder  of images so we're going to click this command   over here to run the evaluation you can change  your weights over here to the last waste that you   used or to any of our saved epoch checkpoints over  here so say for example if we want to use epoch 54   we can just change this to epoch underscore 0 5  4. you can change your confidence score over here   as well as the folder that contains all of your  source images so ours will be here in trash five   test folder and then we're going to be selecting  this image directory over here cool so as you   can see it has processed all of these images  in this folder let's see if we can view them   so you can run the cell here to display inference  of all images otherwise you can even open up this   one over here otherwise you can go to the source  which is in runs we're going to go to detect exp2   right oh it's one of these yeah we have it here in  exp3 so let's open up one of these and let's see   what we get so cool it works for this first image  that we have over here so it says our samsung   phones are not trash i have a samsung phone over  here so i don't have to throw it away anytime soon   let's move on to the next image which is a  whole bunch of items which has been detected as   not being trash you can check out the next one  so this is a cigarette which we can classify   as trash because because smoking is dangerous  kids and don't do drugs so you can really play   around with this and test it out on your own set  of images now we can infer on custom images we can   run this helper code for inference which is pretty  quick we can then move on to our configuration   parameters and this is where we set our classes  that we want to filter so now we don't really   want to fold any classes out because we want  to detect trash and not trash but for whatever   reason we can always specify over here to say  that we do not want to show not trash right   not trash hopefully i spelled it  correctly let's just check out our   images again not trash so that's us for the  space right so that's not trash with a space   cool and then if we do this it'll only show  objects that are of class trash but for now   we can just keep it to none great so this is  the configuration parameters that we'll use for   images video and the webcam so you can specify  which weights you want to use so i'm gonna change   this to epoch weight five four so that is the  one that we will have here in our drain folder   exp weights and it'll be this one over here  just make sure that the directories match up   before you click run we can specify our image  size our confidence thresholds our iou score   as well as what device we want to run it on right  now we only limited to google call ups free gpu   or in the case we're using google pro you're  actually paying for the gpu and then we have our   classes to folder great so then we'll move on to  section 5.3 which is inference on a single image   now we're going to run this command over here just  to change our directory and we are also going to   be downloading an image now if you can upload  your own image make sure that you rename this   thing over here so that it doesn't give you any  problems down the line so we're going to click run   over here and then we can run all of the code  for inference okay so i had a bit of an error   earlier it was mainly because it could not find my  weights now to avoid this error in future what you   need to do is just go over here right click on the  weight copy path and then paste it right over here   so that way you can avoid having any other errors  great so once that is working we can scroll down   and then run this it is implementing cv dot i am  show of the image up here and this will display   our image for us to view great so as you can see  we are able to differentiate between objects that   are trash versus not trash now just note that  this model is not perfect it will misclassify   in many circumstances and that's because we've  only trained around 45 epochs if you want this   model to perform better what we need to do is go  back into roboflow and ensure that we have a lot   of examples that are not trash so that we have  a balanced data set and avoid data biasing the   second thing we can do is to train to maybe 100  or maybe a thousand epochs and then we can also   play around with model parameters to ensure that  we have fine tune our model so that it works as   intended great so let's move on to section 6 where  we're going to be influencing on video so we have   three options for importing our video so the first  option is to upload our video via a dialog so we   can click choose files look for our video file  and then click open i'm going to skip the step   and click cancel because i want to use the video  from google drive that brings us to 6.1.2 which is   to download our video from google drive is using  the g down command and the identity of the file   that i'm sharing through google drive and then the  final option is to download from any public url   i don't have any public urls on the top of my head  so i'm going to skip the step but it is possible   to pulling a video from the internet cool so  here in 6.1.4 we're going to enter our video path   just note that if you change the name of the video  you'll have to change it here we will definitely   automate this process in future and then we can  go on to section 6.2 which is influencing on video   so let's click the play button and scroll down and  wait for our video to be processed so this is a   pretty big video there's about 1234 frames so this  processing depending on which plan of colab you're   on could take anywhere between one minute to maybe  around 10 minutes on the collab pro plan you can   see that it's working pretty quick now just note  that if you are planning to train your models in   the cloud using google collab most likely you  will want to buy the pro plan of google caller   let me tell you why if you are on the free plan  of google collab your runtime will most likely   disconnect and it's going to be super frustrating  for you to reinitialize that every time you want   to continue training your models and it's just  a big headache so i would recommend forking out   i think it's nine dollars per month i mean just  train your models for one month for nine dollars   and then on top of that you may need additional  google drive space so i'm on the one plan of   google drive which gives you about a hundred  gigabytes of storage i think i have additional   storage i'm not sure why i have additional storage  but having this much space especially training   models like your v7 you're gonna need a lot of  space so the initial 15 gigs of google drive space   is not sufficient for training large models like  YOLO v7 so i definitely recommend that you upgrade   your google drive to the one plan which gives you  about 100 gigabytes of space and that should be   sufficient for training your YOLO v7 models cool  we can scroll down and we can click this button to   process our video otherwise we can find our output  file which is in the yolo v7 directory and it's   called output.mp4 which is this file over here now  you can either click over here to download it or   you can head over to google drive find the folder  and then you'll find it right over here now i find   that downloading it from google drive to be faster  than downloading from collab so that's what i   normally like to do you can also preview it right  over here if it allows you to okay cool it allows   me so i'm going to click play over here and you  can see that it's detecting trash and not trash   objects cool so as you can see it's working pretty  well and that's only on 24 epochs if you want   to download via the collab environment you can  click this command over here and it will download   this file your browser and then finally we can  perform inference on a webcam so we're going to   execute some of these helper functions okay  cool that is done there's a lot of javascript   magic that is happening in the background here  it's just too much to explain in one video as it   is this video is very long and then we can run  our video stream over here so cool as you can   see we have yellow v7 working on a webcam in real  time but just note that there is a lot of latency   mainly due to the all the javascript magic that is  happening right up here and running this in google   collab obviously it's not ideal but nonetheless  we are able to get YOLO v7 running on images video   and webcam cool so if you enjoyed this tutorial  you can buy me a chai or coffee right over here   i sort of grown in affinity for coffee you can  check out all of our courses in computer vision   right over here we've got a course on image  segmentation with unit another one on just nano   self driving car specialization yolo R which is  our most popular course ever because we built 18   applications with ulr we built a full computer  vision dashboard with yellow x we've got a drone   programming course we've got object segmentation  word tracking using cmes networks and much more   courses to come otherwise if you just want the  project itself you can head over to our project   store which you've seen before and then you can  scroll down and then select any of the projects   that you want to try out and if you aren't  already subscribed to my youtube channel you   can click this link over here it'll take you back  into youtube if you're not already watching this   on youtube you can click that little button over  there with the bell icon to subscribe cool thank   you for watching and if you want to learn more  on YOLO v7 you can click this video right up here
Info
Channel: Augmented AI
Views: 49,030
Rating: undefined out of 5
Keywords: darknet, object detection, yolo, custom object detection, train yolo in cloud, cloud, google colab, object detection classifier, custom detector, custom yolov4, deep learning, yolov7, yolov7 cloud, yolov5, yolov7 tutorial, install yolov7, train yolov7, augmented startups
Id: kbMfgVZn05U
Channel Id: undefined
Length: 22min 36sec (1356 seconds)
Published: Fri Jul 29 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.