In this video tutorial, I will be testing the Yolo v9 model performance on image video and on the live
webcam feed.
So let's get started with it.
I have divided this complete tutorial into six different steps.
In the step number one, I will go on the yolo v9 GitHub repo.
In the step number two, I will create a virtual environment which is recommended if you don't want
to disturb your Python packages.
Then after creating a virtual environment in the step number three, I will install all the required
packages or libraries that are required to do object detection or image video and on the live webcam
feed.
In the step number four, I will do object detection on image.
I will be showing, showing you how you can play with different hyper parameters and adjust them as
per your requirements.
Then in the step number five, we will be doing object detection on video.
And in the last step I will show you how you can do object detection on the live webcam feed.
So let's get started with it.
So over here you can see that I have created a project by the name testing YOLO Benign Model Performance.
In my local app directory.
You can create a project in any of your directory, and I am using PyCharm Community Edition.
And I have Python 3.10 installed.
Okay.
Going.
The step number one, we need to clone the Yolov5 and GitHub repo.
So I will just go over here.
Yolo v9 GitHub and I will just open the first link from here, and just go over here and just copy the
URL to the clipboard, and then go back to the PyCharm.
And over here I will just write let clone and just uh, pass the link or copy the URL link, which I
pass.
Uh, just paste the link over here.
So now I will clone the complete Golovnin GitHub repo.
So now in the next step, I will just go to the clone folder.
So if I just, uh, refresh.
Okay.
No need, no need to refresh.
We can find this over here.
So we have all the benign repository being cloned over here.
And we have all the required files we can see over here.
Okay.
So.
So in the next step I will just go to the clone folder.
So I will just set CD current directory yolo v nine.
So now we are going to the clone folder.
So now we are here at this clone folder.
Now.
So now we have done with the step number one.
Then the step number two will create a virtual environment.
Okay.
So to create a virtual environment I will write over here.
I on, I am.
Virtual environment, and I will be creating a virtual environment by the name YOLO v9 testing.
So this will be the name of my virtual environment.
Yolo v9 testing.
This will take few more seconds.
It will.
Let's wait for it to get completed.
Okay, so it's done.
So if I just.
Your ballot.
Here we have this jewelry nine.
Let's think forward here.
Benign.
The next step we will go to this scripts directory.
So I will just write.
First we need to go to the YOLO v9 testing.
So I will just write YOLO in testing folder.
Okay.
And then we need to go to the scripts directory.
So I will just write CD scripts.
And I will just activate this.
Okay, so it's now activated.
So now I will just go and.
But that's done.
So now in the next step, what we'll do is we will, uh, install all the required packages that we
have in the requirements.txt file.
So if I open the requirements.txt file, we can see all the required packages that are required to do
object detection on image video and on the live webcam feed using YOLO.
Benign are being listed over here.
To install all these required packages we just need to write pip install minus r requirements dot txt
and let's enter.
So this package installation will take time.
So if, uh, you can see over here I have written minus r.
So this is basically a hyphen RI1.
You can say that hyphen r.
So basically it means that uh recursively for each library will be installed that are listed in this
requirements.txt file.
So this package installation will take some time.
So let's wait for it to get completed.
Now you can see that all the required packages are being installed.
So now we will do object detection on image.
So I will just go to the GitHub repo over here.
So if I just go down over here.
So now we will be using the following nine models.
And to do object detection on image using following nine model we will be using the detect.py script
file.
And then we will use this command okay.
So let's move forward here.
So detect-2.py.
So let's see how we can do object detection on image.
So I will be using Python detect dash dot py.
And I have just created a folder by the name over here resources.
So here I've added three different images okay.
So now we will be doing object detection on these images.
And I have also added two videos over here as well okay so that's fine.
So then I will just define.
Thought over here as.
We'll go to the resource space for the.
And then I will be doing object detection on image one dot jpg first.
Okay, so I just need to pass the file name over here.
The spelling of.
Beaux Arts.
Correct.
So let me add weights over here as well.
So if you just go over here.
So and if you just if over here so go releases over here.
So now you can see that you'll be nine comes with four different models.
But currently we have uh nine weights available for two models which is YOLO v9 compact and YOLO v9
extended.
So I will be downloading the YOLO v9 compact model weights.
And we will be doing testing using the YOLO v9 compact model weights.
So now you can see that V9 comes with different models.
But currently the weights of YOLO one and compact model and the V9 extended model are available.
And we will be using the YOLO v9 compact model weights.
Although YOLO v9 extended model weight is better, gives better accuracy than YOLO, and compact model
like YOLO v nine extended model outperforms uh income.
Uh, all the other YOLO v9 models like you can see over here.
Well, now you can see the file is downloaded and I will just go over here, go under downloads.
Copy this from here and go into my.
Wandered over here and I'll just play it again.
And so there we have that model.
And that's all you need to do.
Okay.
So let's go backward here.
And if you just see over here we have the model weights available over here.
And if I just go below down over here.
Okay.
So I will just passing the normal weights.
So first the model weights I will be writing weights.
Then we will just go to the weights rectory.
And over here we have the following line.
Bad.
Seen it all and let's see how it goes.
So there are some stay over there.
Here is our Lord and let's see how it works now.
But this will take two more seconds.
I don't have a GPU available so I'm doing are testing it on my CPU.
Okay now.
So here.
Opening, it will work fine, but let's see.
Okay.
So now we have the output into this runs segmentation do image one.
So this is our output image which you can see over here.
Okay.
So now you can see over here we are able to track the person dog okay.
And here you can see that uh the car is quite blurred but our model is available uh also able to detect
that car as well.
But, uh, this is a wrong detection.
This is complete backpack.
Okay, so now one wrong direction is look fine.
Okay.
So, for example, if, uh, you got a case where you have very small objects, okay.
And you have to decrease down the confidence value, for example, currently my confidence threshold
is being set as 0.25.
Like you can see over here, the default confidence value is 0.25.
So what is this confidence value means.
So.
After doing uh, so object detection using yolo v9, we will only be drawing the bounding boxes around
that.
Around around that, objects that are on that, our confidence threshold or confidence value above 25%.
Okay.
So this is the confidence threshold.
So all the detected objects that have a confidence uh below 25%, uh, we will not be drawing bounding
box around them.
Okay.
So now you can see here the confidence value is 0.900.780..
Like something here as well.
Like it's not visible over here.
But we can see currently the back 0.48 the all the uh.
All the objects that have bounding boxes drawn around them have a confidence value above 25%.
Okay.
So like we are only drawing bounding boxes around those objects which have a confidence value above
25%.
So what this confidence value means, the confidence value means that the model is 25%.
For example, I've said that for for example, the confidence value over here is 0.90 for dog.
So this means that the model is 90% confident that this is a dog.
Here is person.
For the person, the confidence value is 0.78.
This means the model is 78% confident that the this is a person.
Okay.
And like this is what we meant by confidence value.
So and here I have defined the confidence threshold as 0.25.
So this means.
All the objects that have a confidence value, all the detected objects that have a confidence value
above 25%, we will be drawing bounding boxes around them.
Like you can see, we have drawn bounding boxes for a dog, for a person, for a god, and that's it.
Okay, so there might be some case where you have to decrease down this confidence value to do object
detection.
Okay.
For example.
If I decrease the confidence value to 0.10 and let's see, what results do I get from here.
So now by default the confidence is back.
So I just need to write 1% threshold.
So now I have decreased the confidence threshold to 0.10.
So what I mean over here is that the all the objects that were benign model detect all the objects that
my YOLO benign model, that which have confidence value above 10% will have bounding boxes drawn around
them.
Okay.
But now you can see, uh, I don't see any.
Back over here.
Let's decrease the confidence value to 0.05.
Like all the detected objects that have a confidence value above 5% will have bounding boxes drawn around
them.
So now you can see over here okay.
So now you can see we have detected a handbag over here as well.
Okay.
So let's decrease down the confidence value to 0.101%.
So this means that after doing object detection using YOLO benign, all the detected objects that were
confidence value above 1% will have bounding boxes drawn around them.
So if I just, like, crash over here.
So now you can see that this is what I want to show you over here.
So if you just see over here, let me open this image from here as well.
So this is the output image which we have gone to.
Now.
You can see over here, uh this is the backpack okay.
So this is correct direction.
This is the person over here like you can see over here.
We have detected person two times okay.
So now you can see there are two persons like it has detected person 2.42 times.
Although there is only one person okay.
Like you can see over here there are two person like it has detected person two times but there is only
one person.
Okay so.
But last you can see over here, uh, we have uh, detected two backpacks like you can see one over
here, one over here.
Okay.
So now you can see it has detected three backpacks, although there is only one backpack.
So like you can see that we have, uh.
Multiple bonding boxes around a single object, like there is one person, but you can see we have two
bonding boxes.
There is one backpack, but you can see we have three bounding boxes around the backpacks.
Okay.
So.
But to remove this overlapping bounding boxes like you can see that for person we have two overlapping
bounding boxes.
For backpack we have three overlapping bounding boxes now.
So to remove this overlapping bounding boxes we use a technique called non-max pressure.
So non-max suppression is a technique that is used to remove, uh, overlapping bounding boxes that
may arise from the object detection algorithm.
Okay.
So what is the main idea of norm expression?
So the main idea for the norm expression is to retain only the bounding boxes that have a high confidence
score than other.
Okay.
So what will happen is that we will be using norm expression to remove this, uh, like multiple bounding
boxes that have been drawn around a single object, like two parts.
We have only one person, but we have two bounding boxes.
Uh, like the model has detected two persons a plus.
You can see we have only one backpack, and the model has detected three backpacks.
Okay.
So now you can see we have multiple bounding boxes, uh, for one single object.
So to remove this overlapping bounding boxes or redundant or extra bounding boxes, we will be using
a technique called norm expression which will retain only uh.
So now you out of this multiple bounding boxes for a single object like person, like we have created
two persons, but we will only retain only one person, and that person will be retained that have a
high confidence value.
Okay.
So what will I will be use for this?
I will be using a technique called norm expression.
And here you can see we have a IOU threshold for the norm expression.
So this IOU is what non-maximum suppression.
But the value of this IOU threshold for the non-maximum suppression varies from 0 to 1.
So this value will be between 0 to 1.
So if we set the higher threshold value, like currently it's in the middle.
But if we set the higher threshold value like 0.80.9, what will happen.
This will result in a.
So what will happen is that the this only lapping bounding boxes will not be removed.
If we set the original threshold for the non expression of value high like it varies from 0 to 1.
And if I set the value 0.8 to 0.9.
So this overlapping bounding boxes will not be removed or very few will be removed.
And all the overlapping bounding boxes or the maximum number of overlapping bounding boxes will be retained.
Okay.
And if I just set the, uh, I use threshold value to low, like 0.1 or 0.2.
So this will result in all the overlapping bounding boxes will be removed.
And this will result in a fewer but more accurate detection.
So if I set up a threshold for non expression as a very low value.
So this will result in uh overlapping bounding boxes will be removed.
And this will result in fewer but more accurate detections.
So let's test this out.
So if I just set out the IOU threshold over here.
0.1.
Okay.
So currently you can see that we have only 1% but 2% collected.
We have only one backpack but three backpacks are detected.
So let's see if I just set this threshold value okay.
And I will stake its IOU ratio.
So let's see if I just set a small value of higher threshold.
Will it affect my result.
Will it remove the overlapping bounding boxes that are being drawn?
So now you can see that only we have one person.
Now we have one backpack.
And okay.
So now you can see that here we have only okay okay.
So now you can see that in the previous case we have two persons and three and backpacks.
But now you can see we have only one person and one backpack.
Like this means on the overlapping bounding boxes have been removed.
And if I just show you over here.
So now, if I just show you this output over here as well.
Well, now you can see over here like.
The is.
So now you can see we have only one bounding box around the person like you can see over here.
We have only one handbag.
Okay.
Over here we have only one dog.
Like all the overlapping bounding boxes have been removed.
Okay.
So now you can see that my output looks very fine.
Like I have not changed the confidence threshold.
I only adjusted the threshold for non expression.
And this has removed all the overlapping bounding boxes.
Like you can see that all the overlapping bounding boxes have been removed.
Okay.
So like you can see I have set it the very small value for the threshold for non expression which you
can see over here.
Okay, I've just set the value 0.1 and this resulted in all the overlapping bounding boxes being removed.
And if I just set the threshold for non expression as a high value like 0.9.
So the overlapping bounding boxes will be retained.
And this will like maximum number of overlapping bounding boxes will be retained okay.
So let me show you if I set the threshold value high.
And.
Like if I just show you over here.
So now you can see that there are so many overlapping bounding boxes.
Like for dog, they are two for the person they are.
They are multiple hand-bags backpacks are being rejected.
Okay, so there are so many overlapping bounding boxes.
So with the help of this, I would, uh, threshold value for norm expression.
You can vary the, uh, you can vary your results.
You can.
This will affect your results very much.
Like you can see now, uh, if I set the high value of threshold for norm expression.
2%, six Hand-bags six backpacks, two handbags are being detected.
Okay.
So in the same way, you can do object detection on your other images as well.
So you can try this out over here.
See, this is another concept which I want to explain about, uh, norm expression and transport.
So you can try it out with your own images as well.
So now let's test do object detection on the second image over here as well.
So I'm just using the default person's treasure that I treasure now.
Nothing different.
Okay, so we have the results now.
Over here.
So now you can see that we have detected person.
Person.
Okay.
We have detected these two person as well.
And the sports ball is detected as well.
So the results look quite good over here as well.
Like you can see the person over here and over here is quite blurred.
But our model is able to detect it as well.
In this way you can test on other images as well.
So now I will be testing on a video over here as well.
So.
I will just say radio one dot NPY forward.
Okay.
And here.
So now if I want to show the output.
Bye.
So I will just write you the image.
So this will be showing me the live results over here as well.
So now you can see over here this is a wrong detection.
So now you can see that we are able to detect the cars over here as well.
So I'm using CPU.
So the detection is very slow.
Like you can see that uh the inference is very slow.
But you can see that we are able to detect a car over here as well.
So the results look like.
Good.
So in this way.
So this works.
In the same way you can test out on other video as well.
So if you are running on CPU, you can imagine that the processing will be very slow.
But if we tried on GPU, the the frame rate will be very high and the processing will be very fast on
CPU.
The FPS or the frame rate is very low and the processing is very low as well.
Now you can say I've tested on other video.
We are able to detect a person handbag over here as well, and the detection results look quite impressive.
Okay, so in this way you can test on other images and videos as well.
So let's go on and do detection using live webcam feed.
We do object detection using the light webcam feed.
We will set the source to zero if you are using your internal webcam like I am using my HP laptop internal
webcam.
But if you are using an external webcam, then you can set the source 1 or 2.
Okay, but if you have only one external webcam, then you can set the source value to one.
Okay.
And let's run this up now.
When all you can see over here.
I am able to do object detection on the live webcam feed over here as well, so that I'm just running
it on my CPU machine.
So you can see, uh, the detection is very slow.
So that's one of the reason what you can do this object detection on the live webcam feed as well,
like I am doing over here.
And you can see the frame size is already by 640 okay.
So it's 640 is the bid and the 40 is the frame right.
You can see the 640 is the width and frame height.
So let's see I have this uh uh pic of the scissor.
So let's see if it is able to detect the scissor or not.
Okay.
So it's the night.
This is not a knife.
This is a scissor.
And let's see.
Okay.
So now you can see that as decorated as scissor now.
Okay.
So now you can see that here we have overlapping not a cell phone okay.
So now you can see it's going to detect it as Caesar.
And that is fine.
Like now you can see that it's being detected as Caesar.
So in this way you can do object detection on the live webcam feed as well.
And that's all from this tutorial.
Thank you for watching.