How to train YoloV5 model on a custom dataset within minutes

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
and in this video we are going to discuss about how to train your yolo v5 model on your custom data set so this is your boy kasari back with another tutorial on object detection so let's get started so in this tutorial what we are going to see is how to train your model completely which have more than one class in your data set how to make changes in a yolo e55 and how to train it so for the sake of this tutorial i am going to use this detection football versus cricket ball data set which is available readily available on kaggle and this data set if you check is basically it's already annotated so if you see here we have train and valid images and we have labels as well labels for validation and for testing as well so you can see here we have to in total 1730 files which are nothing but 868 our image files and 869 are nothing but our annotation file which is in the format of dot txt so one another interesting thing is like if you want to annotate your data set so you can use this tool like makesense.ai so in this makesense.ai you can annotate your images like it supports yellow voc xml vgg json or csv and anything so you just have to click on just get started drop your image select for example i have i am selecting this pytash.jpg i selected on object detection and i started giving some label like object okay so i'll click here and click on start project and i'll start annotating from you so after that you can select your object detection and you can save and download your annotation files so this is a very handy tool you can say because you have label mg as well so for installing label img you have to do a lot of thing you have to create a separate environment and after that you have to install your label uh label me or label i img tool inside it but if you use makesense.ai it's very user plenty kind of thing and it's available like on the web big website that's available and you can easily annotate your images and you can download the annotation files as well as the image files so coming back to our data set so i'll close this what i did was i downloaded this data set so you can see like inside my terminal i have already downloaded my data set and i have already converted my data set into zip and i have uploaded my data set into my google drive so i would i will be able to easily access my data so i need not need to upload my images file again and again so let's get started so getting started with yellow e5 first what you have to do is you have to go to the yellow v pipe get a repository so how you will do it so you have to just say viola v5 ultra latex github repository so you have to choose this first link so after clicking on that link you'll land up on this page so this page has the whole lot of information about yellow v5 how it is performing you can see a yellow v5s model this is a model comparison between you know v5x 5l 5m and 5s and with efficient net as well so after coming to this github repository what you need to do is you need to scroll down a little bit and you need to scroll down until you see a google collapse right so what you have to do is when you will come down in the environment section you will see your google collab and kaggle notebook with free gpu so what you have to do is you have to do nothing but you have to click on this open collab so it will open a google collab notebook for you and after that what i'm going to do is i'm just going to change my account so i'll close this previous notebook so my notebook is loading so yeah it has loaded my notebook after that what i'm going to do is i'm going to mount my google drive okay so you can also do by just dragging and dropping it here your image files in zip format and you can unzip it here here only and you can just use your data center so my notebook is connected so what i'll do is i'll mount my google drive so what i'll do is i'll just do shift enter and do it run anyway so it's mounting my google drive so my google drive is already mounted and you can click here and i'll choose my account and after that i'll click on allow so i'll copy my code and i'll come here and i'll paste it here and i'll do again shift enter so by doing this this will mount my google drive so it has successfully mounted and just refresh it so you will be able to see my drive here so after that what we have to do is we have to clone our github repository ultra latex yolo v5 github repository so i'll just click on this concept and it will start cloning the yellow v5 repository so it's cloning so yeah it has finished cloning and if i reload this you will see a yolo v5 github repository it has loaded here so after that after cloning your repository if you scroll down a little bit you will be able to see like how the yolo v5 is creating a bounding box is how it is detecting it so this is the stock image which yellow e5 has already predict given us and made and has made prediction on this so moving ahead our main agenda for today is to train our model on custom data set so how to do it so just scroll down and you will see a train okay so inside this train section what you have to do is you have to come here the strain yellow b5 on coco 128 for three books so now to train your data set on your custom data set you have to make few changes so what the changes would be what you have to do you have to go under data you have to go under this data repository and you have to download this coco 128 dot xml so click here click on download so i'll save this file okay so i'll just save this file on my desktop so i'll minimize this minimize everything so this is nothing but my cooper128.yaml so i'll open this so after opening this we don't need this part so we'll just delete this after deleting that part you can see here nc is equal to 18. this is nothing but our classes which are already with yellow v5 so yellow e5 already gives you 80 classes but we are training on a custom data set so what we are going to do is we are going to change it according to our data set so our data set have two classes which are nothing but football and cricket ball as you can see here our data set has only football and cricket ball so we have nothing but two classes so i'll just change the number of classes here and i'll replace i'll also delete this and i'll give my class name cricket ball and football so after doing this what else you have to do is you can see your train and valve okay so i'll just increase the font size so you can see your train and valve so make sure like your directory structure should be like this so your folder name should have train and valve okay because euler v5 will check for train and valve okay like if i come here i have uploaded my data set already so i will show you how my directory structure is for euler v5 so you can see here i have images inside images i have train and valid okay so for that i need to pass the data set path here and just replace this completely and similarly for valid okay i'll replace the input i don't need this because we have more than 20 128 images let's just delete this and i'll save this so after saving this file what i'm going to do is i'm going to upload my yolo v5 custom underscore yaml under data set data data folder sorry so what you have to do is you have to click on upload you have to go on desktop but i have saved so let's change the file name into custom underscore data so it would be easy for you to understand so i'll rename this what i'll do is i'll change the name the bus custom underscore data sorry it's custom on password data not dial so we have renamed this file what we are going to do is we are going to upload a file under this data and click on upload i'll click on desktop custom okay so we have a custom underscore data underscore i'll just rename it again so that i remove this underscore so yeah we have our question we delete this only and we name it okay so it's done so if you can see here we have our cricket ball and output ball okay number of classes part to our data set that's it so after that what i'm going to do is i'm going to replace this 128 dot yaml with our custom underscore data dot y a m l okay so we have our data set ready so what are we going to do is we are going to start training our model so let's begin i'm just going to train my model for three epoch just for testing purpose we will see how our we are making predictions and what is our precision so this will be our first experiment so let's begin with the training part so as you can see your the cell has started running and it has successfully open dynamic library it is it has downloaded the model after that it's loading that's checking whether you have your data set or not so it has found 300 images inside my training training data which is nice so it's just caching the images for the train and for valid so that it does not require to load your images again and again so after that you can see here we have started training okay our training has started so this is nothing but our first epoch so it is training for first hip-hop so let's wait for it so it will take some time depending upon how big your data set is so my data set for this tutorial consists of 300 is 300 images for training and 100 images for validation according to that it's taking little time so you can see here the mean average precision is 0.95 which is pretty good so we have trained for our first epoch and it's training for our second depart so let's see our model is going so it has done training for second part as well it's training for the last hip-hop while training so i have to tell you one thing if your notebook stops i mean training like the cell stops training and you face a memory outage issue so what you need to do is you just need to change the batch size just change it to two two or three just reduce the batch size so you will get rid of that memory issue so it has done training so you can see here it has saved our weights in our model here the best.pt which is our model which is trained on our custom data set so let's check how our model has made prediction which is you can check under runs inside train and inside experiment this is nothing but this is our first experiment so let's checks check the labels whether it has properly given or not so okay it is predicted images correct so we'll check for the labels so you can see here it has predicted pretty much good so you can't even see cricket ball here so it's it has still predicted the cricket ball okay so for this cricket ball as well so it has predicted desperate football as well this for football as well this for cricket ball so this is very tiny cricket ball i mean you're barely able to see with your naked eye but it has still predicted correctly so if you can see here football football cricket balls see he is holding the ball in his hand still it is able to predict this it's a cricket ball so you understood how beautiful this yolo v5 algorithm is so if we train for more number of epochs we'll be able to get good results so let's train our model what 20 epochs let's see how it's performing with 20 epochs so let's start with our training so it's caching our images for training and for tests there's plotting labels and it has started training so you can see it started training how many gpu memory gpu memory it's using it's locating it's creating a bounding box here it's locating the object i mean at what coordinate your object is and you can see here it has trained for first epoch and your mean average position is 95 which is very good people i want to tell you one thing like if you're not getting good results with respect to your object detection model so what you need to do is so first of all do your annotations pretty well take time take few days with peace in your mind just annotate your data very well because if you don't annotate your data very well you won't be able to get the desired results okay because annotations are pretty important and after that if you consider one more point like just have ample amount of data set okay inside your training as well inside your testing uh image testing uh part because it will help your model to model to identify your objects within your images pretty well and it would give you good results in the end so it will take some time but still with the first epoch so you can see here it's taking pretty much good time it's some time it's taking time to train because i'm using the standard google collab notebook you can opt for google pro version which is available with high rank and high disk and with good gpu as well and you will be able to train your model pretty much very fast if you don't like waiting you can go with google pro so meanwhile while our data set is training so you can explore this like how it is so you can give your predicted images as well and you will be able to see your your images you predicted your testing images and the yolo v5 is pretty much good model when it comes to object detection that's why i prefer i prefer only two which is yellow v5 and detector on two both models have given me good results on my data set so it's training for 15th epoch so it's training for the last time let's see how it goes so that's it it has completed our object detection and it has detected two classes here which is cricket ball which is and another one is nothing but football for 20 epochs and it took about 10 minutes of time to train our model so the training which is done on a custom data set is saved in this directory under run experiment weights large.pt this is our nothing but our model which is strained on our custom dataset so what are we going to do is we are going to check our experiments this is about nothing experimenting for predicted labels okay so this is predicted pretty much well so you can see here you have football your over your your as well so it's still able to detect it you can see here as well football has detected cricket ball as well so let's close this and coming back to our collab notebook we have our object detection model ready on our custom data set and which is which has been predicted with our images it has successfully able to localize the images and to create bounding boxes across our images pretty well so what are we going to do is we are going to check how my object detection model which is trained on a custom data set how it is performing on a video okay so for that what i'm going to do is i'm just going going to go under this inference i'm just going to comment this line and i am going to use my weights which is straight recently okay i'm going to select this model and i'll replace this model with my model and what i'm going to do is here this is nothing but our confidence score i'll increase my confidence score here i'll give it 35 and what i'm going to do else is i am going to just upload a video and i am going to check how my model is performing on the video okay so i'll upload a video on this you can also drag and drop your data set here zip file and you can extract it you need to upload your data set into your drive but make sure you give correct path in your custom underscore data dot yaml file because it's pretty much important or else you will face an error so what i'm going to do is i'll copy the path for this and i'm going to just replace this with this that's it and i'm going to run this cell so after that what is going to do is it's going to check frame by frame okay it's going to detect the object so for example you can see here see it's detecting football football it will again detect some football for this frame okay so you can see here for this perimeter football for this frames also so it's checking frame by frame where the object is okay so you can see here how past it's localizing the objects it's taking like point twenty zero point twenty four seconds to localize and create the bounding box across the image so yes our experiment is successful energy let's say in yellow e5 under detect runs under detect and experiment so this is our file what are we going to do is we are going to download it so its downloading my so this experiment completed in 37.399 seconds so you can imagine how fast yolo v5 is so let's wait for our mp4 file to get downloaded so it's almost download it and we are going to save our file we are going to give this yolo red and i'm going to save it on my desktop just save it so i have saved it on my desktop so you can see here i'll display this video so you can see how accurately it is detecting the football okay see what yeah so this is how it's predicting see the confidence score as well so if you train for more number of epochs you will be able to see good results as well because it did some misclassification oh no that's not the misclassification that was a football over there only so it is doing some misclassification over here so that's it for the today's tutorial hope you like it make sure you like share and subscribe to this video this will motivate me to create more videos and i'll bring some more exciting stuff which will help you in your day-to-day life and it will make your life easy and if you have any doubt or anything you can reach out to me on my linkedin you can message me on linkedin and you can also post your doubts in the connect comment section below and i'll be able to happily resolve your issue so thank you very much that's it for today's tutorial this is akil kasari signing off take care bye
Info
Channel: Akhil Kasare
Views: 13,598
Rating: undefined out of 5
Keywords: #deeplearning #objectdetection #yolo #datascience #machinelearning #computervision #opencv
Id: ik6Pt7Wc9FY
Channel Id: undefined
Length: 32min 36sec (1956 seconds)
Published: Sat Apr 10 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.