Yolo v nine is the new computer vision object detection model released by Jin Yong Wang and his team
on 21st February 2024.
In this tutorial, we will review how we can do object detection on images and on videos using YOLO
v9 in Google Colab.
Before you run this script, please make sure that you have selected the runtime as T4 GPU.
Google Colab offers free GPU so you can use this.
So in the first step, we will clone this yolo v9 GitHub repo.
So you can simply go here and you can just click copy this URL from here.
And you can just come back to the Google Colab notebook.
And over here you will write git clone.
And here you will pass the URL that you have copied.
So here you will just add the URL that you have copied.
So now we will just run this cell and we will be able to clone the GitHub repo into our Google Colab
notebook.
And here you can see the complete repo which we have cloned.
So Golovnin introduced two new architectures, Golovnin and Glenn.
So in the Yolo v nine paper, two new architectures have been introduced.
One is the Yolo v nine and other is the Glenn.
Both model weights are available in the Yolo v nine repository released with the paper.
So if you just go over here.
So and if you just click on this version 0.1 and here you will find the Glenn model weights as well
okay Glenn C I Glenn E and yolo V9C Yolo V9E.
So you will find the Glenn model weights as well as the Yolo v nine model weights.
So YOLO v nine and Glenn come with four different models 1V9 small, YOLO nine compact, YOLO v nine
medium and Yolo v nine extended.
So if you just go over here, you will find the list of models that YOLO v9 come with YOLO v9, small,
YOLO v9 medium, YOLO v9 compact, and YOLO v9 extended.
Similarly, you can also come with all these models as well.
So in this tutorial we will see how we can do object detection with YOLO v9 as well as with Glen model
as well.
So in the next step we will download the pre-trained model weights from the GitHub repo.
The weights for the Yolov5 small model and Golovnin medium model are not available at the time of writing
this notebook.
So if you just see over here, uh, yolo v9 comes with four different models YOLO v9, small, medium,
compact and extended.
But over here you will see that we have only weights available for the compact model as well as for
the extended model.
And similarly in the case of Glenn, we have weights available for the compact model as well as for
the extended model.
We have don't have the weights available for the small model or for the medium model.
So we have two weight model, uh, weights available, compact and extended.
While we don't have the weights available for the small or the medium model.
So to download this weights, you can simply, uh, click over here, copy the link address and you
can simply write w get.
And you can add the link address over here.
And you will be able to download all these weights into your Google Colab notebook.
So I will just download all the weights.
So I'm just downloading the compact and extended weights for the Glen and YOLO v9 model.
So here you can see that I have downloaded Golovnin compact model weights, YOLO v9 extended model weights.
And similarly here I've downloaded Glenn compact model weights and Glenn Extended model weights.
So now in the next step, we will set our Golovnin folder, which we have cloned over here, our Yolov5
repository, which we have cloned into our Google Colab notebook.
So I will just set this, uh, directory or uh, I will just set, uh, change my directory to yolo
v nine.
So I've just changed the directory to YOLO v nine folder.
So now we will install all the dependencies.
If you just see the requirements dot.
TXT file in the requirements dot txt file.
We have listed all the requirements or all the libraries that are required to run the uh to do detection
on images and videos.
So if you want to install all these packages once, you can simply write pip install minus r requirements
dot txt.
So it will install all the libraries dependencies that are mentioned in the dot txt file.
So I will just run this cell and it will install all the dependencies that are mentioned in the dot.
TXT file.
So this might take a few seconds before it gets completed.
Nope.
We have installed all the packages that are listed in the requirements.txt file.
Now in the step number five we will see how we can do inference on images and videos.
First we will do inference on image using Galen model.
So this is the best model uh in the Galen series.
So first of all, I will just download a random image from my Google Drive into this Google Colab notebook
over here.
So I will just run this cell and it will download that image from my Google Drive into this Google Colab
notebook.
And over here, if I just go to the YOLO v nine folder and over here you will find the image one dot
jpg which I have downloaded.
Okay, so now I will just write over here python detect.py.
And here I will just pass the weights and which I have downloaded already above.
And here I will just pass the image name in the source and device zero because I have selected the runtime
as GPU.
So if I just like to CPU then I will just write device CPU.
But I am using.
I have selected the runtime as GPU, so I am writing device zero and now I will just run this cell.
So if you want to get familiar with more about this command, you can just go to the GitHub repository.
And over here you will see uh, all the steps are written how to uh, if you want to do inference with
the YOLO v nine model.
So you can write Python detect dash dual dot pi.
And if you want to do inference with the Galen models, you can simply write Python detect dot pi.
So I am doing inference on image using an E model.
So I will just write Python detect.py.
And here I will just pass the weights file name and the source and device.
So this is all you require.
So now I will just run this cell over here.
So the inference take a few seconds.
So it is about to be done.
So now you can see over here we are using Tesla T4 GPU and our results are saved in Runs Detect experiment
folder.
So if you just go to the Yolov5 folder and here we have the runs detect and experiment.
And here is my output image saved.
So I will just first from IPython I will just import the image library and let me display my output
image over here.
So you can simply copy path from here.
You can remove this because you'll be nine is already set as our current directory.
And if you just run this cell over here.
So this will display you the output image.
So now you can see over here uh using Galen Extended Model we are able to detect the first person's
handbag backpack.
Uh.
But we have detected traffic lights as well.
And this is not the surfboard, so this is the wrong direction.
Uh, one there is one wrong direction, else all other directions look pretty fine.
It has, uh, detected persons which are far away or blur as well.
So now we will do inference on the same image using YOLO v9 extended model.
So.
If you just go over here.
So these are the best performing models.
YOLO v9 extended.
They have more number of parameters as well.
And they uh, have good mean average precision as compared to the other YOLO v9 models.
So we are using the best, uh, YOLO v9 model as well as the best Galen model, which is the extended
model.
So now as I told you to do inference on image video using yolo v9, we need to try it over here.
If I just show you we need to write Python detect-dual.py.
So we will write over here python detect-dual.py.
And here I will just pass the weights name.
And here I've selected a source as image one.
I'm using the same image and device as GPU.
For GPU I will write zero.
So now I will just run the cell over here.
So in the inference takes some time.
So now it's using layer.
And you can see that we have uh folder exponential two is being created.
And inside this we have the output image.
And let us uh display this image output image over here.
So you just need to find pass the file path over here.
And you can see that, uh, in the previous, uh, Glenn extended model, we have one wrong detection,
which is sort of word, but, uh, the this is not the case with the yolo v nine over here.
So exactly as yolo v nine outperforms Glenn E model as well.
So now you can see that, uh, we don't have any, uh, false positive over here.
And you can see over here we have the sandbag backpack, a boss person, and it has detected, uh,
persons which are quite far away or blurred, like you can see over here.
So this is good.
Now we will be doing inference on videos using YOLO v9 and Glen model as well.
So let's first download a sample video from the drive into this Google Colab notebook.
I have already placed the sample video onto my drive, and I'm just downloading that video from drive
into this Google Colab notebook.
So now you can see that this demo dot mp4 video is.
Okay, now you can see this demo dot mp4 video over here.
We have downloaded this.
So now I will just try and write Python detect.py.
And here I will just pass the file name and the source as demo dot mp4 and device zero for GPU.
So let's run this cell.
So now you can see that our complete video is being divided into 1314 frames, and the detection on
each of the frame is being done one by one.
So this will take some time.
So let's wait for it to get finished.
And then I will display the output video over here.
So this might take a few more seconds before it gets finished.
So the inference on this input video demo mp4 is being done.
We have used the Glen E model.
So Glen stand for generalized efficient layer aggregation network okay.
So if you I have also displayed the output demo video over here.
So let me just download this from here and let me show you how our output look like.
So here we are using Extended model, the best performing model among other planned models.
So I have downloaded this video.
So let me just.
Let me just navigate my screen towards this video.
So over here you can see that we are able to detect, uh, so this is a wrong detection truck.
Uh, okay.
And this is also a wrong detection person.
This is not the person.
And this is also a wrong detection.
And this is not a truck as well.
So this is other wrong detection okay.
As we are able to detect the cars trucks as well.
So the results look pretty fine to me.
So let's go back as well.
And now I will download other video.
Uh okay.
From here.
So I will I will just downloaded the video from Google Drive into this Google Colab notebook and let's,
uh, run uh, Glenn model on this input video, which is test Walker MP4.
So let's run this.
So I already told you, Glenn Stanford.
Generalized efficient layer aggregation network.
Okay.
So the complete video is being divided into 341 frames, and we are doing detection on each of the frame
one by one.
So this might take few seconds to complete.
And then we will display the output video over here.
The inference on this dashboard that MP4 video is also done.
And here is our output video.
I have also displayed the output video into this Google Colab notebook.
And let me download this video over here and let's see how our results look like.
So let me just open this up okay.
And let me navigate my screen.
So over here you can see that we are able to detect the person's handbag over here.
And um the results look pretty fine.
Like you can see that uh, but there are some false positives as well.
So if you just see over here, this is not a tennis racket or this is not a Frisbee.
So there are some, uh, false positives as well, like you can see over here as well.
It's detecting at tennis racket or Frisbee, which is wrong.
Okay.
And if we just go ahead.
So now we will see how we can do inference on these two videos.
Demo dot mp4 test dot mp4 using YOLO v9 extended model YOLO stands for you only look once.
Okay, so if you just go over here in this GitHub repo.
So if you want to do inference with the yolo v9 models, we need to write python dash dash dual.py.
So we will run this.py file.
And if you want to do inference with the clan models we just write detect.py.
And if you want to do inference with the yolo v9 models we use detect dash dot py.
So now I will just run this cell over here and I will do inference on this video.
So let's see how does it goes.
So the complete video is being divided into 1314 frames, and we will be doing detection on each of
the frame one by one.
I'm using, uh, the YOLO v9 extended model, the best or outperforming model among all the YOLO v9
models.
You can see that yolo v9 extended model, uh, gives mean average precision on the validation set of
the data set is 55.6%, and it has more number of parameters as compared to the other YOLO v9 models
like test 57.3 million parameters.
So like it is about to complete.
And let's see how does it goes.
So, uh, 760 frames are done and let's wait for all the frames to complete.
And I will also display the output video over here.
For the inference on this demo video with Golovnin extended model is being completed, and I have displayed
the output demo video over here as well.
So let me just download it and let us compare these our these results with the clan model results as
well.
So I will do the comparison over here as well.
So let me just navigate my screen.
So over here you can see these are the results from the YOLO V9 extended model.
This is our own detection.
Uh the clan model is also detecting this as proc.
But this is not the case over here.
This is also a false positive okay.
So.
There are some false positives as well.
Uh, but in the with the uh, Glen model, they are more false positives, I believe.
So these are the results over here which you can see over here.
So let's go back over here.
Okay, so let's, uh, run on this other video test workload, MP4, and we will be using yolo v9 extended
model again over here as well.
So now I will just run this cell over here and let's see how our results look like.
We on this video when we track an extended model, there were some false positive like it was detecting
potholes as frisbees or tennis racket.
Let's see if this is the case over here as well or not.
So the complete video is divided into 341 frames.
And detection on each of the frame is being done one by one.
So let's see how does it goes.
Now I will just display this output video into this Google Colab notebook as well.
So this will take few more seconds.
And here you can see all the models which I have downloaded from the repo into this Google Colab notebook.
You will find all the names over here as well.
So this might take a few more seconds before it gets completed.
For the inference on this video is being done.
And here we have the output video.
So let me just download this up over here okay.
So let me just navigate my screen towards this output video and let me just play it from start okay.
So now you can see over here we don't have local.
They are very less false positives okay.
There is one false positive over here.
Else overall the results look pretty fine.
Like in the case of Glen extended model there were more number of false positives like here.
And in this case we have quite less false positives.
So that's so good.
So in this tutorial we have seen that how we can do object detection using Glen and YOLO benign models.
And we have seen that how we can do uh run these models in Google Colab and do object detection on images
and videos.
So that's all from this tutorial.
Thank you for watching.