Official YOLO v7 Custom Object Detection on Colab

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone and welcome back to my channel in our last video we trained yolo v7 custom object detection model on our local machine but what if you do not have gpu available locally if we train the model on cpu it's painfully slow fortunately we have free gpu resources available online that we can use to train our models we can either use google collab or kaggle for this purpose in today's video we will learn how to train yolo v7 custom object detection model on google collab let's get started i have this yolo v7 underscore custom notebook opened in collab first let's enable gpu acceleration by going to runtime change runtime type and select gpu as hardware accelerator click on save and then on connect once the notebook is connected to the runtime let's mount google drive from google.collab import drive and then drive.mount slash content slash g drive hit shift enter and it will execute this cell click on connect to google drive and it will ask your permissions click on allow that's it google drive is mounted now we can move to google drive by command percentage cd slash content slash g drive slash my drive once we are here now we need to create directories and clone official yellow v7 repository so let's import os and if not os dot path dot is dir the coding bug then os dot make dirs the coding bug this will create the directory inside google drive if it's not already there and if we click here and go to google drive we can see that the directory is created here if you have installed google drive on desktop you would be able to see this directory there as well now in collab move to this directory by command percentage cd the coding bug here we are now we need to clone official yolo v7 repository just copy this link and type command exclamation mark get space clone and then paste this link execute this cell and it will clone the repository we can see it here in our directory same changes are also reflected in our google desktop drive next we need to label custom data set to train yolo v7 models we already did that in our previous tutorial so i do not want to repeat that check out these timestamps on this video and come back when you are done the link would be in the description all right if you have followed that tutorial you should have these two folders each having images and their corresponding labels these two folders will serve as training and validation sets let's copy these two folders and go to google drive repository that we just cloned and paste it inside data folder now we will make a copy of coco.yml file let's rename it to custom underscore data dot yml and open it in your favorite text editor just delete these four lines and we also do not have any test folders or delete that as well for train we need to mention the path for drain folder that we just copied it's located in data slash train and similarly val is in data slash well so nc is number of classes in my data set there is only one class and we also need to mention the name of the class which is jack sparrow that's it save this file here and it will automatically be reflected in google collab now we move to cfg and then training directory there are seven configuration files for all the versions of yolo v7 and we can use any of these variations for training our custom object detection model in our last video we trained yellow v7 on our local machine but this time let's train yellow v7x on the same data set so that we can also compare the performance of both models in our clone repository let's copy yellow v7x dot yml and rename it to yellow v7x dash custom.yml open it in the text editor and just change nc from 80 to 1 and save this file as well and if you do not have desktop version of google drive you can always download files from here make edits and upload the edit files back now we are all set for the training let's see where we are in google drive by command exclamation mark pwd we are in the main directory so let's move to yolo v7 by command cd yellow v7 to train the model let's issue this command exclamation mark python train dot pi minus minus device zero minus minus batch dash size 16 minus minus img it's the resolution for the training as we are interested in yellow v7x we will use 640x640 as mentioned here then minus minus data which is inside data slash custom underscore data dot yml minus minus hyp which is hyper parameter file inside data slash hyp dot scratch dot custom dot yml then minus minus cfg which is inside cfg slash training slash low v7 x dash custom dot yml which we just modified then minus minus weights which will be yellow v7x dot pt that we will download in a moment let's add another cell here and copy link to this yellow v7x weights file from here and then issue command exclamation mark wget and then paste that link execute this cell and it will download the file once it is downloaded let's add the file name here against minus minus weights then minus minus name of the model which can be your lobby 7x dash custom execute this cell and if you encounter this error that dump all got unexpected keyword sort underscore keys you actually need to update yml version i will import my ml and look at its version it's 3.13 currently maybe in the future google collab will start using the updated version and you do not get this error but for now we need to update yml we can do that by command exclamation mark pip install minus minus upgrade pi yml equals equals 5.3.1 it will ask to restart the runtime and do that and now if we see yml version it's 5.3.1 as we have restarted the runtime we need to go to our directory again by using this command i can just copy it from here and that's it execute the training command again and it will start training it has found 52 training images and label pairs and 12 pairs for validation the training is started i will get back to you when it is done all right the training is finished and the weight files are located at this location let me just rearrange these pi yml installation cells so that these are at the top of the notebook all right now if we go to this path we can see a bunch of folders and files there as we showed this command multiple times multiple folders are created but we are only interested in the last one and inside this folder we have weights directory that contains best.pt file now we are ready to run custom object detection on images and videos i'm going to copy one dot jpg and savvy.mp4 here in google drive which will be uploaded to google collab automatically let's issue the command exclamation mark python detect dot pi minus minus weights and then copy the path to this best dot pt file here minus minus conf 0.5 minus minus img dash size which is 640 minus minus source that is the name of your image zero.jpg and then minus minus no dash trace let's execute this command i have made this mistake it's not zero.jpg it's one dot jpg let's change that and run again and here we have results stored at this path we can verify it that this file exists here for video the same command is used just to replace image name with video name and that's it the result will again be stored at the same location in another subfolder now if you want to use these weights locally just download this best.pt file or you can copy it from your google drive desktop and paste in your yolo v7 dash custom repository if you do not have this repository you can set it up using instructions at these timestamps in the same video that you used for developing dataset i am going to copy the best.pt file in my local repository and rename it to yolo v7x underscore custom dot pd open anagona prompt and head to your local repository just copy this command and paste here but now weights file path is yolob7x underscore custom.pd and there won't be exclamation mark here if we run this we would be able to run custom object detection locally as well even though you trained this model in google collab similarly for video replace this source with savvy.mp4 and it will run custom object detection on video as well here are two more folders that produced the result from our local run using yolo v7x so it's worst than yolo v7 that we trained locally i do have those previous results here as well so yeah base yolo v7 has a better performance if we look at it side by side by the way we had a very small data set and we were able to train the model on google collab but if you have very large data set google collab disconnects very frequently so you do have an option of kaggle as well which gives you 41 hours of gpu time maybe we will do that in one of our future videos if you have learned something of value today leave a like and subscribe to the channel to watch more videos like this consider support on patreon to help the channel out i will see you next time [Music] [Music] you
Info
Channel: TheCodingBug
Views: 34,964
Rating: undefined out of 5
Keywords: yolo v7, yolov7, yolo, object detection, YOLOv7, Official YOLOv7, train yolo in cloud, yolov7 tutorial, train yolov7, yolo v7 tutorial, yolo v7 object detection, yolov7 object detection, yolo7, yolo v7 official, official yolov7, official yolo v7, yolo v7 custom dataset, yolo v7 custom, custom yolo v7, custom yolov7, yolov7 custom dataset, yolo v7 colab, yolov7 custom object detection, yolov7 custom, yolov7 colab, yolov7 google colab, yolo v7 custom object detection
Id: _fXABNYlZhY
Channel Id: undefined
Length: 11min 5sec (665 seconds)
Published: Thu Aug 18 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.