YOLOv8 Model Training and Deployment for Object Detection with Real-time Webcam

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys and welcome to a new video in this video here we're going to do custom update detection with the YOLO V8 model so this model was just released a couple of days ago we're going to train it on our own custom data set we're going to use roboflow we're going to actually like have a data set uh which we're labeled with bounding boxes around our Optics we're going to detect different mocks in our images then we basically jump into Google collab I'll show you how you can actually train your own custom URL V8 model it is actually like fairly easy to do I'll show the whole process I'll show you how to export it and how we can actually like Import in our own python script and then inside of our python script we're going to run real-time inference with our own custom trained YOLO V8 model so we're going to jump straight into Google app I'm going to show you the block of code that you need to run to act like run and train this YOLO V8 model we're going to do validation on the model and then I'm going to show you how we can actually export it we're just going to download the model that we're trained here in Google lab and then we're basically just going to export the model I'm going to show you how we can load it into our own python script so you guys can play around with it and you can actually use it in your own projects and applications so first of all here I've just connected the runtime to the GPU first of all we'll just verify that we actually have access to the GPU for the training because this will just speed up our process a lot then we need to PIV install Ultra Linux here which will basically like be installation of YOLO V8 so inside this autolytics we have the yellow V8 model if you're not familiar with the lv8 model I have another video where actually just went over the GitHub repository I showed you how you can do live inference on a pre-trained Model but here we can see that we have now installed the YOLO V8 model and now we are actually ready to use it so here we can just import the different kind of modules from other lytics we're going to import YOLO we're going to import OS and some display here so we can actually display our predictions with our model here we're just going to run this block of code and now we should actually have all the modules imported that we need so the new yellow V8 model here from autolytic is act like setup uh really really nicely because we just have this kind of like YOLO format we just have like this whole Coast structure where we have the YOLO files and basically you just run these YOLO commands here into the Python scripts you can pass in different kind of like arguments to it methods and modes and so on so now we can actually adjust first of all before react like we're in the trainer model we'll just see how to do interference on a single example with a pre-trained dual V8 model so basically we're not just have this YOLO command here now from the YOLO you'll V8 repository from autolytics that were just PIV installed then we can just set the task here equal to detect so then we would like like do update detection we can also do instant segmentation and classification with the yellow weight model I'm going to create another video where we're going to train our own custom instance segmentation model as well and then we're going to use it in our own python script so then basically we just did the mode here equal to predict we have the model equal to the YOLO V8 Nano model we can also choose a small model medium model large model and so on we can set up a confidence score here so we basically just filter out like um predictions with a low confidence score we can also like increase this and then we just set the source here equal to the image that we actually want to make a prediction on you can also do like for example a webcam here if you just specify zero but then you will have to have it in your own environment on on your local computer but basically here we're just going to run it to see a single example and then we will train our own yellow model on our own custom data set so that'll be way more exciting than just sharing this example but here I'm just going to show you how we can do appearance on a single example with a pre-trained YOLO V8 model then the results you are saved it runs um slash detect slash predict and then we can basically just go in uh specify the file name here for that and show it as an image here in Google collab here we see the predictions we get a talk we get a person we just acts like a really low confidence score for the talk and it also like extends the boundary box all the way to the bottom we also have to take the car in the background so again we get some really nice predictions we can like here again we're using the Nano model we can also use like the larger models and and so on and we'll get way higher accuracy and confidence in our predictions so I was not trained the yellow V8 model on a custom data set first of all here I'll go inside my roboflow account you can basically just go in here as well take one of my data sets or you can go to the universe where you can basically like find all the public data sets when we're doing object detection you can just press like optic section here and then you will get all the different kind of like update sections uh projects that is available here publicly in the roboflow universe uh you can basically just go ahead and take one of them export data set as I'm going to do now but then basically we just go inside our roboflow project in this example we are doing cup detection and I have this version two then we can basically just go in here hit export inside of our projects we have the yellow V8 format show downloadable code and then we hit continue it will then zip our folder and we can basically just take this code copy it and paste it into our Google collab and then we can specify the path to that to that folder inside of our notebook so if we just go back here again to our training of the yellow V8 model we can then just specify copy paste in the data set then when we actually want to do detections I'm just going to run these blocks of code so here we download the data set it will unsub it and we will get it over here to the left in our directory we can also then run the detection mode here we can run train so we hit we want to do optic detection we can set the mode equal to train we just specified a model that we want to train as well so here we can actually just try with this with the media model and then for data set we basically just have our data set variable from roboflow so this will be our data set variable up here we can specify the location for that and over here to the left we can now see that I have my data set so we have computation version 2.3 we have a test set of train set and a validation set so this is basically old images and also the labels for our Optics that we want to train our custom ylv8 model for so again we just specified the data set location number of epochs we want to train it for and also our image size then when we want to train our model we just run this block of code again this notebook here will be a weightable on GitHub there's a link down description so basically just go check that out copy paste it run it on your own custom data set export the model and then use it in your own applications and projects so this is actually really easy it's really cool that we can set it up so quickly run object detection models and and even like just train these models here data sets you can just label your data set with roleflow export them and use it in your own projects so here we're just going to run word for for the epochs first of all we get a summary of our model we have a bunch of convolutional layers um concatenation layers we do some up sampling and so on we need Optimizer so we're using SGD with a learning rate of 0.01 we can also see some um data augmentations here we can see the validation set and then we will basically get the training down here at the bottom so here we can see that we have Epoch one of 30. uh we see we get a box loss class loss and some instances so how many instances are we actually detecting we also we will also get some some information about the mean average position of 50 and also mean average position 50 to 95 in intervals of five so this is the most important like uh like metrics to look at I mean you have positions so we basically just we can basically just see here that our minerals position is acts like increasing for uh for each Epoch that we're training and again we're using the medium yellow V8 model so now we will just let it run for the epochs we'll go back in show some results and how to act like export this model and also do validation of it so now model is done training for 30 epochs we can basically just see the results here at the end we get some really uh really nice results uh if you just go to epoch30 out of 30 we have it up here we can see that we get really high um we have we get really high mean average station 50 and also really high mean average position 52.95 we get around like an average position of 0.87 and over here to the right we also get my point 58 here 40 million hours position of 5 to 95 if we just compare this with the Benchmark of the yolav8 model on the cargo data set they get around like Point 44 45 in this metric here so these are some really nice results we can also just see down for all the classes that we're trying to detect in our object detector we get some really nice results with really high precision the the results are saved in runs detect uh train so we can basically just go inside that so this is the the file directory for that so we have the content run detect train and then we're here we're just going to show the confusion Matrix so in the confusion Matrix we will have our um we will have our true labels down at the Y X axis and then we have to predicted labels on the y-axis we can see that we get some really nice detections for that we have some problems with this cup with the with the lowercase C because this is a like some kind of like redundant class there there's like there's only like a couple of samples in that so it's really underrepresented in our data set we can also go in and see that inside of our roboflow data set so if you just go down to the health check we can see that this cup here only has like 10 and like nine nine samples so this is an error in the data set you will go in and correct for that and also just a standard cup here with the upper KC um we only have 42 samples so this is under represented um this is an underrepresented class in our data set but this is actually a really good confusion Matrix we can see the rest of the classes it is really confident about that and then we can basically just show uh the training results as well so here we should be able to see the training graphs you can also get all these files in if you're inside the runs detect and then we have our train and then you'll basically see all both the the F1 Precision recall curve the confusion Matrix and then the results that we're sharing right now so we'll have that inside your train folder so we'll just close this one here and then we can see that the Box loss is still decreasing and hasn't really converged yet we get a really nice decline in our parked lot and also the class laws we can see the Precision it is really stable up here we'll get the mean air position it is kind of like converts here around like 80 83 uh here for the for the other metric for the mineral position of 50 to 95 we can still we can see that our average position is act like still increasing so we could train for more epochs and get actually we can get better results but we already have some really nice results so we're just going to go with that here we're going to run into the validation mode so we basically just set the mode equal to validation and now we just specify the weights that we want to do validation off so this will be our train weights and then the best so these are also the ways that we're going to export I can just do that right now and again we just specified the path to our data set so if we go to the folder to the left we can then see under our train we have the this weight file we can get the best best weights here so the best results for the metrics uh while we have been training our neural network or our yellow V8 model so if you're going to train it for like 100 epochs and at some point like around like 50 epochs it doesn't really learn more or it it starts to increase in loss and decrease in performance again you can just go in here and take the best model throughout the whole training process if you just want to get the last Model you can also take that but here we're going to go with the best model you just right click and hit download then it will download your computer and then we can import that into our own python file and run it with the new like yolavi yolv8 architecture in our own custom python file and we will actually be able to run it in real time as you're going to see in just a second so here we will just download this model to our computer we can go inside and just run the validation mode again I'm just going to run this block of code for the object detection and here it's basically just passing all the images through our validation or like through a model for a validation and then we should get some outputs down here at the bottom so again we get some really nice precision mean air positions on our on our classes for our validation so after we're validated our model we can now set it to prediction mode and then we basically just do predictions on images that has not been trained or validated on we set the task equal to detect and the mode we set that equal to protect now we basically just again we specified the path to the best weight and then also the data set location for our test images and we also set up a confidence score a threshold so here we're just going to run this code code with this YOLO command and then after that we can just go down have a follow running through a bunch of images and show the results to ours so here the results are saved in runs detect on slash predict 2. if you want to get these images again you can go inside the folder you can inside runs detect and then predict two and then we will get all the images here you can download them or just show them directly in the tab if you double tap but here we're just going to show it with code we're just going to show free examples and then we can basically just run this block of code so now we can see the results we get a really nice prediction of the white cup here even though it is seen from above another example here is the Kaka cup uh cop the standard cup with a really high confidence score we have the hand-painted cup uh Halloween Cup and the white cup uh if I just scroll a bit up here let's try a couple of more examples so let's go with five and it will basically just run the predictions and specialize the results so again you can just see that these results here are really nice we have the stand of a cup we have the a cup white cup hand painted cup and Halloween cup and all of them has had like really high confidence score so now when our model is actually exported we can go inside our own python script then we can actually go in and do live inference with a webcam we'll just open up a webcam do live inference on this custom off detection data set and then we're going to see some really nice real-time results so we're not jumping into Visual Studio I'm going to show you how we can actually run this live inference I basically just export the model I downloaded and just specify the path here to to the model and I just renamed it to cup detector here with this yellow from ultrolytics import yellow we're basically just going to to specify the path to our model and then it will load in it will load in the model and we can call this predict method on it afterwards we can specify the source you can either have like a video image we have folder with images or we can specify this zero and it will then use the webcam which is it show equal to true so this function basically just takes in all like the command the command arguments that we did in Google call lab as well so we have to predict we specify the source to show we want to visualize the results that we're doing on our live webcam and we can also specify the confidence score so if our confidence score for the predictions are is greater than like 0.5 then we will visualize the predictions and if they're lower than this threshold we'll just discard the detections so this is basically everything you need to do in another video I'm going to show you how we can actually modify um this like this dataction predict the class up here at the top and how we can export export the results ourself using our own applications and all those different things so definitely hit make sure to hit subscribe button and notification under the video so you can notify it when I upload and now another video where we actually see how we can modify this code for our own applications and projects I'm also going to create a video where we have a Tracker Where we basically track these Optics uh that we're that we're detecting in our image but here basically we just run this predict mode predict function on the model and now I'm going to run the program and then we can just see the results so this should be able to run in real time I have an Nvidia RTX 4090 car we can see all the parameters here we can see the the inference time so here we have around like five five milliseconds that in my five milliseconds so that's around like 200 Hertz so this actually runs on 200 with 200 frames per second and again this was the medium model that we trained so you can see the predictions we just have the webcam up here running sometimes it gets some false predictions it takes this as a cop but with a really low confidence score I'll just take the webcam down here and then I'll grab a bunch of cops or mocks and then let's see if we can actually do a live inference on the x-like Optics that we have trained the models on so here if I just turn the webcam around we should be able to detect these mucks so here we can see we have to hand paint a cup we have the Halloween cup and we also have the Cocker cup we can see here we have the wine cup and we should be able to take the standard cover as well this was underrepresented in our data set sometimes it loses track maybe we should try to take it a bit further out so it's not really that happy about this um this standard cup just try to move it a bit over here to the left so here we detected as the as the standard cup but with a really low confidence score yeah so so all these other cups here are really nice we can see that we can run in real time we had around like five milliseconds so this is 200 frames per second uh I have a a 14 490 RTX and from Nvidia so this is actually like a really uh crazy graphics card but you can run this on like um just standard gpus and you can even run running like CPUs you can have different Frameworks to export uh your models you'll be a also supports that these are just some really nice results I just take this cob up and try to like play around with it and we should be able to still get some some detection so we see we have this cargo cop detection let's see if we can get it from it above can really take it here so yeah we take the yellow collar here's the Cocker crop it is really hard to see that this acts like a Cocker cup just from above here um but when we move it around it is able to actually detect this as a cargo cup again really crazy model like these models here are so fast you just saw how fast it was to actually like go in train it in Google lab export the model and then just throw it into in here to your own python script and then you can play around with it so this is actually like a really cool model it can be used for a lot of different kind of things I hope you guys are going to create some really nice projects on your own custom data sets definitely throw down in the comment section if you have some nice ideas of what we should try to do with these only 8 models and also if you get some really nice results so thank you guys for watching this video here and again remember to subscribe button and Bell notification under the video also like this video here if you like the content and you want more in future it will help me and your channel out in a massive way I'm doing these computer vision and deep learning tutorials wherever you're over the basics about computer vision deep learning how to train neural networks what are the different kind of like high parameters and how is new networks actually like trained so if you're interested in that I'll link to one of the tutorials up here or else I'll see you next video guys bye for now
Info
Channel: Nicolai Nielsen
Views: 32,615
Rating: undefined out of 5
Keywords: yolov8, yolov8 neural network, yolov8 custom object detection, yolov8 object detection, yolov8 tutorial, object detection yolo, object detection pytorch, object detection python, opencv yolov8, opencv python yolov8, object detection yolov8, opencv, yolov7 dataset, detect objects with yolov8, yolov8 opencv, opencv dnn, opencv neural networks, deploy yolov8 model, how to deploy yolov8, train yolov8 on custom dataset, custom dataset yolov8, custom yolov8, yolov8 dataset
Id: TRMZCsBfX78
Channel Id: undefined
Length: 19min 21sec (1161 seconds)
Published: Wed Jan 18 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.