YOLOv9 on custom dataset | Object detection using YOLOv9

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone my name is arohi and welcome to my channel so guys YOLO v9 has been released and it beats real time detection Transformer and YOLO Ms in speed and accuracy today I will show you how to use YOLO v9 pre-train model and after that I will show you how to train your YOLO v9 model on custom data set so let's start first I'm showing you the GitHub repo of YOLO v9 so this is the official GitHub rapper of YOLO v9 and here you can see the paper if you want to read more about it then you can uh read it from here and my today's tutorial I will show you that on Google collab so let's go to the drive so guys I have created one folder with the name of YOLO v9 in my drive and inside that folder I'm going to store everything which is related to YOLO v9 and this is my collab notebook let's open this notebook in this notebook I have the entire code which I'm going to show you today the first thing is let's select the GPU so that uh you can run your notebook on GPU so for that you need to click on edit and then notebook setting under this Hardware accelerator this is the GPU here I have selected it and then you save it let's see let's verify if that GPU is getting used by your notebook so for that you can write this and here you can see the GPU name okay so guys the same thing let's say if you want to see the GPU uh with the pych code then you can write these lines and by these lines you can simply say that uh Tesla T4 GPU is getting used okay now the next thing is here I'm just mounting my drive and after mounting the drive in this line I'm creating a link why I'm creating this link because I don't want to write write this whole path every time when Whenever there is a need so instead of writing this whole path what I want is I just want to write this okay so in the next line CD my drive and this is the folder which I've just told you that I've created a folder with the name of YOLO v9 so we are entering in that folder now here you can see the location is we are inside the YOLO v9 folder and then this is the GitHub repo you uncomment this code and then run it you have to clone this GitHub repo this is the official GitHub repo and once you clone it you will get a folder this folder inside your current working directory and then we are entering in that folder the YOLO 9 official folder and we will install the requirements pip install hyphen R requirements. txe so after running this line your environment will be ready now you can run the code easily the YOLO v9 code Next Step is to download the pre-train Rats of YOLO v9 because as I've mentioned that we first I'll show you how to use the pre-train model so for that we need to download the pre-train model so here I'm loading uh I'm downloading these two models and where I want to download it so in my drive I have a YOLO v9 folder and there I want to download it okay so here you will uh give the location where you want to download these two uh weights so now here you can see these two files this is the one weight and this is the second weight after that we will download one test image for inference for testing so for that I have downloaded this image you can uncomment this line and in this directory in my current working directory I want to download this image now let me show you this image so this is the image once we have the image Now by just writing this single line we will perform the detection the code is Python detect. py and then in this WS we are providing the path of the weight file so we have given the entire path my drive and then my uh folder and then the weight file name and in Source you have to provide the entire path of the image on which you want to perform the testing and here you have to define the device so we are using GPU so that's why we have written zero and let's suppose if you're working on CPU then you will mention CPU over here so when you'll execute it your result will be stored at this location run detect and exp inside exp the results are stored now let's uh see the output image which is stored in this exp so for that I'm just importing this module and we have given the path of our test image over here and here you can see car person dog so guys this v9 model the pre-trained model it is trained on Coco data set and Coco data set have all these classes this person car dog right so uh this is how you use the pre-train model now let's see how to work with the custom data set how to train YOLO v9 on custom data set so for that the data set which I'm using I've given the data set link let me click on it this is the page from here you can download the data set just go here and click on this and you will get the data set so YOLO v9 have the same data set format which YOLO V8 have you will have images and you will have The annotation files in uh txt format okay so you can download this one and we will use the data set in Yolo v9 then once you download the data set I have placed that data set in the YOLO v9 official GitHub repo open it and here Furniture uncore data set this is my data set and where this data set is it is in the GitHub repo which we have cloned I placed this data set folder inside that repo and when you'll open this folder you will see train valid and test folder and let's open the train folder inside that you will have images and labels folder and inside images you will see all the images and inside labels you will see the annotations file for all the images in txt [Music] format once you have the data set I've told you where to paste it in Yolo v9 repo we will paste this data. yaml file okay let's go here let's go inside this repo and here you will see the data dot data. yml file this I have pasted and from where I got this file so I when you'll download this furniture data set inside that folder you will have a data. yl file I pasted that data. yml file over here in the repo okay now let's open it so here is my data. yml file I've given the path till images and in valid also you have to give the path till images valid validation images and training images and here I have mentioned three because the data set this furniture data set have three classes chair sofa and table so this is the data. yl file this file is responsible to tell your YOLO v9 model that where your data set is and the after that this will be the first thing second thing is we will go inside the models under models there is a detect folder and inside that there is a file with the name of YOLO V Vina 9. yl now let's go here here we have a models folder open it and inside it we have a detect folder open that folder also and here we have YOLO v9 yl just copy it and then create another file and then rename it to YOLO v9 custom. yl now let's open this file so inside this file guys this is the only thing which you'll change you'll write three over here by default the value will be 80 because we have 80 classes in Coco data set so you have to change it to three because in my case my custom data set have three classes chair sofa and table and you will write the classes as per your custom data set so this is the change after that save your file that's it guys these are the changes which these are the two things which are required now you can train your YOLO v9 model on custom data set and to train the model you will use train.py you will Define the workers Define the bat size and then the image size and you will write for how many ooks you want to train it and here we have given the path of data. yl file and inside weights I have given the path of pre-trained YOLO v9 weight because I don't want to train my model from sketch it's always a good practice to use a pre-trained model and then find unit for your custom requirement so that's what I'm doing device zero means GPU and configuration file so we created this file YOLO V 9or custom so inside this configuration parameter you have to give the path of that and that's it guys you will execute this cell so this cell is still running right now so let me see for how many EPO it has been trained right now my model is trained for 30 EPS let's see what kind of output we get after 30 a only let's stop the training now and we will use the model which we got after these many EPO so where we will get these results so guys it just scroll up and here you can see that for this exam for this training our results are stored in X9 so let's go to the EXP 9 folder so you will get so right now we are in uh YOLO v9 folder here is the Run folder open it inside the Run we have train folder and exp 9 so the training which is going on the result of their training is getting stored over here and here you can see the results. CSV file and we have have a weights folder inside this exp 9 and here we have the best weight and the last weight and guys over here you will see the conf once the training get completed uh for 50 EPO you will see the confusion metrics right you will you can see the map graphs everything will be over here okay so in our case I am stopping the training and we will use this best. PT model and which is trained for 32 EPO and we will use this model to test on unseen data for a custom data set let's go here let's stop it and let's perform the inference with a custom model so how we do that python detect. py you can write the image size and then the confidence threshold value devises zero and inside this this weight now we will provide the trained custom model path so we have the best. PT model which is in weights and which is in exp folder and then we have provided The Source on which we want to perform the testing so I have one image with the name of furniture.jpg let me show you that let's go back so here I have a image furniture. jpg on this image I want to perform the testing so in Source I've given the path of that image and then execute it let's execute so here the detections are saved in exp2 now WR here exp2 and then run it so this is the uh output of our custom model but the output is not so good because we have just trained our model for 32 EPO and we have stopped the training in between this tutorial is just to give you an idea that how you can train YOLO v9 on your custom data set the link of this notebook is given in description section you can try this code and I hope this video is helpful so so guys if you like my video please like share and subscribe my channel thank you for watching
Info
Channel: Code With Aarohi
Views: 8,001
Rating: undefined out of 5
Keywords:
Id: 3iLJ6YWPg28
Channel Id: undefined
Length: 13min 34sec (814 seconds)
Published: Fri Feb 23 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.