Train Yolov8 custom dataset on Google Colab | Object detection | Computer vision tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Hey my name is Felipe and welcome to my channel. In  this video I'm going to show you how to train   an object detector on your own custom data  using YOLO V8 and Google colab. And this is   the notebook we are going to use in order to train  this object detector and you can see this notebook   is comprised of 1, 2, 3, 4, 5 steps. So in only  five steps you will have your own object detector up   and running and this notebook will be available in  the github repository of today's tutorial. But now let me   show you something else because we are going  to use Google colab but we're also going to   use Google Drive and this is a directory I have  created in my Google Drive in order to work on   this project and you can see that this directory  is located in my drive computer vision engineer   object detection YOLO V8 Google colab, this is the directory  I am going to use in order to upload all the data   and all the files we need in order to work on  this project so the first step you will need to   take is to create a directory in your google drive.  Now let's continue and now let me show you the   data we are going to use in order to train this  object detector and you can see that these are   many many pictures of squirrels so this is the dataset  I am going to use, I am going to train an object   detector to detect squirrels but obviously you  can use whatever dataset you want in order to train   this object detector. Now let me show you something  which is very very very important and it's exactly   how you need to prepare the data and how you  need to structure the data in order to train this   object detector this is a very very very important  step so please pay attention if I go here you can   see I have a directory which is called data this  is the root directory of my data and if I open   this directory you can see I have two additional  directories one of them is called images and the   other one is called labels if I open images  you can see I have two additional directories   one of them is called train and the other one is  called val and if I open train this is where all   my training images are located so these are the  images I am going to use in order to train the   object detector if I go back and if I open the  val directory these are all the images I am going   to use as validation data these are the images I  am going to use in order to validate the object   detector so now let's go back and now let me  show you what's in this directory which is called   labels you can see I also have two additional  directories one of them is also called train   the other one is also called val and if I open  train these are all the labels all the annotations   of the training data, of the training images, if I  open the val directory these are all the labels   all the annotations of the validation data so  it's very very very important you structure the   data exactly like this you need a root directory  then within this directory you have two additional   directories one of them is called images another one  is called labels and it's very very very important   these two directories are called exactly like this  one of them should be called images and the other   one should be called labels it's very important  you name these directories exactly like this then   within 'images' you will have two additional  directories one of them should be called train   and the other one should be called val, it's very  important you name these directories exactly like   this and then within these two directories is  where you will locate all of your data all the   training data and all the validation data and  then for the labels it's exactly the same you   need two directories one of them should be called  train and the other one should be called val it's   very important you name these directories exactly  like this and then this is where you're going to   locate all your labels all your annotations all  the training labels and all the validation labels   so please pay attention because it's very very  very important you structure the data exactly   like this otherwise it's not going to work  so please please please make sure you have   structured data into exactly this format and once  you are sure everything complies with this format   then you are ready to continue then the only thing  you need to do is to upload this data into your   Google Drive so once everything complies with the  format I showed you the only thing you need to do   is to take this directory and to drag and drop  this directory into your Google Drive and that   that's pretty much all and then you just need to  wait until the uploading is completed and that's   pretty much all. Now let me show you something else  which is the dataset I used in order to download   all the images of all the squirrels I am going  to use in this video, all these images I showed you   a few minutes ago and also all the annotations  I am going to use in order to train this object   detector and it's the Google open images dataset  version 7 this is an amazing dataset, an amazing   amazing dataset and I definitely recommend  you to take a look at this dataset because   you are going to find many many many different  images many different categories many different   type of annotations you have bounding boxes for  object detection you also have masks for semantic   segmentation and this is an amazing datset, I have  used it many many times many times in my projects   and this is exactly the dataset from which I have  downloaded all the images and all the annotations   of squirrels so this is an amazing dataset and  I recommend you to take a look at this website   and I also created a python script and a video  with very detailed instructions on how you can   download data from this dataset and I tried super  super super hard to make this process super simple   to make all this downloading process super simple  so by just following the instructions I provide in   that video and by using that script you will be  able to create whatever object detection dataset   you want you can just download images from all  the categories you want and you can just create   your dataset in only a few minutes and this  is an amazing resource I created in order to   help you to train your object detection models  and this is a resource which is available in my   patreon so it's going to be available to all my  patreon supporters. Now let's continue, now let me   show you how to execute all the steps in this  process and how to train this object detector   and the only thing we need to do now is to execute  all the cells in this notebook one at a time and   that's going to be pretty much all the first cell  is the one that's going to connect your Google   drive with Google colab and this very very very  important because remember you will need to access   all the data in your Google drive right... so you  need to select your account then you're going to   scroll all the way down and you're going to click  allow and that's pretty pretty much all now Google   Drive is mounted in your Google colab environment  that's pretty much all everything is ready so we   can continue now the next step is defining this  variable which is root directory and this is   the directory of your project in your Google  Drive, right, remember in my case I'm uploading   all the files and all the data and so on into this  directory of my Google Drive so this is something   you will need to change to the directory you have  created in your Google Drive remember in my case   everything is located in my drive computer vision  engineer object detection yo8 Google colab and   if I show you this variable this is what we have  over here my drive computer vision engineer and   object detection yolov8 Google colab and then as everything  is mounted here on content gdrive you can see   that everything is located in content gdrive  and then it's the location of my directory on   my Google cab so please make sure you change this  variable to whatever location you have uploaded   all of your data and whatever location you have  chosen for your directory in your Google drive   this is very very important and once you have  changed this variable the only thing you need to   do is to execute this cell and that's it then this  cell over here is going to install ultralytics   which is the Python library you need in order to  train yolov8 on your custom dataset and this is   very very very straightforward the only thing you  need to do is to execute this cell and that's it   now if I scroll down we are almost almost almost  there you can see we have only two cells left and   this one is very important... this is the one  we are going to use in order to do the training   and in order to do so you can see that we need  another file which is google_colab_config.yaml   now let me show you this file if I go to my file  system and I go up you can see I have a file   which is google_colab_config.yaml  and if I open this  file you can see that this is a yaml file with four   keys: path, train, val and names, So it's very very  very important you change this value over here   which is path to the location of your data in your  Google Drive you can see in my case the data   is located in my drive computer vision engineer object  detection yolov8 google colab and then data and   if I go here you can see everything is located in  my drive computer vision engineer object detection   yolov8 google colab and then data but first I also  have these two... folders which are content   gdrive and this is the location of my drive in my google  colab, right, so please pay attention and please   make sure you have changed this value to whatever  location you have uploaded your data into, right,   this is very very very important and then if you  have followed my instructions regarding how to   create your dataset, how you structure your dataset,  then you don't need to change anything over here   right this is the location of your training images  this is the location of your validation images and   if you have followed my instructions  then you can just leave these two values...   as they are right now right and it's going to work  just just fine just make sure you change this path   this is very very very very very important and  I cannot stress this enough right this is very   very important and then it's the names of all  the categories you are going to detect, in my   case I'm only going to detect one category which  is squirrel so this is how it looks like for me   but please change this value to whatever object  whatever category you are going to detect in your   problem and if you are going to detect more than  one object the only thing you need to do is to do   something like this right 1 is going to be your  category number one, then 2 is going to be   the category number two this is going to be given  by your data right by your labels you are going   to add all the categories you have in your data in  my case it's only one and its squirrel so once you   have prepared this file what you need to do  is to take this file and you're going to upload   this file into your Google drive right this is  exactly what you need to do the same way you did   with this directory with your data directory you  need to do it with this file and that's pretty   much all once everything is uploaded you are going  to get back here to your Google colab and now   you can execute this cell so the only thing I'm  going to do now is to press enter and I'm going   to execute this cell and that's pretty much all  that's pretty much all we need to do in order   to train this object detector the only thing we  need to do now is to wait until this process is   completed and this is going to depend on how many  images you're using it's going to depend on how   many epochs you are going to train this model for,  in my case I'm going to train it for 20 epochs and   I'm using something like 2,000 images if I'm  not mistaken so this is going to take a couple   of hours I think this is going to take 1 or  3 hours and that's pretty much all okay now the   training process is completed and let me show you  something let me show you all the output which was   generated during the training process you can see  that we have a a lot of information and at the end   it says results saved to and the directory where  the results were saved so now we need to execute   the last cell in this notebook because we want to  copy all the content from this directory into our   Google Drive now it's very important you change  this value over here which is the location of your   directory in your Google Drive please remember to  change this value over here you can see that now   it says my drive computer vision engineer object  detection yolov8 google colab which is the location of   my directory in my Google Drive please remember to  change this value and once you changed this value   the only thing you're going to do is to press  enter and that's pretty much all now let me   show you my Google Drive this is the directory  I have just copied into my Google Drive you can see   it says runs and if I open this directory it says  detect then train and these are all the results   of the training process right so let me show you  now the only thing you need to do is to download   this directory so I'm going back to... here and I  am going to... download like this okay now we   need to wait a few minutes and that's pretty much  all in order to download this directory so this is   going to download all the results you are going  to use in order to evaluate this training   process and also it's going to download all the  weights of the model you trained which is very very   very important let me show you super quickly if I  open this directory runs detect train then these   are many many plots and many images you are going  to use in order to evaluate your training process   let me show you super quickly this is perhaps  the most important of all of these plots and   then this directory which is called weights this  is the directory which contains the model you   have just trained so this is going to be pretty  much all for this tutorial this was a very very   quick and a very straightforward tutorial on how  to train an object detector using YOLO V8 and if   you have any questions regarding this process  I invite you to watch other of my previous videos   where I show you the same process but in a much  much much more comprehensive way I show you the   entire data preparation the entire process of how  to annotate your data how to evaluate the model you   trained this previous video is much much much  more detailed so I definitely invite you to take   a look at this video which I'm going to be posting  over there so this is going to be all for today my   name is Felipe thank you so much for watching  this tutorial and see you on my next video.
Info
Channel: Computer vision engineer
Views: 5,782
Rating: undefined out of 5
Keywords:
Id: bx52WmQvbaE
Channel Id: undefined
Length: 15min 14sec (914 seconds)
Published: Sun Oct 22 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.