All right, guys.
So now we will see how we can train our model or potholes detection so you can see the pipeline in front
of you.
So first of all, we will import all these required libraries.
So first of all, I am going to import OS, then I'm going to import import log, then I will import
the display.
Basically, I use this library to if I want to display any image output image or an input image into
the Google CoLab notebook.
Therefore we need the display library and we are just clearing the output.
So here.
Before running this tape, please make sure that you have selected the runtime as GPU.
Okay.
Please make sure that you have selected the runtime as GPU and we will check now whether we have access
to GPU or not.
Because if we don't have the access to GPU, the processing will become a bit slower, very slow.
Okay.
So we are using the GPU memory, so that's fine.
Okay.
So this home is basically the helping variable which helps us to redirect to different files or folder.
But here we are installing ultralights using PIP install.
So usually it can be implemented in two ways by installing the package which is PIP install ultralytics
or by cloning the GitHub repo.
But PIP install ultralytics is a very easy way, so we will use PIP install ultralytics to install the
V8 package.
Okay.
So just using PIP install ultralytics.
It will install the V8 package over here.
But might take a few seconds, so please bear with me.
Okay.
So.
I'll check if your drinks package is imported and it's working fine.
By writing import ultralytics and ultralytics checks.
Okay, so Internet takes 0.34 installed and set up complete and it's working verified.
Okay, So now we'll go to over here.
So this is the data set which we have prepared the path for data set.
So in the last video I've shown you, like let me show you.
This is the part whose dataset which we have generated in the last video.
So this is the version which we generated.
So we'll just click on this version and click on export.
So if we export, then we'll click on continue.
And this just copy this.
Control C and just remove this.
And just paste it over here.
So what am doing is basically.
Let me show you first one.
So basically I'm just creating a datasets folder over here, and that means to perform this step over
here.
So it will create a dataset folder over here, let me show you so you can see that a dataset folder
is created over here and it's empty.
So.
If you see our present working directory, if we digest, if we see our present working directory,
it is this content.
Okay.
So if we want to save or if we want to after downloading this dataset, we want to save this dataset
into this dataset folder.
So I will set my current directory as.
Yes.
So now my current data directory sent is being set to this folder.
Let me show you.
So now you can see that my current directory is being sent set to this datasets folder.
Now I will install dataset into this dataset folder.
I am just installing this data set directly from Roboflow into this folder, so it might take few seconds
to for the dataset to be downloaded.
Like you can see here.
So dataset is being downloaded.
Imploding Workflow space Downloading dataset.
Dataset usually is downloaded in the zip format.
Then we basically adjust it according to our requirement.
So.
Oh, sorry, we don't adjust it.
It's called automatically extracted.
Okay.
So our dataset is being downloaded.
It's 46%, 48%.
Okay.
So we are just waiting for dataset download downloaded completes and then we can train YOLO V8 model
on this custom dataset.
Rutgers 89%.
9599.
Okay, so the dataset is downloaded and it's.
Around.
We can see this pothole dataset over here.
Okay, so now we'll train our model on this custom dataset.
Okay.
And here is our data rotation, which is this.
Okay, so let's train our V8 model on this, the same dataset.
So first we need to go here.
We can copy path.
And just add this part over here.
Okay.
And yet here we are using Yolo v eight dot model.
This model to fine tune our model on YOLO V8 on this custom data set.
So we are what model we are using.
Let me show you ultralytics.
Your love.
The air.
Okay.
Uh, just going on here.
Okay, let me go to the GitHub repository.
Okay, so here I am, went into the GitHub repo so you can let me show you.
So we have YOLO V8 models from five different models of YOLO.
YOLO, YOLO, V8'S.
YOLO V8 Medium, YOLO V8, large and extra large.
So although this is the this is a smallest model and this is very fast, but it is less accurate and
YOLO v8 X is basically more accurate, but it is less fast.
Or you can say it is a bit bit slower than YOLO v8.
Other models.
Okay, but it is more accurate model so we can use YOLO, yolo V8, medium older model which will be
fine.
So just right.
Yolo V8 empty.
And here I've set my dataset path and I'm training for 70 epochs and I have set my image size as 640.
Okay.
Now that's mod is equal to train and we are performing object detection.
Let's click on training.
Let's see if there is any error so we can fix or the training starts.
So there is an error.
Like data.is not found.
Okay.
Let me see.
Okay.
Basically is dash three in the path is basically creating an error.
Let me fix it.
Just make it this and just correct it from here.
But we need to do other things as well.
We need to go to data dot yml.
And here we need to update our folder path as well.
Just copy path.
And just paste it over here.
Just go here.
Just copy this path and just paste this over here.
Just an aghori here as well.
And just copy a path and just.
Click over here and control V Okay, so we have the only class name as Porthole and all others are fine.
Okay.
So just now I hope that there will no error and the training will work fine.
But let's see if there is any other error.
We will definitely correct it.
Okay, so the training is about to start, so it might take some time.
So.
So we have 1340 images in the training set and in the vector validation, we have 133 images.
Okay.
So it might take some time.
The training has started, but let's see, how much time does it takes?
Okay, so I'm training my model for the 70 epochs and it will take some time to train.
So I will be back as the training completes and then we will start from there and validate and test
our model on some images as well as on videos and see how our model performs.
So see, see you as the training completes and then we will validate our model.
So guys, the training has completed.
So we have trained our model on 70 epochs.
So it took more than an hour for the training to complete.
So we have got the last weird spy on the which is basically the last epoch and the best weights file
on which our model has given us the best performance or results.
So here in the weights section, we can see the best best weights file and last dot means the last weights
file like on the 17th epoch.
So here is the model summary.
We have got the mean average precision with 50 as 72% represented by 0.72 and the mean average precision
when varies from 50 to 95 is 0.408.
So the results or the performance of our model is very satisfying.
Or you can say that it's giving good results.
So in that runs detect train folder.
So in all our results, the confusion matrix, recall curves, F1 curves, precision curve validation,
batch results are saved in this runs detect train folder.
So am just checking here.
The different files I have in the past detect train folder.
So just just running this.
It will show you that we have a precision curve over here.
F1 curve over here, precision recall curve over here and results dot csv which contain the performance
of the model on each epoch.
Then we have results dot png over here in the results dot PNG file.
Basically we have the training and validation loss graphs and here we have the prediction on them of
the model on validation batches and their labels and the prediction of the models on the train batches.
So let us first describe the confusion matrix.
So Confusion Matrix is basically a chart that shows how our model handles different classes.
So we can see here pothole and this is the prediction.
So 68% of the time our model correctly detected that there is a pothole when there is a pothole, while
32% of time when there was a pothole.
But our model was trained to detect the pothole.
So we can say that a 68% of the time our model correctly detected that there is a pothole, while 32%
of the time when the pothole is there, but the model is not able to detect it.
Okay.
So here is the graph of the training and validation loss.
So in the training and validation loss, the box loss and the task loss is most important.
The others don't matter much.
So the overall behavior of the model is very convincing and we can see that the model is converging.
Then you can see that the loss is decreasing in the downward direction.
While the precision and recall curve is moving upward is improving.
So if we train our model, higher epochs like 150 epochs or 200 epochs, we will get more better results.
Okay.
You can see that the loss is clearly decreasing and the precision is increasing.
So here are the model prediction results on the validation batch.
So these images are basically not used for training.
So it is always better to take a look like how our model is behaving on the validation dataset.
Like you can see here, the model performance is very convincing.
It is able to detect the potholes.
Okay, so now we will validate our custom model.
So here we are taking the best weights file and using them to validate our model.
Similarly as before, we are using the command line interface to do that.
So the only difference is that previously we write mod is equal to train, but here we are writing mod
is equal to validation because we are validating our model on the validation images.
So.
So validation.
So this script, basically this cell is using the test dataset images which are not used before.
So you can just run this and to validate the custom order.
So it might take a few minutes, I think.
I have not given the break path, so just go over here and where you have the best rates file, just
click on copy path and just.
Control V and just remove this.
Okay.
And I have already set the data dot yml file.
Okay, that's fine.
And just run this cell now.
So here we are, validating our custom model.
So it might take about few minutes.
So let's wait and see.
I will also add this CoLab file in the attachment so you can run this script on your site as well.
So we have validated our custom order.
So we are getting a mean average precision with 50 is the 72% and mean average precision when varies
from 50 to 95 is 0.40%.
7% means 40%, which is a good and fine.
So now we will run our model on the test dataset images which are over here.
Like you can see.
So these are the test data set images on this will run the model and see what those do I get.
So I have set the path already and just run this cell.
So here I'm doing prediction on the test dataset images and let's see what results do we get.
Okay.
We take my take a few seconds.
Okay.
Let's display these images.
We're here.
Okay.
Award is basically file pod image.
Pod.
Everyone.
Let me see what it's giving this error.
But there was an issue in the script, so I just replaced it with the predicted single image.
And here is our results.
So you can see that the model is perfectly detecting that there is a pothole.
Now what we will be testing our model on a demo video, so just downloading the demo video from a drive.
Okay, so now we will test our model on this demo video.
So it might take a few seconds for this script to run.
So let's wait until this is done and then we will see what results do we get.
Okay, So our model is detecting potholes.
Like you can see that for one one and okay, so let's see where our results are saving runs detect,
predict two.
Okay, so let's display this output demo video.
The demo video name is demo dot mp4.
So okay, just check what results we are getting.
Either they are satisfying or not.
So I'm just displaying the output demo video over here.
Then I will show it to you as well.
Getting the an output demo video.
Let me download it and see what results do we get.
So just downloading it.
And displayed.
Okay.
So you can see that the model is detecting perfectly that there are potholes.
Okay.
So it's is also detecting and here it's also detecting a pothole.
So the results are overall fine.
Like you can see that the model is working very perfectly.
Okay.
So let's see if we can test on some other demo video as well.
Okay.
So currently I've only have this demo video, so I hope you have learned a lot from this lecture.
See you all in the next lecture.
Till then, bye bye.