Now we will train the Yolo v eight segmentation model on the pothole images dataset that we have created
in the previous lecture.
So in this video tutorial we will see how we can train the YOLO eight segmentation model on the porthole
images dataset that we have created in the previous lecture.
I have already prepared the Notebook Google CoLab notebook For this lecture I will guide you as complete
step by step of the complete overflow that how you can train your YOLO v eight segmentation model on
the pothole dataset.
If you follow this complete video tutorial, you will be able to train the YOLO segmentation model on
any of the custom dataset.
So let's get started.
Before running the script, please make sure that you have selected the runtime as GPU.
So my hardware accelerator is being set as GPU, that's why.
Okay.
So in the first step I'm importing all the required libraries.
I only need the library image library to display the input or output image into the Google CoLab notebook.
So we need the image library to display any input or output image in the Google CoLab notebook.
Okay, so just run this cell.
For next.
I am just importing cloning the GitHub repo of YOLO V8 Ultralytics over here.
Okay, so just cloning the YOLO v8 ultralytics GitHub repo over here.
So it's done.
Now you can see that over here.
So here we have the Ultralytics.
If you go over here, we have the YOLO V8 over here and then we can see the detection and segmentation
folder.
So that's it.
So now in the next step, what we need to set, we need to set this cloned folder which we have cloned
over here as our current directory.
So just copy path and just paste this path over here and just run this.
Now in the next step before running the training prediction or validation script, we need to set install
all the required libraries that are necessary to run this YOLO V8 or train the YOLO V8 segmentation
model.
So or do the prediction in the further case as well.
So here using this we will install all the required libraries or the dependencies that are necessary
to run the training prediction or the validation script.
So if you skip this step while running the training validation or the prediction script, you will definitely
face the error that the Hydra library is not installed because you haven't installed the Hydra library.
Then you also face the error that PI test some libraries not installed.
So you can see that some some libraries.
This is appearing requirements already satisfied because some libraries are by default installed in
the Google CoLab.
We don't need to install those libraries.
Okay.
While some libraries are not installed.
So you can see that these are being downloaded over here.
So this step is merged because if you don't run this step or skip this step, you will definitely face
the error that are forming.
The emperor is not installed, Hydra or Matplotlib or Seaborn libraries not installed.
So the only dependencies or the required libraries are being installed next.
As we are doing segmentation over here, then we will need to go to YOLO V8.
And the segmentation folder.
We need to go to this folder and check this folder as our current directory.
I've just have just set this folder as my current directory.
Then we need to see what is our present working directory.
So the segmentation is being set as my present working directory.
So now in the next step what we need to do is we need to export this data set from Roboflow.
Like just copy this from here.
So how did we do this?
Click on export and like the format and just copy this from here and just paste this over in your Google
CoLab notebook.
Okay, So let me just open the Google CoLab notebook and just paste this over here.
So then in this way you can export the data set from Roboflow into your Google CoLab notebook.
So I'm just exporting the data set from Roboflow into the Google CoLab notebook.
So this might take few seconds.
Okay.
So that's I think the dataset will be downloaded.
Okay.
So the dataset is started downloading.
Okay.
So it will be downloaded in the zip format and it will automatically unzip.
Okay.
So now laticeps is consist of only 96 images, so it is easily downloaded.
So now if we click over here we can see the potholes detection dataset and we have the training validation
folders over here.
Okay, so let's now uh, okay, so just set this as our current directory copy path and just set this
as our home directory over here.
Okay.
So now let me see.
What if it is my dataset location from here?
Okay, so here we have the dataset, potholes detection dataset over here.
Okay, let's train our model and see if there is an issue so we can fix it.
And then we will, uh, after the training will take quite some time.
So I'm training the YOLO segmentation model on 100 epochs.
Okay.
What we see over here.
Okay, so there might be an update in the YOLO.
So let me just fix it.
Okay, So.
So if you face ever any issue like this, so you just need to go to.
Like just like your lovin it.
I'll try it.
So just write this over here.
Okay.
And just click on the first link over here.
And just go to ultralytics.
YOLO.
There might be an update, so you might face this error.
But if you work like like this like I'm doing, you will not face this error.
So just go over here and just copy this because here I'm just pasting this error copy and just paste
this over here.
And I hope now our issue will be solved and will not be facing any such issue.
So let's get started.
Let's train the YOLO Age segmentation model.
Okay, so the training is about to start.
Let me see if there is any issue so we can fix it.
If it's working fine that then that would be great.
Okay.
So first of all, it is downloading downloading the Pre-trained model from the GitHub repo into this
Google CoLab notebook.
So.
And now you can see that the Pre-trained model is being downloaded.
We will fine tune this segmentation model on the potholes images.
Okay, so we are just fine tuning this segmentation model on the potholes images.
So that training will take around one hour.
So as the training starts, I will pause the video and when the training complete, I will be back and
then we will discuss the results.
So the training is start.
I am training the YOLO segmentation model on 1.2 epochs, so the training will take time.
So I'm just pausing the video and when the training will complete I will be back and then we will discuss
the results.
Well, we so we have trained the eight segmentation model.
Or you can say that we have fine tuned the YOLO eight segmentation model on potholes images, and we
have trained the segmentation model on 120 epochs with default image size as 640 and here we pass the
data dot Yml file path data dot Yml file contains the train test and validation images file paths and
the model we use to fine tune the model we use to fine tune this.
YOLO.
Yolo v eight comes with five more different models Yolo v eight and is the smallest, but it is less
accurate and it is fast, while YOLO eight X is more accurate, but it is less fast as compared to the
other YOLO V8 model.
So we have considered a medium level of V8 model for to fine tune our YOLO V8 segmentation model on
the potholes dataset.
Okay.
Or you can say that we are training the V8 segmentation model on the potholes images dataset.
So we have trained the YOLO segmentation model on 120 epochs so we can see that after every epochs,
the mean average precision with 50 and mean average precision with 50 to 95 is improving.
So after training the segmentation model on 120 epochs, here we have the results.
So let me show you the results.
We're here so we can see that the mean average precision with 50.
We got at the end of 120 epochs is 0.353 and mean average precision with 50 to 95 we got is 0.159.
These are not very good.
Mean average precision values are because we have only trained our segmentation model on 96 images.
Our dataset consists of 96 images, but if we train our YOLO segmentation model on a large dataset like
1015 hundred, then we will definitely get a mean average precision above 70%, like 0.73.
Okay, so it's currently 35.3% and it is 15.9%.
Okay.
And our best weights.
So best weights best represents the best weights.
Best weights are the way those weights one are represent the weight on that epoch.
For example, on 118 epoch, our model gives us the best results.
So this will be considered as the best weights.
So best dot represent the best dot, represents the best weights, which means the weights on the epoch,
on which model performs the best, while last.is the weights of the model on the last epoch.
So the last epoch over here is 1/20 epoch.
So the last dot represents the weights of the YOLO train, YOLO segmentation model on the last epoch.
So here we have the model summary.
The mean average precision with 50 we got is 0.532 and the mean average precision with 5295 is 0.218,
which is 21.8% and this is 53.2%.
And our results are saved in run segment train.
So if we see the results.
We stood in this folded framed folder.
Our confusion matrix results.
Training and validation loss results are saved.
So let me check what different files we have in this folder.
So just try checking the files and files in the training folder.
Okay, so check the files in the training folder.
So just click over here and click on LHS and just pass this path from here.
Copy path and like just paste this path over here and let us see what different files we have in this
training folder.
We are all our results are saved, so we have confusion matrix results dot PNG file.
We have the validation predictions as well.
We have the F1 curve, we have the recall curve, we have the precision curves as well.
So let's first validate our custom order on the best weights which we have got over here.
Best Dot.
BT Okay, so we always consider the best split.
So best DOT represents the best period.
So let us evaluate it, the custom order on the best weights so we are validating the custom order on
the validation dataset images.
So if we see over here, our validation dataset images are over here.
So the validation folder contains the validation dataset images.
So these are around 15 images.
So we are validating the Yolo v segment.
Train your the segmentation model on our whole dataset.
Okay.
On these images.
So let's run this.
So we are using validation dot pi script because we are validating our train YOLO segmentation model
on this validation data.
Set images and let's see what mean average precision we get from this.
Okay.
So the mean average precision we got is 53.1% with 50 and mean average precision with 50 to 95 is 22.4%.
Okay, so let's see the model prediction on the validation batch.
So.
So these are the model predictions on the validation batch.
So I'm just displaying this image from here.
Let me show you which image I'm displaying.
Okay.
So just give me a minute.
Just let me just go to the.
Train folder from here.
Okay.
Where is my.
Okay, just.
Just give me a minute.
I'm saying this just.
Or in the training folder.
We have the results for the validation predictions, validation, batch predictions.
So these are the predictions on the validation batch.
So these images are not used for the training.
And so it's always better to have a look and see how our model performs on the validation dataset images
so we can see that the model is able to detect the pothole, do the segmentation as well.
So we have the detection bounding box and plus we are doing the segmentation as well.
We are creating a mask where we have the pothole.
Okay, so that's cool.
Okay.
Let me just I think this is the previous step printed skip results.
So let me just refresh it.
Just give me a minute.
Okay?
So just copy this from here.
Okay?
Let me just go to the.
Okay, just copy this from here and just paste this from here to here.
And let's see, what results do we get from here.
Okay, so this might take some time.
Okay, so these are the images you can see that we are able to detect the pothole.
We have done the segmentation of the pothole as well.
And this is the confidence score and the label that we have the pothole.
Okay.
So here is the confusion matrix.
So confusion matrix basically show that how our model handles different classes.
So so from this confusion matrix, we can see that 50% of our times, our model detected correctly that
there is a pothole, while 50% of the time when there is a pothole, our model was unable to detect
that there is a pothole.
Okay, so.
If you want to see that training and validation losses, the losses.
So just let me just copy path from here.
Okay.
And okay, so let me just copy this from here and let me show you training and validation loss.
So what training and validation losses.
So we will just plot the graph for the training and validation loss.
So just go to over here, just copy path from here and just paste this from here.
So this will now pretend the training and validation losses.
So let's see how our results look like.
So you can see that the loss is continuously decreasing.
So if you train our model on more than 120 epochs, we can say that the loss will further decrease,
while the mean average precision tends to increase.
So if we train our model or increase the images of the dataset like currently we are training the segmentation
on pothole dataset with only 96 images.
So if we increase the dataset up to 500 or 1000, so we will have the better mean average precision
and it will increase.
And if we train our model on higher epochs, the mean average precision will further improve.
Okay.
So in the results dot csv file, we have the model performance after each of the epochs.
Like you can see that we have the model mean average precision after each of the epoch mean average
precision results after each of the epoch.
So in the results dot csv file contains the training losses.
Validation losses mean average precision values after each of the epoch.
Okay, so here I will just download the demo video and see how our model gives us the results on a demo
video when we test it.
Okay.
So I'm just passing the best weights and as I'm doing the prediction, so I'm just passing the predict.py
file and I'm just passing the demo dot before the demo video in which I'm testing my train YOLO segmentation
model or fine tuned YOLO segmentation model on the potholes dataset.
Okay, so.
This might take some time to execute.
Okay, so the demo video is not very large, so I think it will divide the complete video into 324 frames.
And it is doing the it is processing each of the frame one by one.
So currently we can see that out of 324 to 24 frames are processed.
Okay.
So it's, uh, processing each of the frame one by one and in response, detect train four.
Our results are saved.
Okay, so the train four, our results are saved.
Okay, so just let's run this cell and see what results do we get.
Okay, so the output video will be displayed in front over here.
Then I will download this video and show you what results do we get from here.
So this might take few seconds more.
So the next step let the video be displayed in the Google CoLab notebook.
Then I will download this video from here and let me show you the result.
So let me download this video from here and let me just play this video and let me navigate my screen
towards this video.
So now you can see that our model train, your segmentation model, is able to detect successfully the
potholes here as well.
So the results are quite impressive.
So this is all from this video and audio.
See you all in the next video.
Till then, bye bye.