Real-time Object Detection with YOLOv5 and OpenCV - Deploy Your Model Now!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
we get the pounding boxes around the optics that we're detecting so right now we're detecting a couch in the background even though we can even see like a small part of the couch it's still detected we can see that we're detecting a chair and also a person hey guys welcome to a video on this computer vision tutorial in this video here we're going to do live object detection with yolo v5 so in one of the previous videos here on the channel we have talked about like how we can create your own custom optic detector with yolo v5 and we also implemented a ulv5 model where we can actually just take a youtube url or any other video file and then just pass it into the object detector and then it will detect all the optics that we have in the video but in this video here we're going to do it with a live webcam so we're actually just going to connect to the webcam and then we're going to do live optic detection with yolo v5 but first of all i'm going to hit subscribe button and notification under the video here only 10 of you guys watching these videos here are actually subscribed to the channel it's just a single click and it helps me and youtube channel out in a massive way you can always remember my channel if you want to report a channel with a small monthly fee everything will go to create more and better quality content here on the channel also if you're a member channel i can help you out on your projects if you have some problems and so on i can help you out and give some guidance if you remember the channel so thank you guys so let's not jump straight into visual studio code and go over a code for implementing this object detection class on a live webcam so in one of the previous videos we already went over this class here line by line so if you want to know more details about like how to implement this class definitely check those videos out here on my channel about yolo v5 so now we're just going to already just load a pre-trained jola model we can also create our own custom optic detector with y5 i have videos about that on the channel so just searching my name or like on my channel for your v5 videos and you can go in there and get more details so in this video here we're just quickly going to go over uh the lines of the code here so first of all we're going to initialize our update detention class we're going to load our model so we're going to call a load model function that we're going to create then we also get the classes here for the cocoa data set if we are actually using cuda we can run the program here on cuda if it's available so again you can joking you can just go into pytorch website so first of all here i'm just going to show you so you can just go into pythor's website and into the installation path then you go in here and choose your uh operating system you can also choose like the package that you want to install it with and also like if you want to use python or cbs plus you can use your cuda version here that you have or if you just want to download it with cpu then you will just get these commands here you can go into command prompt and just pass in that command and they will able to install pytorch here on your computer with either the cpu and also the gpu if you are installed cuda beforehand from nvidia we can also use like here we can see we have this rcm if you actually use um pip install i think it is or linux we can use like an amd um md graphics card as well but if you have a nvidia graphic card you can use cuda here and then you can basically just go in here and install it by copying copy pasting this command and passing it into the terminal or your command prompt so let's just go back to visual studio code here again so if you have a cuda available if you use your gpu track like run this inference with the model on or else it'll just use the cpu then we're going to load the model so we just go inside towards that hop dot load and then we can just go inside inside like alter lytics and we can just take the yolo v5 small model and then we just said pre-trained equal to true so we just use a pre-trained uh yolo v5 model on the coco data set and then we're just going to return our model then we can set up some scores for our frame so here we take a single frame as an input and then the score uh scores like the frame using the ulv5 model and then we're just going to return the labels and the coordinates of the object to take the pi to model in the frame so we both have a score we have like a confidence score for the boundary box uh that we have found in the image and we also have like the coordinates of that bounding box and then we also have like what class rex like detecting inside of that bounding box then we can actually have a function for like converting a class to label we can also plot the boxes on an image so we can actually display the bounding boxes that we're detecting in our image and then we're just going to have our call function here so when we initialize our object detector here and we just call the update detection function we can have this like um awesome autonomously called function uh so we're just going to define that here we're going to open up a webcam so this is the code here that is different from the other videos about my yolo v5 model here on the channel so now we're going to use the webcam instead of a youtube uh url for doing like interference on so we're going to open up our webcam with the capture then we're just going to have a while loop running through like as long as our webcam is open we're just going to read in a new frame from a webcam then we're going to pass that frame into our score frame which will actually just pass our image for our model and then we'll get the results out here at the end then we can just go in and use the other function that we just talked about with the plot boxes we just throw in the results that we got from our model and then we also throw in the frame sort of plot boxes here and then we're just going to return a new frame here that we can then put some text on for example here we're going to count the number of frames per seconds that we have so we're going to use the perf calendar from the time module so we just have a start time we have an end time and then we just calculate the number of frames per seconds that we get then we're just going to put put the text here on top of the frame with the number of frames per second that we that we get and we also have the bounding boxes and also the classes with the confidence score and then we're just going to call cv2.imshow where we're just going to show the frame that we have done all the processing on and the detections on and here we just check if we hit qr on a keyboard we will go out of this while up here and terminate our program and then we're just going to like terminate our program um so this program here will run until we hit q on our keyboard then down here at the bottom we're just going to initialize our object or like an instance of an object so we have our detection equal to update detection so this will be our class that i just showed you and then when we call this detection function here it will actually call this a call function inside of our class and then we're just going to run our live update detector with a pre-trained yellow v5 model you can actually also go up here if you want to use another model you can do so like that you can use like the large model or like nano model or stuff like that but here we're just going to run a program and see the actual results that we get so now we're actually going to run the program here we can see that device used is the cpu so i don't have in uh cuda installed here on my computer we can do another video about that to actually show you that we can improve the performance by running this the old v5 model on the gpu instead of the cpu but we can actually see here that with an i7 um chip here we can actually get some okay performance we get around like three four frames per seconds i also have some other different kind of like programs running on my computer right now so i could actually get up to like six seven maybe eight frames per seconds if i was only running this program here on my computer and wasn't recording and stuff like that at the same time but here we see like ulv5 small model summary we have 213 layers in our model we have like around um seven million parameters and we can see here with the gradients and stuff like that but here we see the device used is the cpu we can get the number of frames per seconds we get the pounding boxes around the optics that we're detecting so right now we're detecting a couch in the background even though we can even see like a small part of the couch it still detects it we can see that we're detecting a chair and also a person we could also draw like the confidence core on top of these bounding boxes here and stuff like that but again we can just like detect arbitrary optics right now when we're just using a pre-chain model so we get all the classes from the kokod data set so this is really easy to get started with you can just go into my github i'll link to a darn description here you can grab the code run it on your own computer and then you can do a lot of different kind of like applications and projects with this code you can also train your own custom yolo v5 model and in just like implement it in in this code here as well i would just bought that on channel so definitely check those out we can just see try to see like some other different kind of objects here where you see we detect a cop so here we see we detect both like a cop remote here so we could actually set up some threshold that if the detections or like if the confidence score of these objects here is lower than some threshold we're not detecting it as an object but here we can see that now would act like it takes it as a as a cup we can also try to like take up some sound classes here if you're able to act like you take those i'm not sure if those are act like in the coco data set i'm not sure those are because these are just like glasses so it doesn't act like detected sometimes it detects it as a remote that is not correct but we can actually see that it is capable of detecting different kind of objects here we see it it keeps pretty good track of the person here and the couch in the background and right now we're only doing detections um a couple of days ago i released a video about like optic tracking how we can use viola v5 together with object tracking definitely check that video out it will improve your performance by a lot it actually uses a kelman filter to act like track these bounding boxes here from frame to frame you can assign an id to the person and then you can just keep track of that object in the scene but here we're just taking in an individual like a single image we pass it through our model we get the detection down and then we just do that for every image that we get in from our webcam so it is way better to actually keep track of these different analog optics in the scene drag it around if they leave the camera like it will just like discard that the tracking or like that detection and it can be useful a lot of different kind of things so definitely check that out as well this video here was just for you guys to like see that we can also do this yolo v5 model here live on a webcam and you can just go in and take my code run it on your computer and do some like optimization to it you can try it out with gpu you'll get way better performance when i ran this code here on my dvr i actually got around like 30 to 40 frames per second so it's act like 10 times faster to run it on the gpu but thank you guys for this video here and remember the subscribe button and notification on the video here also like this video here if you like the content and you want more in the future it just really helps me and youtube channel out in a massive way i'm currently doing a computer vision tutorial uh where we're talking about like basic image operation from the beginning how we can do camera calibration stereo revision to get depth information in our images then we're combining that with point clouds deep learning and so on so it's a really cool tutorial if you're interested in that tutorial and to learn more about computer vision i'll link to it up here or else on the scene next week guys bye for now
Info
Channel: Nicolai Nielsen
Views: 13,827
Rating: undefined out of 5
Keywords: yolov5, yolov5 neural network, yolov5 custom object detection, yolov5 object detection, yolov5 tutorial, object detection yolo, object detection pytorch, object detection python, opencv object detection, opencv yolov5, opencv python yolov5, object detector, object detection yolov5, opencv, yolov5 dataset, neural networks, detect objects with yolov5, yolov5 opencv, opencv dnn, opencv neural networks, deploy yolov5 model, deploy yolov5 model opencv, how to deploy yolov5
Id: KQKwXga_uTM
Channel Id: undefined
Length: 10min 21sec (621 seconds)
Published: Mon Jul 11 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.