In this video tutorial, we will look at how we can fine tune the YOLO 11 classification model on a
custom data set.
We will fine tune the YOLO 11 image classification model for plants classification.
So here you can see we have the data set available on Roboflow.
If I just go to the overview over here we have this plant classification data set.
And it contains around 3800 images.
We can see over here the data set consists of 3764 images.
You can download this project by clicking over here.
But uh to access this dataset you need to, uh, login on roboflow.
With your account.
You can easily create your account on roboflow, with your GitHub account, with your Gmail ID, or
with any other work email as well.
So you can see over here we have, uh, 3764 images available in our data set.
And we have a lot of different classes of plants available over here like Tulip Time and, uh, Ruby
and melon.
Nana's like, there are different classes available over here.
And, uh, we have three versions of data set available over here.
Uh, originally, our data set consists of 3764 images as seen over here as well.
Uh, but, uh, the author of this data set, I'm not the author of this data set.
The author of this data set applied the augmentation.
So now you can see that, uh, clockwise rotation, counter clockwise rotation augmentation and, uh,
nose up to 0.5 pixels.
Uh, uh, augmentation, like three augmentation steps are being applied over here.
And in the pre-processing we have resize the image to the size 6.40 x 640.
So remember that augmentation is always applied to the training data.
Augmentation is not applied on the validation data or test data set.
So we only always apply augmentation on that training data.
So we have 3764 images.
and after applying augmentation.
Our training data size increased to 7905 images.
We have 753 images in our validation data set, and we have 376 images in our test dataset.
In ideal scenario, in computer vision projects, we usually take 70% of the images in the training
data, 20% of the images in the validation data, and 10% of the images in the test data set.
Okay, so we have the three versions of our data set available over here.
We will be using the third version, but we have the other versions available over here as well.
Okay.
So and if you just go to analytics you can see over here if your classes are balanced or not.
So if you see a red line over here this means that that class is not balanced.
So we have seen all the green lines.
So means this means that all our classes are balanced okay.
So like you can see over here we have balanced classes.
We have are originally 3764 images in our training data, in our complete data set.
So we have total 3764 images in our complete data set.
The complete data set consists of training, validation and test data sets over here.
And we have 88% of the images like after applying augmentation on the training data.
Our training data set size increased to 7905.
And we have validation in 783 images in the validation.
And we have 376 images in the test data set.
As I told you, always remember that we applied augmentation only on that training data.
So in order to, uh, export this data set from Roboflow into our Google Colab notebook, you can click
on download and you can just like down folder structure or open a paper version and you can just click
on show download code from here.
Okay I'm just making a mistake.
We need to uh, select folder structure from here you can just click on show download code from here,
and you can just copy this from here.
And uh, and just copy this from here and you will just add this over here.
Okay.
So here you can see we have the complete Google Colab notebook.
I have written down all the code over here.
Uh, before running this script, please make sure that you have selected runtime for GPU.
And first we will install that package.
Then we will import all the required libraries.
So YOLO 11 is available under Ultralytics package.
Okay.
Then you can uh, previously while using Yolov7 Yolov6 Yolov5, you will need to clone the complete
data repository of that model.
But um, uh, YOLO 11 and Yolo V8 are available under that package.
So this makes it quite easy that we just install the package Ultralytics, and then we can access any
of that model as well.
So we will be using the YOLO 11 model through a Python script.
You can also run YOLO 11 model in a command line interface as well.
Okay, so you have both options.
Okay.
So we have installed the analytics package.
And let's see if I can run this version over here.
So we have the Ultralytics 8.3.1 version.
And we have Python version of 3.1.
We have the Cuda available Tesla T4 GPU and like 15 GB we have the Vram available and we have two CPUs
available over here.
And we have like uh, out of 112 GB disk space over 36 86.6 GB is being occupied currently.
So now I will just download this data set from Roboflow into this over here.
So this will take few seconds okay.
Now it's extracting the dataset and like it's 100% done.
Okay, so we can just hide the output.
So here you can see we have the plant classification data set.
We have the train test validation folder over here.
Okay.
For each of the class okay.
Okay.
So that's not good.
Okay.
So here's the link of the data set over here.
Okay.
So you can just check all the details.
And now I will just download the your 11 classification model.
So your 11 comes with five different models for the 11 small.
Your 11 uh your 11 nano your 11 small your 11 medium your 11 large.
Your 11 extra large.
Okay.
So your 11 nano is now or stress but it is less accurate.
But your 11 extra large is the most accurate.
But it takes more inference time as compared to other other 11 models.
So I'm using the other 11 small model or sorry I'm just mistakenly run this cell again.
Okay, so I'm using YOLO 11 Small classification model over here.
If you want to get more better accuracy, you can use larger models as well.
Okay.
So you can see we have downloaded the model.
Okay.
So I have already done that training okay.
So I will not do that training again because this takes very much time.
Like you can see over here uh, for each epoch like it takes around one minute 22 seconds okay.
So if you are training for 60 epochs, this will take around, uh, 90 minutes at least.
Okay, so we have around 797,905 images.
In the training data, we have 376 images, uh, in the test data set.
And.
Okay.
And in the validation data, uh, I, uh, it's none, but I don't know why it's getting none.
So we have around 27 classes over here.
We have a batch size of 16 over here.
Okay.
So over here, like you can see that we have 1905 images in the training data.
So if we are passing our data in 16 batches okay.
So if we just open the calculator over here.
And 7095 divided by 16.
So we have around 494 okay.
So we will be passing data in 16 batches.
So like 494 or 495 are almost equal.
So in each batch we will be passing 495 images to our model for the training.
Okay.
So over here you can see I have just fine tune that in classification model on this image data set for
60 epochs.
Okay.
So we have just fine tune the YOLO 11 classification model uh to detect uh to classify plants.
Uh, and we have finally on the YOLO 11 image classification model on this plant classification data
set for 60 epochs.
Okay, so I'm not run the training again.
And you can see we are just getting a good accuracy score of 97.1%.
Uh, where is the lake?
Okay.
So I think, uh, there is an issue with the link.
I just need to add the link over here.
Uh, so I already saved the model weights into the drive, and we are directly downloading the model
weights from the drive into this Google Colab notebook.
So if I just click this link.
Okay.
But I don't need to download the model from here.
So one thing I can do is I will just add the link over here.
So I have uh, so I have added the link over here and you can see that I am if you just run this cell
I'm downloading the best model weights, uh, from my drive into this Google Colab notebook.
Okay.
So here you can see the best model weights.
And here are my training results.
So after you run that perform the training you have this confusion matrix.
So confusion matrix basically tells us how our model handles different classes.
So over here if you just see that uh for this by ARM class, 11% or 11 times our model detected correctly
that this is my arm by one time when there is a my arm, our model detected it as can be.
Okay.
Similarly, uh, uh, 11 times our model detected correctly that this is a manga.
And uh, 2% of the time there is a manga.
Our model detected that as papaya.
Okay.
And, um, for the others, like you can see, 27% of the time our model is correctly that is the shampoo.
And if our model detected correctly every time, like there is no misclassification over here.
So over here you can see that 92% of the time our model correctly predicted that this is an arm.
And it's not a time our model misclassified.
It as uh.
Goodbye.
So this is a normalized confusion matrix.
And similarly we have other classes like 70% 300 time or more correctly, that is the manga.
And 30% of time when there is some manga.
Our model detected as papaya, and 7% of the time when there is a manga or model detected as zero.
Okay.
So, uh, this is a similar thing.
Okay, so these are the model predictions on the validation batch as I'm not training the model on the
validation data set.
Uh, images.
So it's always better to take a look and see how our model performs on the validation data set images.
And you can see that, um, the results look quite promising.
Like our model makes some correct predictions as well.
Okay.
So like you can see okay.
So here are the training results over here.
Okay, that is my mistake.
Uh, okay.
So I'm just, uh, just like me.
So now here you can see our training and validation loss results.
Previously, I just mistakenly run this cell because I have not run this training in this session.
So I will not have this folder.
When you run this training, you have the runs folder appearing over here and there.
You can just draw this results.
So I have already run training before recording this tutorial.
So over here you can see we have the training.
The loss is continuously decreasing.
Validation loss is continuously increasing.
Our accuracy is increasing continuously.
So if we run train model training on high number of epochs, uh, we can expect that model accuracy
will further improve.
Okay.
Um, so we can download the best model weights from here as well.
So if you just run this cell, uh, the best model weights will be downloaded.
Okay, so now you can see the best model weights are being downloaded over here.
So here we can see the best.
So here we can see the best model weights appearing over here.
Okay.
So uh let's see.
So now I will just load the train classification model over here.
And I will just specify the test loaded part.
So now we will test our fine tuned model on this test dataset images.
We will test the performance of our fine tuned to the 11 image classification model on this test dataset.
Images which we have over here.
Okay so I will just specify the test folder path.
So now I will just go through each class folder in this directory over here.
Okay.
So we you can see we have different uh tests uh class folders in this test directory over here.
You can just check all these.
Okay.
so now we will predict, uh, on each image in the class folder.
So now we will do the prediction on each of these images in this class folders.
And uh then you will see what results we get.
And let's run this cell.
So here you can see I've just added all the code.
So we are just looping through each uh, folder in this test directory.
And we are just testing the model performance then.
And let's see what score we get.
Either we are making great predictions or not.
So here you can see we have the results okay.
So we have the uh so now we are looping through each of that uh folder in this test directory.
And we are doing the what we are making model predictions on each of these images that we have in these
folders over here.
Okay.
And over here you can see if we have the ground truth by arm like you can see over here.
Our predicted class is also Bam, and we have a confidence score of 1.00, which means 100%.
So you can see we have multiple images inside each of this folder.
Similarly, if our ground truth is jumbo, we our predicted class is also jumbo and we have a confidence
score of 1.00%.
And if we go below similarly our class is ground.
Truth is our predicted class and our confidence score is 100% as well.
Okay, but in some cases the confidence score might decrease as well.
So let's see if there is a scenario where we are getting a low confidence score.
Okay.
So you can see for our for the ground truth our our predicted class is lower as well.
But the confidence score has decreased to 50%.
Like the model is 50% confident that this is lower and our ground truth is lower.
Our predicted class is lower, but the model is 70% confident that this is smaller.
So there can be some wrong, uh, false positive or wrong predictions as well.
So over here, like you can see that we have tested on model performance on all this test data set images.
You can also test the model performance on some random image or an image as well.
And you can see how well your model performs.
Okay.
So basically we are going to loop through each of the folders we have with the test factory.
And we are making model predictions on each of these images.
And then we are saying that if our predicted class matches with the ground truth and what confidence
score we are getting.
So in this tutorial, we have learned how we can fine tune the YOLO 11 classification model for plants
classification.
And we have fine tune.
The YOLO 11 model on this plant classification data set are available on Roboflow.
You can also fine tune your 11 image classification model on any other data set on your custom data
set as well, and you can test the model performance on, um, other random images as well.
So that's all from this tutorial.
Thank you for watching.