Hi guys.
So now I will train my Yolo v eight model on the pen and box dataset which I have created in the previous
lecture.
You can see over here.
So I will just export this dataset into my Google CoLab notebook by just copying this and pasting this
into my Google CoLab notebook, I will be able to export my dataset from Roboflow into my Google CoLab
notebook.
So first of all, before we export the dataset from Roboflow into my Google CoLab notebook, we first
need to have we need to install YOLO v eight so YOLO V8 can be implemented in two ways by installing
the package Ultralytics or by cloning the YOLO V8 GitHub repo by.
So YOLO V8 is the first version of the YOLO to have its own official package, so we will demand YOLO
V8 by using PIP install ultralytics by installing the package by cloning.
The GitHub repo is a bit lengthy process, so I will follow the easy way which is PIP install ultralytics
to install yolo v8 and implement it.
So first of all, I will set my home directory as this path and setting my current directory.
And now I will install Android ethics package to implement YOLO V8 so it will install all the required
libraries as well.
So now we will check whether Ultralytics is imported and it's working fine or not.
Okay.
So until it is imported and it's working fine, so now I'm creating a folder over here by the name dataset,
so I've already created it.
So it's appearing cannot create directory because it's already exists.
You can see over here.
Okay, so I'm just checking what is my present working directory.
So now I am setting my present working directory as this dataset so I can import my dataset from roboflow
into this colab notebook datasets folder.
Okay.
So I will just copy this all from here and just paste it over here.
Just remove this and paste it and run this.
So now all data set will be downloaded from roboflow into my Google CoLab notebook into this datasets
folder.
So it might take some few minutes or few seconds.
So the data stood for the dataset to get downloaded.
Okay.
What's the issue?
Let me see.
Okay.
I think then we can copy it completely.
So just click on export over here, show download and see.
Okay, so now it will be downloaded.
There.
But if you face this error as well, just remove this and just run this.
So now we will be able to export our dataset from Roboflow into our Google CoLab notebook.
So if you ever face this issue, just go here and click on.
Export again and just copy this one as well.
So this error will be fixed.
Okay, so now our dataset is being downloaded and it's completely downloaded.
You can see that 100% downloaded and it's available in the datasets folder.
You can see pan book detection and train test validation.
And this is the data dot yml file.
You can see that we have two classes Pan book and this is the train test validation path.
Okay, so let's see, what is our dataset location?
So we need to make few changes over here.
Let me tell you, just rename this folder and just remove one because it because if there is any numeric
number, dash one.
So our model is unable to assess the dataset path.
Now just go to read data, dot HTML and just go to train and just copy this path.
And just paste it over here.
Similarly, will go over here as well and write test over here.
Okay, so I'm just setting the path for that train test and validation and write validate over here.
Okay.
So just save it.
And now just rerun that training cell and book detection.
Just rename this folder.
Copy and just.
Rename this folder and let's train our model on 70 epochs with image size, which we have set in.
The robot was 640, so we will have the same image size and pen book detection data dot yaml file.
Okay.
Looks good.
So just run this.
So if there is an issue we will definitely fix it.
So it might take some time.
So let's see if this is working fine or if there is an issue.
So we can fix it.
So the training is about to start.
So this training process will have an idea.
It will take around one hour, 15 minutes or 2 hours.
So I will stop the video over here as the training begins and as the training completes, I will be
back.
Then I will explain you the whole training process and how we can validate our model and validation
prediction batches, results and how to test our model on the test images.
Plus we will also see how we can test this model on the webcam as well.
So the training has started, but it will take some time.
So as it completes, I will be back.
So see you as the training complete.
Guys the training has completed.
So it took around 39 minutes for the training to complete.
We have trained our model on 70 epochs and we have the last epoch weights while on the 70th epoch and
the best weights while on which our model gives us the best performance or results.
Okay, so here is the model summary.
Or you can say that the overall performance analysis of the model.
So we have got a mean average precision with IOU 50 as on book is 0.295, which is 29.5%.
On the pen, it is 0.157, which is 15.7%.
While the mean average precision when IOU varies from 50 to 95 is with on book is 60.16 8%, which is
16.8%.
And with pen it is 0.0623, which is a bit low, like it's around 6%.
Okay, so let's see, what are the files?
Do we get in the training folder?
So we have the confusion matrix, we have the F1 curve, we have the precision recall curve and we have
the results dot CSV file, which gives us the performance metrics and the performance analysis or metrics
of the model After every epoch.
The result DOT PNG contains the training and validation losses, while the training batch zero gives
us the model prediction on the training batch.
While the validation batch prediction give us the model predictions on the validation pads.
So let us display the confusion matrix and in the weights folder we have the best and large weights
file.
So let us first display the confusion matrix and see what do we get.
So Confusion Matrix is basically a chart that shows how our model handles different classes.
So like you can see that 33% of the times our model detected correctly that there is a book, while
67%, 66% of the times when there is a book, our model was not able to detect that there is a book.
So our model detected nothing 66% of the time while there was a book.
So only 33% of the times our model detected correctly that there is a book.
Why?
11% of the times our model detected correctly that there is a pan one 1% of the time there was a pan.
But our model detected that this is a book, while 88% of the times when there is a pan, our model
was unable to detect anything.
So here we have the training and validation process so you can see that the loss is decreasing a bit.
So if we train our model on a more number of epochs, like 200, 300, we will can see that the we have
the loss will be decreasing and our accuracy will be improving.
Like you can see that mean average precision is increasing like you can see over here and you can see
over here as well, like mean average precision is increasing plus.
Here we can see the model prediction on the validation batch.
So these images are not used for the training, so it's always better to take a look.
Our model is performing on the validation batches, so now we are validating our custom model on the
test dataset.
So the test dataset is not used in the training, so we can validate our model on the custom test dataset.
So here we have validated our model on the test dataset.
So just one thing we have changed in the training process.
We choose mode as train while in the validation, we choose mode as validation and validation.
So here is the other zones of the model.
When we test our model on on the test dataset images, we date our model on the test data set images.
So here we have a mean average precision of 0.29 5.9% .9. 5% of the book and mean average precision
of with 50 port pen is 15.7%.
So here we are testing our model on the test dataset images.
So let's see what results do we get over here.
So here model is unable to predict anything here.
The model has predicted correctly that there is a pen while here.
Our model has also predicted correctly that there is a pen here.
Also, our model predicts correctly that they are walking the shelves and here also on model is predicting
that there are book in the shelves.
So I will download this model weights at best speed and we will test our model on the live webcam as
well.
So test let's test our model on the live webcam and see what results do we get over there.