Episode 5 | How to Extract the Outputs from Ultralytics YOLOv8 Model for Custom Projects

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys welcome to new video in this video here we're going to see how we can extract results from your V8 so after we're done in clearance we actually just get a results generator back in this video here we're going to see how we can extract all the powering boxes the mass the probabilities the path to the image the original image and so on so let's now start inside the ultimate you'll be eight documentation first of all we'll go over to the mode and now we go down to our prediction inside of our prediction we can just scroll down to our working with results but first of all we need to set up our model in the previous videos we covered like how to do object detection segmentation and tracking post estimation and so on definitely check those videos out so let's just jump straight down to the working with results section so we have this results update that is actually returned from our model when we're doing interference we can also go in and extract all the attributes from that object so first of all here we go through the documentation then I'm going to show you how to do it in code and then we will see the results so we can use this in our own application and project so first of all here we have the results dot boxes and this is how to actually get the boundary boxes of the update that we're detecting so we can also go ahead and extract The Mask so we just called results.mask the key points for post estimation we can also go in and get the probabilities which is basically just the class probabilities for all the objects that we're detecting whether it's segmentation boundary boxes or barely just key points then we can filter those ourselves based on a confidence score if you don't want to use like the model arguments that we have with dual V8 so the results update actually contains a tensor from pytorch which is actually really easy to use so here we can see some of the results so either if you're running it on the dpu or the CPU you need to convert it back to the CPU if you're running it on the TPU because then all the results will be on the GPU and directly being able to manipulate it and use it in your own project nav application we need to convert it to the CPU so we can display the results or like do whatever we want with it so here we see that we can call Dot Kuda if we want to have it on the GPU you can also call dot CPU if you want to convert it to the CPU so you can also see here we have the bounding boxes how we can extract those the mask and then we can call these individual attributes on all the different kind of like Properties or all the individual classes so both have the boundary boxes we can get the X Y for the top left corner and the bottom right corner we can also have the normalized coordinates we can get the confidence scores the classes and also just the raw tensor data for the mask we can get the individual points in our segmentation mask also for the key points we can get the individual key points in the detected parts of our body and also the probabilities so here we can basically just get the top one and also the top five indices and scores when we're doing classification so yeah this is pretty cool let's just jump straight into it and see how we can actually work with it in our own custom file script so Random straight into Visual Studio code and I've created this custom authentication class where we're going to extract all the results so we have this update the detecting class first of all we set up the capture index if we want to run it on a live webcam we use coder if it's a way available or else we'll just use the CPU then we load the model we create an instance of the YOLO model we're going to use the meter model for update detection in this example and then we have our predict function which is basically just throwing our function through our model through our model then we get the results return that and then we can directly throw that into our plot boundary boxes function and this is where I'm going to show you how we can distract the detections for our classes that we're detecting and the objects that we're detecting so first of all here let's just work with the boundary boxes let's see how we can convert that so we have the results so from our results we just have a for Loop running through all of our detections then we have our bounding boxes and our bounding boxes in this example here will be equal to our results and then we also actually have our result here we take the first one we take the boundary boxes and then we also just convert it back to CPU and a numpy array so we can work with that first of all here let's just print the boxes so we can actually see the format so I'm just going to run the application here we're going to take a webcam and then I'm just going to show you what the output will be and then we're just going to work on that so this is just to show you guys so now we get the out x y x y h n and also for the normal coordinates so this is the bounding boxes around on our Optics right now we're not printing anything or we're not visualizing anything because right now we're just extracting results we're not using the ultralytics framework to act like plot R and to visualize our results so here we see we get our x y and width and height and we also get our x y and x y depends on if you just want to get the top left corner and then get the width and the height of our bounding box or the X like coordinates so let's go ahead and extract the act like coordinates here we can then just call our boxes so we have our x y x y and that will be equal to our boxes then on our boxes we can take the attribute X Y X1 and we should be able to print our x y and X1 let's do that and just show you guys that this is act like how we can access these attributes so right now we should get some bounding boxes out there we go let's just terminate this program let's go up here we see that we're detecting one person one TV one laptop and two keyboards so that would be five bounding boxes that we need and this is also the results that we get okay so this returns a list of all the boundary boxes that we have so let's just call this XYZ and X y's then we can have a for Loop running through all of our X I's and X I's we can either append them to some list if we want to display those lists later on or just collate all the results store domain.json file CSV file or whatever but in this example here let's just draw our rectangles as our boundary box so basically just going to Loop through all the boundary boxes in our detections and then draw a rectangle around them on our frame we're going to return the frame and now we should be able to run our program and this is actually how we can use the results and also just do whatever you want with the results here we can see that we're taking keyboards my hand the TV monitors and so on right now we're just throwing the bounding boxes we get some pretty nice results in this example here we just extract the results to go in and visualize it but you can use it to control your other applications create some logic around it and also create your machine learning and AI projects for this so now if you want to extract the results and don't want to plot the boundary box yourself you just want to use the results for your own application and project so now right now we can just delete this part here this is basically just to extract it we can also just go in and append it to our list and then return those lists from our function use them for whatever we want to do with that after that so the here everybody just have a pin and then we're going to just append our boxes dot x y x y and we can do that do the exact same thing for all the other ones so it could be like for confidences and also for our class IDs so let's just do that we just have our confidences so that will just be our bounding boxes so boxes.com and that will be our confidence and then we can do it for the last as well so that would be our class IDs dot attend box dot classes so that will just be CLS now we have the classes and then we're going to go down and return these lists as well use them for whatever in our own project and application so right now if you don't want to do the plotting we can also just go in and directly call the plot function um from our results so basically if we're just going to take our results so we just have these results just going to take grab that one so that will be our results take the served element of that and then we can just call this plot method directly on it and we should be able to see our results so yeah here we can just have our plot function and then we can return this instead of our frame so instead of doing the plotting itself we will then have our results and then we just directly plot on that let's run it and see the visualizations together with returning the list there we go our program is not running let's take it out here we see we get all the results together with returning all the lists with all the results extracted so thank you guys for watching this video here I hope you learned a ton and that you can use this in your own projects and applications stay tuned for the next video bye for now
Info
Channel: Ultralytics
Views: 26,442
Rating: undefined out of 5
Keywords: Ultralytics, AI, Artificial Intelligence, Object Detection, YOLOv5, YOLOv8
Id: QtsI0TnwDZs
Channel Id: undefined
Length: 7min 56sec (476 seconds)
Published: Wed Aug 09 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.