YOLOv9 Training On Custom Dataset | Yolov9 python tutorial for beginners | Yolov9 python tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone my name is Assad ibal and welcome to my YouTube channel so guys in a previous video we had a look at how we can use YOLO v9 pre-train model to make the inferences on a image without any training so the goal of our today video is to fine tune the YOLO v9 model for our custom data set right and make infes on a test data we will also make the Ines on a video as well so first of all we need a data set to finetune the model and we will use construction site safety data set which is freely available on Kel in the YOLO V8 format the format for the data for YOLO V8 and YOLO v9 will be the same so that's why we are using the same data set from the k so in order to download the data set from the Kel we need to have an Kel token API and you can easily assess it from your kegel account settings and after downloading uh the Kegel API you can import it into your Google collab environment and this token will be download in a Kel dojon file you have to import this k. Json into your Google collab environment right so let's get started with our project so let's install the Kel python API using pip by using this we can directly download the data set from the kegle into our collab environment so before running the cells make sure you have to connect with the GPU uh we can change the Run type to the GPU okay and save it so after connecting with the GPU let's first install the gel API so we can easily download it and install it using pip so after uh installing the Kel and now we have to make one directory called do Kel which will uh save all the Kel configurations and file and let's run it now we need to import the downloaded Kegel token API from our Google Kegel account into to the collab environment so let's import it we can uh it will be in a kle do Json file okay and now copy this Kel do Json file into this folder that we have just created right there right so let's run the cell after running the cell so now we are setting the permission for our Kel API using this CH mode command which is stand for the change mode right so let's run the cell after running the cell now let's download the data set from the Kegel and we can uh just copy the API path of the data set and I will be mentioning the link of this data set in the video description you can assess it easily from there just run the cell as you can see our data set is downloaded and it is in a zip file so we need to extract the data from the this ZIP file so for that we are using unzip function which will extract all the content that is present in a zip folder I just copy this path and paste right there right okay now let's run this cell once execution process is completed we will be ready to use this data set for our experimentation and training so so now let's clone the repository from the GitHub using the git clone command this repository contain all the code that we need to implement the YOLO v9 object detection model so let's run this cell and clone the repository as you can see our repository has been downloaded and now we have to need set the some configurations so first of all here I am setting two variables data directory holds the path where our set is stored and the variable working directory which defines the path of our working directory right so because uh in a collab the working directory is content and this is the path of our data set this path is actually the path of unzipped data set right make sure this thing so we can just copy the path from there and paste in here and the number of classes is the count of the classes and classes is the the name of the classes that is present in our data set so let's run these both cell now here we are creating one EML file that contain the file path for training validation and testing data as well as the number of classes and the name of the classes uh we will create this EML file inside the YOLO directory because we will perform all the experimentations and training within this directory okay so let's first import the uml file and the operating system which is the import OS now create one dictionary uh train will keep the training path of the data set and it will the this is the path of uh this train folder and the validation keep the path of the training data set validation data set and test will keep the path of the test data set and NC is the number of classes which is the 10 and name is equal to class which is the name of all the classes that is present in our data set so let's run this and create one EML file inside the YOLO v9 directory after running this cell we can see the one data. EML file has been created in our YOLO v9 format and you can see this is the name of the classes the count of the classes and the path of our data set right now let's download the pre-train of YOLO v9 model once the weights is downloaded we will be able to fine tune these weights for our custom data set this is always the best practice to use the pre-train weights and use these weights to fine tune for our data set right as you can see our vs downloaded in our working directory and we can see right there which is the YOLO v9 e. PT so right so now move to the training process so first of all let's navigate into the YOLO v9 directory by doing this we can assess all the code that is related to our project so we can we can navigate into the YOLO Vite by just using the CD command which is the chain directory you can see we are inside this YOLO v9 directory so next we are installing all the necessary packages using pip that is listed in a requirement. txt file and hyphen Q stands for the qu mod which will hide all the installation process let's install the dependencies for our YOLO v9 model and now our dependencies has been installed now it's time to train and fine-tune the YOLO v9 model for our custom data set and this command will initiate the straining process for our YOLO v9 model but before executing the cell we need to modify two arguments right the first argument is the hyphen hyphen data and we need to pass the path of our data file that we have just created above which is the data. ML and we have created this file inside the YOLO v9 directory right so navigate to the YOLO v9 and copy the path of this file which is the data. yml that which is contain all the path of our data set number of classes and the count of the classes and just paste right there and and the second argument which is hyphen hyphen config okay we need to make a little changes in the YOLO v. gml file because this original YOLO v. gml file is configured for the Coco data set on which the YOLO v9 model has trained and which contain the at classes as our custom data set we have only 10 classes so we need to adjust the number of classes parameter that is present in the YOLO v9 file and pass the 10 instead of 80 so let's go to the models inside model we have a detect folder inside the detect we you can see we have a YOLO b9. EML file just open this file and you can see there is a NC parameter which is the number of classes and this for the Coco data set it has 80 but as our custom data set we only have 10 classes so we need to pass 10 here so after uh mention this we can save this file as you can see our file is saved and we are good to go with this yolow V 9. EML file so now copy the path of uh this file and just paste right there so and hyphen hyphen hpy which is contain the hyper parameter for our model and we don't need to modify this so we will leave it this as is it right so let's train the model for uh 50 ook and here are some other parameter which is the worker uh we set eight worker right there number of batches which is the four in our case and the size of the image which is 640 by 640 and the number of epo we set it to the 50 and uh there is one more parameter which is the hyphen I device which is zero zero means we are using the GPU for our training process now let let's run this C and F tune the model on our custom data set we got the not found error of the vs uh I think uh we are not put the right path of our sorry we have a pre-end YOLO v9 model inside the content not in the YOLO v9 directory and you can see it just copy the path of this pre-train ws and uh put right there now it will work as you can see our training has been started and it will take some time to train the model on our custom data set so once the training is completed I will get right back so guys I have stopped the training process after the 10 EP because the of the model for the 50 aox was taking so much time so uh that's why I sto it after 10 and you can train the model for 40 or 50 ook right so let's navigate to that folder where our model has saved after 10 ook so this is the in the YOLO v9 directory there is a folder called runs inside run there is a 10 train folder inside train we have two experiment folder the first experiment folder is created when we run the cell and we got the error but the model that is saved after the 10 Inox will be in a experiment two folder so open it and there is a v folder and there is a best. PT file which is our best model that is saved after the 10o just copy the path of this model and use this model path for our detection so let's make the inferences on the image so for that we will be using detect. py file and pass the size of the image config 0.1 and the device is again we are setting the zero which mean the GPU and the weights now we have to pass the weight of that we have just copied right now we will be using the Bas of the model that we have trained on our custom data set just paste the path and in a source argument we need to pass the image on which we want to make the inferences so let's navigate to the data folder and copy one image and pass to the source argument just pass right there okay now let's run the cell and display the detections as you can see our model has make the predictions on the image that we have just passed to the detect file so it save the result in a run there is a detect folder inside the detect we have experiment folder so let's navigate to that folder inside the run there is now you can see it has created two folder and te and inside the detect we have a experiment folder and just copy the path of this image and paste it here to display the image so let display it as you can see the model uh not making the perfect prediction because we have just trained the model for the 10 books so let's try with another image just copy the path of uh this image and close all the tabs and paste the path of the image into the source folder again and make again run the cell and make the predictions again now again it save the result in a detect but now there is created one more folder called Experiment 2 so let's navigate to that folder and copy the path of the image and put the path of theage image right there to display the image as you can see the model making the prediction but uh there is some Falls in a prediction because we have just trained the model on a 10 aook so you can uh increase the number of size and that model will be trained on more ebooks and it will make the right predictions so aim of our this video is just to show you how we can train it on our custom data set not to make the model more accurate right so as we have uh tested our model on images now it's time to test the model for the video so in a source file we have a source folder and I copy this hard head. mp4 file right let's copy the path of this video and pass in a source argument after passing the path of the video in a source argument now let's run and make the pred on a video as you can see the result of the video predictions are stored in the detect folder this time it stored the result in a Experiment three folder in a experiment 3 folder so let's navigate to the folder download the file right after downloading we can plate any media so let's play it as you can see how our model make inferences on a video as well but there is a lot of wrong prediction that our model is making and again this is because of we have trained the model only for 10 ebook to make the accurate prediction we have trained the model for more ebooks okay guys this is all for our today's video I hope you enjoy this video please share like And subscribe to my YouTube channel and I will see you in the next video
Info
Channel: Asad Iqbal
Views: 1,961
Rating: undefined out of 5
Keywords: machine learning, deep learning, computer vision, computer vision project, machine learning project, deep learning project, yolov9, yolov9 tutorial, Yolov9 python, Yolov9 python tutorial, Yolov9 python tutorial for beginners, yolo object detection, YOLOv9, YOLOv9 Tutorial, Deep Learning, YOLO, Computer Vision, Object Detection, Real-Time Object Detection, Machine Learning, Neural Networks, YOLOv9 Model Training, YOLOv9 Architecture, object detection
Id: pCdq9_ioQaI
Channel Id: undefined
Length: 17min 3sec (1023 seconds)
Published: Tue Feb 27 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.