YOLO-NAS Custom Object Detection | Fall Detection Using YOLO-NAS

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone my name is arohi and welcome to my channel so guys in my today's video I'll talk about new object detection algorithm which is Yolo nuts YOLO Nas has developed by Desi Ai and this model surpassed the performance of all previous object detection algorithms like YOLO V8 YOLO V7 YOLO V6 and YOLO V5 this YOLO Nas um model is trained on pre-trained on famous datasets like Coco dataset objects 365 and then the roboflow 100 okay so in my today's class I'll show you first we will see how to use the pre-trained eulonas model to make the predictions and after that we will see how to work with the custom data set how to train your YOLO Nas model on a custom data set so that it can detect your custom objects okay so let's begin so guys we will start with this Jupiter notebook okay and guys first of all I have created a separate environment because I always recommend to work in a separate environment because what happens is if your python environment have multiple uh python projects running in it so sometimes what happened is um you know different projects may need different versions of same modules right so that can cause compatibility issue okay so it's always a good practice to use a separate environment so that's what I've done I have created a python environment and I'm using python 3.10 for it I have activated the environment and once I activated the environment I have installed this package super gradient package okay so this basically the super gradients is a pytorch Based training library and this package is required when you want to train or test or you want to run your YOLO Nas model you need this package okay and if you want to know more about this package then you can you know visit their GitHub repo I'll share I will share the link of that GitHub repo you can visit that repo and you can see more about it okay now let's go back to this Jupiter notebook so we have installed this package after that we are installing this package I am utils okay and then the third package is roboflow guys you need this roboflow package if you want to you know directly download the data sets from your code only right then and you want to use their data set in your code then only you need this robofo roboflow package okay so if you're using your custom data set suppose that data set you're not using the data set of roboflow and you have your custom data set then there is no need to install it but if you want to download the data set from roboflow website and then you want to work on it then you need this okay and after that we have this package Okay so these four things are required for yolunas once we done that let's check the version the torch version I'm using is 1.12.1 and it is compiled with Cuda I'm using 11.6 um Cuda toolkit okay and then over here I'm showing you the GPU on which I'm working so my GPU is G4 GeForce RTX 3090 and after that now let's uh load the model printing model and let's test our test that model so what we are doing is okay guys before that just see here this this and this these are the three different versions of this YOLO Nas underscore small means s means this is the smallest model underscore m means the media model and this L stands for large model okay so this smallest model this will work fast but you will get you know the accuracy will be less as compared to the medium model right because this data set is small okay and then in the case of medium and large model if you compare medium and large model large model will take time to process your data and show you the output but it will provide you more accuracy okay so it's always um you can always decide which model is best for you if you are looking for more speed and you can compromise on accuracy then you can go for smaller model but if accuracy is the concern then always choose the model with the large model and it will provide you a higher accuracy okay so in my today's tutorial I am using the large model so that's what we have done over here first of all we are importing the models from Super gradient trainings and then we are writing the name of the model which we want to use so underscore l means we have we want to use a large model and large model which was trained on Coco dataset okay so we have stored this in this variable okay so guys I have commented out this section this section is only required if you want to see the architecture in detail like what all layers are there then you can uncomment this section and then you can check it okay now the next thing is Let's uh provide the URL of our image and then see how what kind of predictions we get so this is the the URL in this variable we have provided the whole URL of the image and then over here this dot predict and then the URL we are providing and this is the confidence score you can change the value over here and you can you know play around you can change the value and you you can see what kind of outputs you get okay so this show will show you the output so we will we are using the predict method on this URL with this is the confidence score we have provided threshold value and then it is showing so you can see this is what we are getting okay so this is quite a good result now let's say if you want to test this YOLO Nason video then how will you do that so for that just to input video path in this variable provide the path of the video so my video is present in the current working directory so that's why I have written the name of the video only but if your video is at some different location then you have to provide the proper path over here okay and then the output video path so this will be the output video path means after you know plotting the bounding boxes on your video this YOLO Nas model will we want that yellow Nast model create the output video with the name of detections.np4 okay so that's what we are writing over here you can rename it you can give any name over here so over here we are performing the prediction yolona's large model to device devices Cuda okay so we if you're working on CPU you can change it accordingly dot predict in pit video we are providing the input video and then we are saying after making the prediction save it at this location with this name okay this name detections dot MP4 now let's see what I'll show you the input video first and then I'll show you the output video okay so let's see so this is the input video so and this is the output video so over here let me Zoom it so this is what we have as an output so you can see that the results are um pretty good right so let's just scroll it right guys so this is how it works on and my input video was this this was my input video so this is how it work on videos and if you want to use the web camera then you need to write this last thing is predict underscore webcam this function you have to call okay here we are saying that we if GPU is available we want to use that otherwise use CPU and we are loading the pre-train weights and then we are calling the predict uh webcam function okay this will open the webcam like this and you will see the output okay so guys this is how the pre-trained model work now let's see how to work with a custom data set okay so for that I have created a separate folder inside this folder I have done all the work which is related to custom data set so first thing is this is my data set folder fault detection so I have only one class in my data set which is fall detection so let's open it we have train test and validation folder train folder have images and labels now guys um one more thing this YOLO Nas model it accepts okay let me open this first YOLO Nas custom data set here so this yolonas model it you know it is compatible with pi torch data sets and data loaders okay so you if your data set is in Cocoa data set format then also it will accept Pascal format is accepted this format is accepted and YOLO V5 format is data loader function is also there so uh what is the benefit of these uh you know already data loaders are already there so what is the benefit of using that that you know we don't have to spend time to write those functions data loaders data loaders are already there you just need to uh call the right function and then you can work on it okay so in my today's class what I've done is I am um working on a data set which I have stored in the YOLO V7 or V8 or YOLO V5 format okay so what YOLO V5 or V7 or V8 format looks like we have a folder train folder inside that we have two folder images and labels inside images you will have all your training images and inside labels you will have all the um corresponding annotations files so if you have 100 images in your image folder then you should have 100 corresponding annotation files which should be in a text format in your label folder and let's open one file and see what kind of file we have so when you open it you can see this is the class ID and these are the bounding box coordinates okay so this is the this is how YOLO V5 format or V8 format looks like so in my today's class I'm using this format and my data set have one class which is Fault detected okay so in the same way you can see the valve folder inside images we will have all the images and inside labels you can see the corresponding labels okay so this is my data set after that only thing is this is the code this is our code and let's see this code first okay so this part I have already told you right so torch version and Cuda version is this now let's fine tune YOLO Nas model to work with our custom data set so guys uh it is always recommended to fine tune the model means use the pre-trained model then you fine tune that pre-trained model with your custom data set to get good results okay instead of creating your object detection model from scratch it's always a best practice to take a pre-trained model and then fine tune that pretend model with your custom data sets so that's what we are doing today okay so whenever you want to train your custom data set using YOLO Nas then you need a trainer okay so over here you can see a trainer we are importing a trainer from Super gradients.training okay so imported that trainer so then here so over here checkpoint directory and this is the folder name okay so what we are doing here is this checkpoint simply means over here I want to store the trained weights and all the files and the logs which are related to the training process I want to store all those things in this checkpoints folder okay so that's what we have written this is a folder name in which I want to store that so trainer experiment name and then this so guys this is the another folder name so so inside checkpoint folder name we want to have this folder name inside this folder we want to stay store all the output okay let me show you this checkpoints and inside checkpoint we have this okay let me show you this so this is my checkpoints folder inside that I have the another folder which I've just told you and inside that you can see we have all our models this best DOT best and latest and average okay so these are the different kind of model best model means we have trained the model for suppose 100 epochs and whatever the best model is you will get that in this checkpoint underscore best DOT PT model OKAY latest means the last one model average model will give you average model okay so you can use any of these three models for making the direction so I'm using obviously I'll use the best uh dot PT model okay so uh this part is clear so we are calling the trainer and then you have to provide the path of the checkpoint folder where you want to store the training related files okay and then this data data set and data loader this part I have already told you that this um super gradient supports the all kind of data loaders so if your data set is in any of these formats so you can just you can simply uh you know load that data set using the existing data set loader and it will save your time okay so that's what I'm doing I am importing the data loaders first and these are the detection YOLO format pal right so what we are loading my data set is in uh YOLO format right YOLO V5 format so that's why I am loading those data loaders which are related to you know which will help my data set to get load on this okay and then these are the important parameters which you are providing data underscore directory so this is my folder name where my data set is so let's see again fall detection so this is the fall detection is the folder name in which I have my train test and validation folder so that's what I've written train images folder where our training images are in Fall detection folder we have a train folder inside that we have our images folder inside images folder we have related images trained images okay so after that in the same way we are providing the uh where our labels are where our validation data is where our test data is and the classes in our my case we have only one class fault detected so let's suppose if you have multiple classes then you will just write comma and then the second class name and then the comma and then the third class name this is how you'll write the class names okay so in my class I have only one class so I have written like this so here train data and then this well data and then this test data so these are the three data loaders train underscore data have uh we are loading the training data here we are loading the validation data and here we are loading the test data so it's simple right data directory in images directory what we are giving to image images directory train image directory where is the train image directory see here okay so this is how we are using our training labels are present at this location and we have stored it in over here so we are writing like that okay so this is what we have done so now we we have initiated that uh trainer we have you we have used the data loader to load the data now these things these few steps are like if you want to perform augmentations on your data so you can perform these steps okay over here you can see I'm performing the augmentation right here you can you know plot you can see some of the examples over here you can see okay and after augmentation this is how your data set look like and then scroll down over here here we are see model dot get we are calling the pre-train model right num classes length of our classes the custom classes so that's what we are calling here like this pre-trained weights are Coco so we want to use the large model which was trained on Coco data set and these are the classes of our custom data set okay so we have defined all that and we have stored it in a model variable now these are the few parameters which you can fine tune or you can play around these you know with these parameters to see how these parameters uh you know affect your uh training or results right so they have mentioned that these few things maximum epochs you can choose okay so maximum epox loss Optimizer these kinds of things you can fine tune your model over here so you can see the Maxi box I have trained the model for 100 epochs okay and then Optimizer is Adam Optimizer we are using right now but you can use in other optimizers also so all that detail they have provided over here you can see that optimizers you can use all these optimizers you can visit the super gradient uh you know GitHub repo I have given the link in description section and you can know you know more about it you can um understand these Concepts more and you can fine tune the parameters according to that and and as and you can you know see how that affects your training okay so these are the parameters we have provided and I am training for 100 epochs but guys I have stopped the process in between only so now let's train our model so these few lines will train your model trainer dot train so remember we have created this trainer above so from that trainer we are training and we are providing the model over here we are providing the training train parameters training data and validation data these are the loader this will load the training data this will load the validation data so train data and Val data remember we have defined above here train data and valid data okay these are the data loaders so they are loading the data we are loading the train and validation data and we've called the model so and we are training it so once you run this cell after this cell you will get this checkpoint folder this checkpoint folder will get created itself once you start the training and it will then have this folder and inside this folder slowly slowly how you know training will go on and you will get all these files and models after some time okay so this is how you can train your model so right okay where is it training now once we have the training done so I have explained you that best model is with this name and this will be the last Model okay and now you can decide which model you want to use and this is how you call your model so I am calling this this parameter you have to provide and over here we are providing the path of our custom trained model okay and we have stored it in best model variable now we'll call this variable in our next cells and we'll make the you know predictions okay so if you want to evaluate your model this is how you evaluate your model okay you can see the result over here so guys again I have trained it for very less epochs okay so the results are not so good for that now let's make predictions with the best model so my image is this test t1.jpg let's see this image first T1 okay this is the image on this image I want to make the predictions so let's do that image and we have saved the breast model in this variable right dot predict and on this image I want to predict and then I want to show it so you can see the result over here fall detected with this much of uh confidence okay now if you want to work on a video so how how we can work on it so give the this is my input video and I want to store the output video with the detections with this name and here best model then dot predict on this video I want to make uh you know want to perform the predictions and I want to save the output video at this path so let's see input video first Fallen dot MP4 let's see this first so this is our input video okay so now let's see our output video detections so this is the output video and as we have one class uh fall detected so we are getting results like this so guys this is how you use um YOLO Nas model and I am blink is given in the description section you can get this Jupiter notebook from there and I'm also sharing the GitHub Repco of there's no official GitHub repo of this YOLO Nas and super gradients you can visit there and you can know more about this algorithm so guys if you like my video please subscribe my channel like and share also thank you for watching
Info
Channel: Code With Aarohi
Views: 20,201
Rating: undefined out of 5
Keywords: yolo-nas, computervision
Id: pgf9bPuEsFo
Channel Id: undefined
Length: 23min 24sec (1404 seconds)
Published: Fri May 05 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.