I love everyone.
In this video tutorial I will run on Windows.
So first we need to set up environment for YOLO V8 and install required libraries.
I'm using Anaconda Navigator, so I have open Anaconda prompt and so I will create a new environment
with Python version 3.9.
So before I create the new environment, let me show you the folder where I have the input image for
a demo video to test the YOLO V8 model.
So this is the input image and the demo video, of course, which we'll use to test the efficiency of
YOLO V8 model.
So first of all, I will redirect to the folder where I have this.
Input in which video.
Now I will create a new environment and create.
Minus ten.
Know, the A Lecture series will be the name of my environment.
You can choose as per your choice, so you can choose any name for your environment and by conversion
as 3.9.
Now I will click on Enter.
So it will create a new environment.
Just why.
It might take a few minutes, so please bear with me.
No, I will activate the user environment which I have created.
Gonna activate.
Yolo v eight lecture series is the name of my environment.
So I'm activating it.
Okay.
So I have activated my environment.
After activating the environment, I will install ultralytics.
So for this I will write PIP install.
I'll draw.
Radius is equal to 8.0.
Find zero and click on Enter.
So YOLO V8 can be implemented in two ways.
One way is to clone the GitHub repo or.
Other way is to install ultralytics.
So prior versions of YOLO don't have their.
Official package.
So YOLO V8 is the first version of YOLO which has its own package which.
So.
YOLO V8 can be implemented by just writing PIP install ultralytics.
So it's very easy and simple.
So write python over here and see if I have installed torch.
Fort Dodge.
Uh, is this module available or not?
Let's see.
Okay, so this module is available, but in case if this module is not available.
So how to install it?
Let me show you over here as well.
So you just need to go to the PyTorch website and click on Get Started.
And here you will select by Dodge, build stable or operating system as Windows.
But if it is Mac, you can select Mac.
If it is Linux, you can select Linux, then package it with PIP.
Language will be Python and I don't have label, so if I have to install this package I will select
CPU.
But if you have label you just need to go click here copy and you just need to go to.
Anaconda prompt and just exit over here.
And just did this.
But as I don't have Gouda so it will definitely give error because I don't have a GPU available.
Okay.
So next I will go and run YOLO V8.
For object detection.
So let's run YOLO V8 for the object detection.
So to run your revered for objection.
Right.
Your low dose is equal to detect.
What is equal to predict.
Modern is equal to YOLO.
We ate and bought.
Source is equal to image.
The name of our input image which have saved in the folder is.
Image dot jpg.
And just run it.
And see what the results do we get.
It might take a few seconds or a minute.
So let's wait and see what the results to.
So it's downloading the Pre-trained model over here.
The Pre-trained model is downloaded.
Okay.
So image.jpg is not defined.
Sorry.
The name of my input image was image one dot jpg.
So just correcting it.
So you can see that our results are saved in run detection.
Predict two and our model was able to detect 10%, one bus, two traffic light, two backpacks and two
handbag in the image.
So let's see the results and then we will run object detection on our video as well.
So here is the input image which I have passed, and this is my model which was downloaded.
When we run the script and here runs folder in which my output of output image is saved.
So let's check the output image.
So this is my output image.
You can see that the model was working very fine.
It is able to detect the traffic light persons and back and very well.
So the results are quite fine.
So now let's test this model on a demo video so as I don't have a GPU available, so the processing
will be a bit slow.
So let's wait and see the results on a demo video as well.
So to run on a demo video, I will just change the source as.
denmark.mp four and just demo.mp four is the name of my input video on which I want to perform the detection.
So it might take a few more seconds.
So let's wait and see.
So you can see that as I don't have a GPU available, I'm using CPU so the detections are a bit slow.
So I have already run this script.
So let me show you the output which I got.
But this is the output demo video which was getting you can see that the results were very fine.
You can see that the model was able to detect the car's track.
There is a wrong prediction of track, but overall the results were fine.
Like the model was able to detect the cars, truck and so on.
So now we will move towards the.
Anaconda prompt and let's explore some further things.
You can set the confidence value as per our choice if we want.
Our deduction shouldn't be below a certain confidence.
So we can set the value of confidence as per our requirements.
So here, for example, I am setting the confidence value as 0.8.
So the deductions below the confidence 0.8 will not be appearing.
So let's set the confidence as 0.8 and click on Run and see what results do we get.
So our output is saved in runs.
Detect prediction file.
Let's see what the output do we get?
Okay.
This move course differed?
Is the prediction pipe folder.
And here is our output.
So let's see what is different from the previous one over here.
Thought.
Now you can see that.
Few deductions are missing or not.
We are out.
For example, we are unable to detect the bus.
We are unable to detect the traffic light.
We are unable to detect these two persons as well.
Okay.
The reason why we cannot detect these two persons because we have set the confidence value limit as
0.8.
So the model will not detect those in which order, will not do the reductions or the detections will
not be printed, which have a confidence value less than 0.8.
So only those detection will be printed on the image which have a confidence value above 0.8.
Okay, so let's explore some other things as well.
The other thing is that we want to save the bounding box for great sports.
Want to save the bounding box option so we can write.
Complete.
Saved dash tags.
Is equal to true.
So this will save the bounding box information.
Let me just click over here.
You can see the bounding box coordinates.
Information will be saved in a text file.
If we reset save dash text is equal to true.
So our output is saving prediction six labels world and let's see what do without what output do we
get?
So.
I'm just going to prediction six folder and if you see labels.
So here you will save image file.
So let me show you this image file.
So now in this, you can see that these are our detections coordinates.
For example, 26 represents the class number.
These x, these are to the X1Y1 coordinates the top left, and these two are the bottom right coordinates
of the bounding box.
So for each class, we have the coordinates.
And this is the class number.
This is our top left coordinates.
And these two are the top left coordinates.
And these two are the bottom right coordinates.
So in this way, we have the coordinates for each of the objects in our image detected.
Object in the image.
So now let's see for the new things.
So if we want to crop all the.
The teeth were.
For example, we have detected 5% damage.
So I want to crop on the detected persons in the image.
We can do also do this by restricting.
Save dashboard.
Is equal to true.
So this will save all the detected objects in the image separately.
Etsy would do the results.
Do we get.
Then I will show you the results as well.
So the results are saved in run detect predict seven labels folder.
Let's see the results.
So click on crops.
So let me see what.
So you can see over here.
Let me open this image.
So you can see that only this bus is detected like you can not see our other objects.
So the the frame in which we have the bus, we have only this frame a separately stored.
So let's see other objects as well.
Just open this image and say.
Resemble this.
This bonding box or this is also separately shaped.
So using touch image, we can save each of the bounding box separately or each of the detected image
separately.
Okay, let's explore some new things together.
Okay.
So.
Now you can see that we can also remove labels or hide labels or hide the confidence value as well.
So to do this, I will just write.
Eight dash labels.
Is equal to true.
And a great confidence.
Equal to.
So.
Of this will hide the labels and copy value from the.
Objects in the image or the bounding boxes as well.
It will also hide the.
Objects in the.
It will also hide the labels and the confidence values in the videos as well.
So let me show you in the latex, our output is say predicted.
So if I show you this image.
So now you can see that we don't have any confidence value or the label value over here.
So they are missing.
So by setting high dash label two and high dash confidence to hide the confidence value as well as the
label as well.
So now let's move towards the segmentation part and see what do we can implement over there as well.
So to implement the segmentation, you just need to do one thing or you can run the detection on a live
webcam as well.
You just need to show change source as zero and you can test it on live webcam as well by changing source
to zero.
So now.
Just to implement segmentation.
DOS will need to do one thing only by checking.
Changing dos is equal to segment.
Okay.
And just click and just you need to change the modulor as d'assise.
So Shg represents segmentation while for classification, while right click.
Okay.
While for simple reduction just right YOLO, V8 and V8.
So just click on enter now.
And see what results do we get?
So it might take a few seconds.
So let's wait and see what results we are getting.
Okay, so our results are saving one segment predict folder.
So let's go to this folder and see what results do we get over here.
Okay.
Select e-mails to assist under or over here.
Strong.
Let's open this.
So this is our output image.
Let's see this image.
What results we are getting over here.
So you can see that we are able to implement detection as well as segmentation as well.
So the bus is being segmented as green.
So here we are implementing semantic segmentation while the persons are have a mask of maroon, while
hand backpack, backpack has the mask of yellow.
So this is basically semantic segmentation, like same object, have the same mask, while different
objects have the different masks and upon different color of the bounding box.
So let's implement some further things over here.
So in the segmentation as well, we can hide label as well as the confidence value.
Let me show you how you can do this.
Well here.
And you just write.
Hi, neighbors.
Is equal to true.
And confidence is equal to true.
Please click on this.
So it might take a few seconds to run.
Okay.
So I think that I have not written the spelling of convenience.
There is a mistake there.
Let.
Can you see?
Okay.
So I have written.
Okay.
So there is a space issue.
Let me correct it.
So please, while implementing this, make sure that there is no such space and click on Enter.
Now.
And see what the results do we get here?
Might take a few seconds.
Okay, so the results are saved in run segment prediction.
So let's move towards there and see what results do we get.
So now you can see that our output image does not contain a label and the confidence value.
So this is the output that neither we have, the label or the confidence value.
Well, not if we want to show the output in real time what we need to, but just add one thing.
Just add show is equal to true.
It will display your output in real time, but it will be appear only for one millisecond.
Let's see.
So just press enter and see.
It might take few seconds to execute, so wait for few seconds until it executes.
Okay.
So it will appear only for one millisecond as you can see.
And our output is saved in runs.
Predict four and let me show you the output.
Okay, so it's just seven runs, predict four.
So here is our output.
You can see over here.
Just opening it now.
So this is our output.
You can see that.
But by writing show is equal to two, we are able to display the output in real time for one millisecond
and output is saved in the folder as well.
So let's move forward now.
Well now to convert our V8 model into Onnx format, I will write YOLO mod is equal to export loss is
equal to DEC.
If we have a detection model in the case of segmentation, we will write segment and in the case of
classification we will write CLS and model YOLO V8.
Empty and format is equal to on x.
So after adding this, click on enter and let's wait.
It might take a few seconds for the execution.
So let's wait and see how our model is converted into Onnx format.
We are able to convert our YOLO V8 model into Onnx format so it is saved as Yolo v8 n dot onec.
So let me show you this file as well.
So here we have the dot Onex file you can see over here.
So we have successfully converted our model into onex format.
N dot onex file here.
Now what to do all this in Python instead of one line?
I will go to go to my folder.
Okay, so in this folder I will have created a file by the name prediction.
I have created a.py file.
prediction.py file which you can see over here.
Now I will create a project in PyCharm.
Let me open PyCharm.
So this I have opened PyCharm.
I have created a project and here I have the prediction.py file.
So here I have written the code here, so let me explain you the port from ultralytics import yolo.
Then I have initialized YOLO with the model name.
You can see here I have passed the name my model.
Yolo V8 and you can pass any pre-trained model or if you have any custom model, you can also add it.
Add that model over here.
Then I have I am using model dot predict.
So predict method takes all the parameters of the command line interface.
So here I have defined my input image image one dot jpg save is equal to true and to save the bounding
box coordinates information.
I have written a save dash text is equal to true as well and I have set the confidence value is equal
to 0.5.
Now let's run this script using Anaconda prompt.
So I have open anaconda prompt and here I will write.
Light on prediction, dot pie and press enter.
So now the script will execute and take a few seconds.
So let's wait and see our results Look.
And so it might take a few more seconds, so please bear with me.
It will not take more than two seconds.
So now our results are saving runs detect, predict well and labels.
So let's go towards this folder.
Okay runs detect predict 12 and here you can see the output image.
Let me show you this image as well.
So just opening the image.
And so this is our output image, which you can see over here.
The detections look very fine.
So last we can also see.
Our Indian labels folder by bounding box card in this text file by bounding box coordinates are saved,
so you can check it as well.
Now we will see how we can convert our YOLO model into an ONNX format.
So let me show you this as well.
Convert model in x format.
Just point out this line and write model dot export.
Format is equal to.
Interest and overdubbed an X.
Now just save it and just open Anaconda prompt.
And right by Thorne reduction dot pi.
And just press enter and see whether our model is converted into onnx format or not.
But we can see that our model is successfully converted into Onnx format.
Let me show you the Onnx file as well.
So if we go over here, this is the YOLO V8 and dot on X file.
So we have converted our model YOLO with our model into onnx format.
This video tutorial we have implemented.
Object Segmentation and detection using VR.
In the next video tutorial, we will run it in Google CoLab.
See you all in the next video tutorial.
Till then, bye bye.