object detection custom dataset using Yolov8 and Python | custom object detection in Google Colab

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone so in this particular video we will fine tune a YOLO model on custom data set YOLO V8 model on a custom data set so before getting started you need to make sure two things number one you have data with you which is basically given in three different folders you have the train folder in which you have a folder of images and a folder of labels now I have to tell you that this pre-processing and data I'll try to make another video where I'll be going through each and every step and I'll be coding in I'll be coding each and everything in detail but here I'm just going to show you how to quickly fine tune a data a fine tune a YOLO model and create the detections okay so we have train and where you have images and labels images have certain images over there now right now I'm not going to open those and then same thing with Val and same thing with test so valve for validation again it has some images and labels and the test data has some images okay the next thing that you need to make sure is that you have the GPU so you can see the GPU is set so don't run it on CPU otherwise it will take a lot of time okay so let's start by going through our coding so the first thing that you need to do is we need to pip install Ultra lytics which we do almost every time and okay and we are going to pass past Dash queue and we are going to run this so it will take some time and it will download our YOLO model YOLO uh stuff the next thing that we need to do is we are going to instantiate the model so we are going to say model is equals to YOLO and then what we are going to do we are going to use YOLO medium okay yellow V8 medium so as you know if you go to GitHub and then you go to the detections detection portion there you can see there are five models and the Nano one is the smallest and extra large is the largest okay as as I have said earlier even when you go down the down the chart you the value or rather the weights will increase the number of parameters will increase and the accuracy will increase but at the same time uh the speed will also increase so you will have to trade off you'll have to do a trade-off between speed and accuracy okay now what we are going to do here we are going to pass L YOLO B 8m dot PD so what it will do it will basically download your and before that what we need to do is we need to go here and we need to say from ultralytics import your low capital okay so we have to run this self basically first and then after that we are going to run this cell so once you are done with running these two cells what we are going to do is we need to actually Define a yaml file so we have already seen the data over here we have already seen the data there are three folders but we need to define a yaml file that will have the location of this data and other things I'll show you so first you need to do is you need to write touch uh data Dot yaml and then run it okay so over here you will see a data.aml has been created so I'll do a double click on this and you can see file has been opened so here we need to write certain things that I'll write right now and you also follow along okay so we will say train then give a colon and space here we are going to give the path to our training data so training folder so we will say copy path and here just paste it okay next we'll say well colon space and here we will give the path of the validation validation folder and we will copy and paste over here we'll go and the next line will write NC give a colon so after writing NC NC is basically number of classes so in this data set We have basically four classes prohibitory danger mandatory and other so in this data set what we are going to do is we are going to have the detection signs so many signs will be there on the road and all those things and then we are going to classify okay on which uh we are going to first detect and then say which sign it is okay so we are going to have four of them so in the next line we will say names and we have a colon space and open square brackets and the first one as I said will be ProHeat B tree prohibitory then the second one is going to be Danger third one is going to be mandatory and the fourth one is going to be at so this is going to be a yaml file and Ctrl s for Save and then we are going to cut it okay so once we are done with that what we are going to do is we are going to say model in here first we will close this and here I am going to say model Dot train and I'll say data so this is where we will be passing our this is basically fine tuning of our models okay so we have already downloaded the model over here YOLO v8m.pt here we will be fine tuning okay so we are going to say data equal to and then we will give the path of the yaml file so the path of the ml file is we'll go over here and we will say copy path okay and then we are going to give open close uh quotation marks or rather just the quotation marks and then we are going to say paste it over here okay and then what we are also going to do is we are going to define the epochs or number of epochs so I am going to say we are using 5V box okay so now I am going to hit Ctrl shift or rather shift enter in order to make this cell run okay so this entire fine tuning process took five minutes roughly and we can see that we were able to get our results so results were saved in runs detect train and so on so what what is saved over here actually the best performing model is saved over here that will be or rather let's say the fine-tuned model is saved over here so what I'm going to do is I'm going to actually I'm going to that location so I'll hit over here and then I'm going to runs let me close this one then I'm going to detect then I'm going to train and then I'm going to wait so if you see there are two models over here best DOT PT which is the best performing fine tune model and last dot PT okay so last one was the fifth one because we ran for five epochs and whatever was the best is over here then there are other things as one as well F1 curve PR curve and so so many things I'm not going to get into that right now I'm going to basically now use the fine tune model so here I am going to say here I am going to say infer or the infer model I am going to say YOLO I'm going to instantiate that same class and here I am going to pass the path of the best performing model so I am going to say copy path and then here I will just paste it okay so I have pasted it over here and then I am going to hit shift and enter okay so after hitting the shift and enter now this infer has the fine tune model OKAY the best fine tune model now in order to make predictions what I have to do is basically I have to first show you the test data okay so I'll go to all data I'll go to test and then I'll go to images so as you can see there are certain images so for example this is an image so let me first close this one so you can see this is an image whatever the image is too big for this display over here so you can you can see that there are other images as well okay so what we need to do is we will go over here and we are going to say infer dot predict okay and then what we are going to do we are going to pass the path of these images test and then images so we are going to say copy path and in the double quotations we are going to paste it and then what we are also going to say is we want all these things to be saved okay so we are going to pass the hyper parameters over here we're going to say save is equals to true because because this will save our results that's why save equal to true and optionally if you want you can also save text equal to true even though we will not be using it okay so now you can see that this is our entire code so now I'm going to hit shift and enter okay so this might take some time okay so it took roughly around second seven seconds not a lot so now what we are going to do is we are going to actually see where our predictions are okay so we will go to runs detect we are going to see predict because we did a prediction over here so now we will open predict so you can see there are so many images that we have got okay so let's open the second image for example and let's try to see what we have got over here so this is a um I think it's in the right side yes so you can see the image is actually quite big that's why it's not able to fit but you can see the detections okay so this was so the model was able to detect this and this over here let's go for some other image so let's take for example 82 and close this one for a second so you can see this mandatory sign is there so if you remember as I said there were four classes prohibitory danger mandatory and other so it can find mandatory over here they can be multiple other uh to say predictions also but in this case there was only one fine so as you saw this is how you do custom data set fine tuning on a custom data set now let's try to play a video okay so what we can see over here is first let me close this there is actually a video over here traffic sign to test.mp4 so if you haven't seen the last video that I made on how to use YOLO V8 on a video I'm going to use a CLI command so now why I use CLI why not python actually I tried using python but the problem is I think on collab there are some issues with uh compression of the video that is given from uh what to say your YOLO V8 through python but with CLI it works so I'm going to use CLI only so I'm going to say YOLO I am going to say detect I'm going to say predict here I am going to say model but we are not going to use any other model we are going to use this model only that we have got as the best DOT PT so we are going to say again run runs even though you can just copy paste from here because this was the same model so I'm going to say copy first let me close this and I'm going to say paste now we also need to give the source so we will say source and our source is going to be over here let me close this first and then we will be going down and here you can see copy path then again close this and double quotes and so this is going to be our the main file so I'm going to hit shift and enter so this will basically run it so we are going to use that file this MP4 detect video which you are right now seeing on your screen this is a very small video one second so and we are going to use our model that we have trained okay that we have fine tuned so now obviously we need to do the last step that is compress this video so we can go again runs detect now we'll use predict 2 because and you can see the video is here but this video is not compressed so we need to compress it right now so for that what I'm going to write I'm going to write ffmpeg ffmpeg Dash I open close bracket I have explained this in the last video that is on how to apply YOLO V8 on a video and I'm going to say V codec lib X 64. and then I'm going to give here traffic dot MP4 okay now I need to pass the path of this uncompressed video so I'm going to go over here and then I'm going to paste it close this so this is our entire your command so I'm going to hit shift and enter so this roughly takes around 7 8 or to 10 seconds or it took five seconds okay so now what we are going to do is we are going to close this over here and hopefully our final Dot oh sorry traffic dot MP4 is our traffic dot MP4 is over here now what you can do is you can download from here and then if you look at the video it is very small video you can see that it is able to detect over your traffic sign Okay so I think this helps definitely I'll be making a detailed video on each and every step but it will be quite long and it will be coming I think tomorrow or day after tomorrow so I hope you understood the video and bye
Info
Channel: Datum Learning
Views: 17,440
Rating: undefined out of 5
Keywords:
Id: YK-y3U__pLw
Channel Id: undefined
Length: 14min 9sec (849 seconds)
Published: Thu Jan 26 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.