For now, we will see how we can do vehicle counting, entering and leaving using YOLO V8.
So first of all, for this project I will be using this GitHub repo.
So here are the steps provided to run the code.
First I will run the code using the steps provided.
Then I will explain you the complete code of the predict.py file.
Okay, so when we run this script in this github repo we will be able to get the results.
Like you can see over here.
We will we will get the number of vehicles leaving the count of number of vehicles leaving.
And we will also get the count of the number of vehicles entering.
Okay.
So here are the steps provided to run the code.
So we will follow these steps and run the code.
Now.
So to run the code, I will open the PyCharm here.
So here I will just write PyCharm and open PyCharm.
So I will just follow step by step.
So if you want to implement on your side, you can implement it on your site as well.
So the repo I'm using is YOLO V8 Deepsort Object tracking by Mohammad Moin.
It's my repo which I have created on one vessel YOLO v8 Deepsort object tracking.
I will add the link in the description as well so you can check it from there as well.
So I have opened PyCharm over here, so it's creating a workspace.
Or you can say it's preparing the workspace currently.
So it might take a few more seconds.
Oh, so just close tip of the day.
Don't need it currently, so we'll go to file.
I click on new project.
And from here I will choose the folder where I want to create the project.
So I have created an empty folder by the name vehicle counting, entering and leaving.
So this is this will.
This will be my project main folder.
So let's go from here and select this folder as my required folder.
So just click over here, go to your course, and from here I will select vehicles counting, entering
and leaving.
Okay, So at please look at that location over here and location over here is same.
Then click on create.
So in this way I will create a new project over here.
So this might take few seconds.
Okay, so.
We can see that the project is now created over here and the project file name is vehicles, count date
and entering and leaving.
Okay, So as this project is created, it's creating a virtual environment.
Virtual environment.
So, okay, so this project is created over here.
So now I will just follow the steps in the repo and just do the implementation will open the terminal
over here.
Let's go to the repo over here.
And just follow the steps provided in this post.
Okay.
So first of all, here are the steps to run the port.
So first of all, I will go over here and clone the GitHub repo.
So just click over here and copy this command and just paste it over here and click on Enter.
Okay, so this might take a few seconds.
It's currently cloning the GitHub repo.
So after the GitHub repo is cloned, you can see the folder over here.
Okay.
So you can see that it's 67% done.
But founder of my GitHub repo is created over here.
And as this gets 100% so we can see the files over here as well.
So.
If we go over here, we counting, entering and leaving and just click over here.
So now we will see all the files.
So just wait a few seconds until it gets updated over here.
Okay, so here we have vehicle counting, entering and leaving and.
And here are the files.
So here we have the ultralytics over here.
This is the CoLab files are also there.
So you can run this script or this project in the Google CoLab as well.
So over here we also have the in Ultralytics if we go over here so we can also go inside YOLO, we ate
and then we go to detect and we can also see the predict.py file over here as well.
So.
Let's set this project or this clone folder as our current directory.
So to set this folder, our current directory, we will just copy this command and just paste it over
here.
So now this project is or this folder clone folder is set our current directory.
So just click on Enter.
So now this folder is being set.
Our current directory.
The folder name is YOLO Deepsort object tracking.
So in the next step, what I will do is I will install all the dependencies or all the required libraries
required to run this project.
So if we skip this step, then in later on we might face this issue that the following library is not
installed.
For example, Hydra library is not installed or some other library is not installed.
So it's always better to install all the required libraries by installing the dependencies.
So just paste this command over here.
So it will install all the dependencies and all the required libraries will also get installed.
So this might take a few seconds.
So if you are running the script for the first time, it will take time to install all the packages,
but have been running this script quite a while, so it's appearing here.
Requirements already satisfied.
So now let's look at the another thing which so basically.
Now we'll go to the detect folder as we are doing object detection and tracking in this project.
So we will only focus on the tracking or detection and tracking.
So we are not doing the segmentation.
So now I will set this folder, detect folder as my current directory so I have the access to the predictor
PI train dot pi and the validation dot pi script.
So let me set this detect folder as my current directory.
So now my current directory is being set to YOLO v8 detect folder.
Now, in the next step, what I will do, I will go to the download and Deepsort files from the Google
Drive by going towards this link.
So just copy this link and just paste this link over here.
Okay, so I will just download this deepsort python file by clicking on the right click, doing the
right click and click on download.
So it will download in the zip format.
I will unzip it and just add it to this folder where I have this project.
So it's zipping currently the folder, so it might take few seconds.
But it will not take very much time.
So.
Okay, so now the file is zipped.
Now it will start downloading.
It will take around eight seconds further.
Okay.
So it's very soon it will be done from here.
So as it completes.
Okay, so the file has been downloaded, but it's a zip file, so we will just go over here.
Okay.
But okay, we can see now.
Okay, just copy this from here and just go to your V8 and your V8 course over here and let's see what's
the name of vehicle counting, entering and leaving?
What's the name of our project?
As far as I remember.
Okay, so let's go towards our project because counting, entering and leaving.
Okay.
Just open the wrong file.
Okay, so now I will go over here.
Okay?
Just.
Just click over here and just place this folder over here.
I don't need this, so just close it currently.
Okay?
So just extract the files from here and click on.
Okay.
So all the files will be extracted.
Then go over here and just copy this folder from here.
Then go back and click on your Deepsort Object Tracking YOLO Ultralytics YOLO V8 Detect and just paste
this folder over here.
So that's cool.
So in the next step, what I will do is I.
I have the deepsort pytorch object.
Because what we are why we are downloading deepsort pytorch folder because we are implementing object
tracking using deepsort.
So we need to have the deepsort files in our required directory as well.
Okay, so what's next is I don't need this now.
Okay.
So now let's download a sample video from Google Drive.
So I have this this folder into detect folder.
So I'm right by this way.
So just go over here and just download a demo video for testing from the Google Drive.
So I'm just downloading a demo video for the testing from the Google Drive.
So this might take a few more seconds.
So it's 100%.
So the demo video is being downloaded from that Google Drive.
Now we'll run this script.
So basically we are performing object tracking detection, tracking plus vehicle counting.
So we need to download the files from here.
So I will just go over here and download the update predict.py file.
Okay, so just download this file from here and just click on right click.
And I think the processing is becoming slow.
I don't know what the reason, but let's just do a right click.
I think it might take some time.
Okay, so just click on here, download, okay, download anyway, and just go back over here and the
file is downloaded over here, so that's cool.
Okay, so here is our file showing folder and just copy it and just go over to the detect folder and
just place this over here and just remove this predict.py file and just I'm just remove the previous
predict.py file.
Please check this.
Okay.
So I am doing, I think I'm doing a correct way.
Now I will run this script by clicking on predict.py file and just pasting this command over here and
just clicking on enter.
So now the script will run.
As the script starts to run, I will explain you the complete code and the process as well.
Okay.
So.
The script has started to execute, so this might take few seconds to start, but as the processing
starts on the video, so we will explain you the step by.
I will explain you the code step by step so it comes easy for you to understand.
Okay, so the weights are loaded.
Okay?
So just don't ask me again, please.
Okay, so now the weights are being downloaded.
Your the V8 empty.
So we are using your V8 pre-trained model for this project.
YOLO V8 comes with six different models YOLO V8 and is the smallest, but it is the fastest as well.
But it compromises on accuracy.
YOLO V8 is the most accurate, but it is less in speed.
Or you can say it is not as fast as compared to the other YOLO V8 model.
So the script has started to run and if I click over here to see the live demo, what I'm getting over
here.
So okay, so just see one of the results and then we can will go to words to explain you the complete
code.
And we'll be just focusing on seeing one of the results only and will explain you the complete code.
So after seeing only one of the results.
So okay, so as you can see over here.
Let me see what results over here.
So as this trails crosses this line.
Okay.
So let's see what we get over here.
So by just I'm seeing as this train crosses this line.
So basically, when this train, you can see that this trail is moving the south north direction, basically
this direction is the north direction.
So as this train is intersect with this line, please focus on, you will see the number of vehicles
entering.
So as this train, the color of this line, green line will also change.
Okay.
Change to white.
And the number of vehicle entering is now truck is equal to one, although it's directing it wrongly.
But if you use a yellow x or yellow eight larger model or medium model, then it will give the fine
results.
I'm using YOLO v eight but on the larger model it gives that it good accurate detections.
Okay, so now when this train is coming from here, these trails intersect with this line.
You will see the increment over here, the number of vehicles leaving.
So let's see over here.
Okay, So let's see.
Just it will take a few more minutes.
Okay, So I'm just waiting for these trails to cross this line so you can see these trails, these lines
below.
So when this line trail intersect with this green line, you will see an increment of the number of
vehicles leaving.
Okay.
So as we are implementing object tracking over here as well using Deepsort, So what object tracking
is, is basically an object tracking.
We assign a unique ID to each of the detected object like you can see over here.
Here we have detected the car.
Here you can see a unique ID by the number four with this object here.
We also detected a car and you can see a unique ID 15.
And here we also have detected the car and you can see unique added 12 here.
We have also detected the car and you can see a unique ID 11.
So these unique IDs are being assigned randomly.
It is not in the incremental order, like you can say after one, two, three, four, basically model
assign these unique IDs randomly.
Like after four, there can be ten, there can be 15, there can be 105, there can be 200.
So these unique IDs are being assigned randomly.
Okay.
Like for 15, 12, seven, 11, and here I can see that two as well.
And here it is.
Eight So these unique IDs are being assigned randomly, so you don't need to worry like, well, I'm
not getting in the order.
So these IDs are being assigned randomly, so you don't need to worry at all.
So now in the next step, we will see that if as this train like you can see this train, please focus
on what my mouth says as this train like you can see this point, center point, this center point,
the bottom coordinate.
So this is our boat at the bottom of the bounding box, the center point at the bottom of the bounding
box.
Okay.
So when this train intersect with this line, you will see an increment in the count of the number of
vehicles leaving.
Okay.
So just focus on this line.
And as this trail intersect with this line, you can say that this trail is intersecting with this line
and you can see that the car is detected.
And when this trail intersect with this line, you will see that the this trail, this trail intersect
with this line, this green line.
You can see that the number of vehicles entering as the car as one.
Okay.
So just focus on this result.
Only then I will explain you the predict dot pie script.
What's in it?
Okay, so just.
I'm waiting for this to intersect.
Okay.
So as this train intersect with this line, you can see that we have the increment.
The car is equal to one.
So let's move towards the code and I will explain you the code now.