How to Perform Detection, Tracking & Counting Objects using YOLOv8 & Roboflow Supervision

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone welcome back to my YouTube channel my name is buy Hamed and I'm your host so guys after a long time I have came up with another computer vision related video so guys in this video we'll be learning like how we can perform object detection object tracking and object counting with the help of YOLO V8 by track and and amazing open source computer vision Library called rlow supervision so guys many of you have already requested me for this particular video like how we can perform these kinds of tracking and Counting okay with these kinds of tool so finally I have came up with this particular videos so this is going to be one amazing video guys make sure you're watching this video till the end and if you need anything from my side and if you are having any kinds of questions what you can do just write down the comment in the comment box so I'll be happy to pick up that particular request so guys in this video for the object detection actually I'm going to use the latest model called YOLO V8 and for and for object tracking I'm going to use the state of the art by track and guys I'm going to use one amazing open source Library called overflow supervision so what I will do guys I will combine these two task and I will also make one object counter on top of it so that is why actually I'm going to use this rlow supervision library and there are some advantage to use this lowlow supervision Library I'm going to discuss this part as well no need to worry about so guys in this video I'm not going to uh train any kinds of object detection model for this actually I have already created uh some dedicated video on my YouTube channel so if you are already watching my channel so I think you have probably seen like how to train these kinds of object detection model with the help of YOLO V8 YOLO V5 and yellow V7 so guys if you check my YouTube channel I already created the video regarding object detection like how we can train this yolow V8 on our custom data okay so this is the video actually you can refer in this video actually I'm going to use the pretin model on top of that actually I'm going to perform my task and I have already uh told you the tools and Technology I'm going to use for this video so here I'm going to use yolow V8 for the object detection task and by track for the object tracking and Robo supervision Library I'm going to use for the object counter okay uh so what I will do I will combine this object tracking and object uh detection together then I will be making one object counter on on top of it let's say if you want to do the object counter so first of all you need to detect that particular objects then you need to track it then on top of that you can perform the counter operation right so that is why actually we first of all need to do the detection then do the tracking then we'll be doing the counter operation and to make our task easy actually I'm going to use this rlow supervision library because this is like very easy to use library and uh it makes like life very easy so whatever code actually you be writing frequently so what they have done actually they have already written this particular code for you so you don't need to worry about the coding part so guys first of all let me uh give you some brief introduction of this roof flow supervision Library so what you can do just write uh roof flow uh roof flow supervision okay if you just search it on Google so you will get this particular GitHub so guys this is the library they have developed this is the tool they have developed and this is completely open source so with the help of this roof flow supervision you can not only perform this counting operation and all you can also perform some more task as you can see whether you need to load your data set from your hard dive or Draw the detection on the image or video or count how many detections are in the zone okay as you can see this is the things actually we are going to use and uh see guys how to install the supervision library and all everything they have given and with the help of that actually you can also load up the model yolow V uh uh yellow V8 related model you can also load and you can also use it for the annotator purpose okay as you can see and for the data set loader actually you can also use and they have given lots of you can say uh utility of for this uh overflow supervision Library okay as you can see you can do lots of thing okay you can perform lots of thing okay so guys what you can do just go with this particular GitHub and try to read the documentation like what are the functionality they are giving okay so in this video I'm going to use some of the functionality from this overflow supervision okay and I will tell you like uh why we need to use it and what is the advantage to use this particular uh Library okay so guys for this actually what I'm going to do uh I'm going to first of all open up one collab notebook because whatever code actually I'm going to write uh some so I'm going to write on my Google collab because actually here you will get one free GPU okay if you're not having let's say collab Pro account it's completely fine you can also access free GPU from here also so guys here what I will do I'll first of all create one new notebook so guys I already opened up my uh Google collab so first of all I'm going to give a name of this notebook so this is the name I'm going to give and here first of all I'm going to select the GPU so here I'm using guys collab Pro so that's why I'm having this kinds of Premium GPU but if you're not having premium GPU so what you can do you can use T4 GPU okay so this is the free GPU so I'm going to select this v00 and save it and make sure I have taken highr as well uh yeah so hm and save it and now I'm just going to connect this particular notebook uh so guys as you can see my notebook is already connected now if you want to check whether you got the GPU or not you just execute this particular command called Nvidia uh SMI so it will uh show you the GPU actually got so here I got Tesla v00 okay everything is fine from uh my side now here the first thing actually you can check the current directory you are in because this is very much important whenever you are working with any kinds of projects just check the current directory word in so I'm inside content that means in this directory okay so here first of all what I will do I will just uh upload one video here okay because uh I'm going to uh show you this uh detection and count and uh this tracking uh with one vehicle actually video okay uh we'll be doing the vehicle tracking and vehicle dediction and vehicle counting so for this I have some vehicle related video okay vehicle moving on the road so Guys these are the video actually I downloaded from the YouTube okay you can also download from the YouTube so in this video actually I'm going to use uh actually vehicle like you can say related videos okay and I'm going to perform the task on top of it so here I'm just going to um just comment out upload video okay so here what I will do just try to upload this particular video so this is my video inside the video folder I'm having this car footage and let me just upload and let me show you how this footage will look like so here I'm having two footage I'll just uh show you both of them uh so see guys uh this is the C footage actually I collected from the YouTube and card is moving on the road okay so we just need to detect the card uh we just need to detect the card then uh we need to track the card okay and after that we'll be counting like how many cards are moving so this is one video and I'm having another video so let me show you so this is another video so this video looks good actually because I have two track here okay so left hand side uh like cards are coming and right hand side actually cards are moving okay so whenever we'll be doing the counting operations at that time actually we can count both of them like how many cards are coming and how many cards are actually moving okay so both we can track so guys uh these two fruites actually I'm having right now so what I will do first of all I will upload uh this particular footage this car footage MP4 okay so this is the footage I upload it and what I will do I'll just uh make a source path so I already created this particular notebook so most of the code I will copy paste from my previous notebook because I just want to save the time okay same code I don't want to write again and again so I'll just copy this kinds of path so this is my card footage path and I'm going to give the path here okay so this is the uh my source uh video path okay now let me Define another source I think um let me just try to upload that Source also upload vehicle counting so this is what actually I'm also uploading on my uh you can say Google collab so guys I will share both video with you okay you can use any of the video it's fine okay but I'm going to use both video to show you okay how things will happen and if you want actually you can also download any kind of video from the Internet it's completely fine so guys it's uploading so in between what I can do first of all uh I'm going to install uh this YOLO V8 okay and how to install YOLO V8 uh I already showed in this particular video okay and how to train it on the custom data and everything I showed it so just try to refer this particular video and try to understand so here I'm going to directly install this yellow V8 for this actually you need to install one package called ultral litics okay so this is the package actually you need to install and after installing this package actually you would be able to access this yellow V8 now let me install so guys installation is done now if you want to check whether everything is working fine or not so you can uh use this particular code so here I'm importing alter litics okay okay it's done now I also need to install something called by track because uh by track I'm going to use for this uh object tracking and this is the state of the art uh actually uh model so let me show you this by track uh if you just startch over uh internet so this is the link of the by track okay official GitHub as you can see but this is not like very organized okay organized actually uh GitHub so if you want to install this so you need to write some additional things okay to install this thing and use it with your yolow V8 so you need to install some more libres and all I'll tell you okay I'll share this notebook with you so that you can also install U with me okay so see guys this is the bite track official uh GitHub as you can see and this is the performance of this bite track so here uh you can see and they have also included the paper and everything okay and if you want to read like what is B track and all about and what was the like you can say uh score and all everything you can read from here and uh this is the performance guys of this B track see uh it's like very crowd here but still it is able to track all the person okay perfectly so uh it's like very good state-ofthe-art tracker okay so that's is why I'm going to use this kinds of by track so uh I need I need to install this by track for this actually you need to use this particular code snippit so let me just show you uh see guys this is the Cod snippit to install this by track first of all make sure you are inside your uh uh current working directory so let me just set my current working directory so guys this is the current working directory I'm having right now so which is nothing but content so let me show you PWD so I'm inside content that means this is the current working directory so here I want to clone this particular repository after cloning actually I'm installing um some the package okay with that I'm also installing requirement. txt as you can see and after that actually I'm just importing yellow X okay because if you are installing this by track you also need to import EO X okay e x would be automatically installed in back end so that is why actually I have written these are the code okay and don't worry about like how I collected these are the thing because I faced lots of issue okay whenever I was installing this by track then I just saw lots of solution and all then I prepared this code cipit for you okay so what you can do you can use my code cipit and you can easily execute this particular code now let me just execute and install this by track for me now guys here if you see uh it will clone this by track repository first of all here then it will install all the requirement package and my video is still uploading so I'll be waiting for some times then I think I can use this particular video and in between I'll show with this video okay C photage video the first one I already showed you uh so guys as you can see installation is done now just to test whether everything is working fine or not I'll just importing some of the libraries uh here and uh make sure everything is working yeah so everything is working fine now I also need to install something called rlow supervision uh this Library so for this uh I can use this particular command I already showed you so here is the command guys you can use pip to install this particular rlow supervision and I'm going to use one specific version of this rlow supervision because what what happens actually this is currently like new research uh going on so uh every day they are doing some changes on this Library so if you're not uh using specific version so what will happen it will install the current version and some of the functionality like would be missing there and will get uh eror okay so some of the functionality some sometimes they will uh you can say delete some of the functionality they will add in this particular Library so that is why I'm going to use this particular version because in this particular version actually the codes repat actually I'm going to write uh okay later on everything is available okay so that is why always try to use the specific version whenever you are using any kinds of latest tools and Technology okay so let's install this supervision Library so here if you see it is installing so it will take some times and after that I think we can start with see guys it's done now what I will do I'll just test it everything is fine or not so I'll copy this code and here if you see I'm importing supervision uh supervision library and it is working fine okay and this is the specific version I got now what I will do guys I will load uh one pretin model from the YOLO V8 and how to load pretin model and all I already discussed uh in my uh this video just make sure you're watching this particular video okay and here you can uh easily load this model okay if you're using Ultra litic package so easily you can load the model just Define the model name and after that you can load the model okay uh so you can actually use this yellow V8 model in a two way one you can write python script and another actually way you can use this particular model OKAY using uh common line interface okay both uh it is possible I already discussed this part in my uh previous video that video okay make sure you're watching that so first of all I will uh show you with the help of this command line uh uh command Okay so for this first of all make sure you are inside the content directory so now I'm inside the content directory as you can see I'm inside my content directory now this is the command guys so you just need to execute this particular command um uh to actually do the object detection task okay as you can see here I'm writing yolow command and task is equal to detect I want to perform detection because with the help of this model you can also perform U segmentation as well classification as well that is why you need to specify the task and mode is equal to predict I only want to do the prediction on top of my data okay the video I'm having currently and this is the model actually so the same model actually I'm using as you can see yellow V5 uh yellow V sorry YOLO V 8 x PT model and there are so many model if you go to YOLO V uh 8 reposit yolow V 8 GitHub okay if you go this uh GitHub repository in the mod section actually will see lots of models are available uh here if you see guys uh lots of models are available okay so I'm using this particular model you can use any of the model so this is the smallest version of the model uh sorry I'm using X model so this is the X model guys this is the X model okay so this is the smallest model I'm using and you can use any of the model it's up to you and this is the confidence SC I'm ascending and Source video I think you remember we already defined the source video path here okay so this is the source video path I'm using this card footage MP4 you can also use uh vehle counting MP4 it is completely fine but first of all let's do it uh so I'm going to use this particular uh video and let's do the detection so if I execute and what it will do it will load this particular video and it will uh perform the detection on top of my entire video okay so actually here you don't have any access on the frame like if you let's say want to perform um on top of like only one frame from the video so you don't have any access here okay for this uh what you need to do you need to use this uh U rlow supervision Library so it will give you that kinds of functionality I'll show you it's like very uh easy to use so here I gotten one error so Source okay so here it should be I think one okay maybe I defined as one uh let me check the path once yeah so this is underscore one not Source video path H now I think everything is fine now let me EX Ute now guys as you can see it is taking all the frame one by one and it is doing the inference and here it will create one folder for you call runs inside that actually it will uh save you that detection uh videos okay and after that we can download and we can watch it so first of all let's complete it okay and I'll show you like how this detection will happen so guys as you can see detction is done and it has saved this particular video inside detect folder inside predict and here is the final footage okay now what you can do you can download this particular footage so I already downloaded so let me show you uh the inference so here I already downloaded this particular footage so what I can do I can open it uh so see guys this is the final uh detection I got and detection is pretty good guys as you can see it is also detecting this uh invisible cards as well as the person okay as well as the uh see it is detecting everything trucks and traffic light also it is detecting okay it's like very amazing model and see bus is also coming I think uh yeah it's a train see now it has become train previously it was looking like bus that's why uh it was detecting as a bus okay it's completed that means everything is fine uh everything is working fine and we got to know like how to perform the detection okay now see guys you have performed the detection on top of the entire video now let's say I want to only perform the detection on top of one particular Fame okay of of that video so how to do it okay for this actually if you're doing it manually you need to write some custom code for that first of all you will be using open CB load the video take the frame load the model detect the uh like you can say detect on top of the frame then again save as a image okay so you need to write tons of code for that but if you are using this uh ROFL supervision Library okay roof supervision Library they have already written this particular code for you and they have already created this kinds of Library so what you can do that is why they are telling uh we write your reusable computer vision tools okay so the code actually will be writing more and more okay for your task this kinds of code they have already written for you so what you can do actually you can install it and you can directly use this particular functionality for you okay so that is why we'll be using this particular RL supervision Library it is one of the amazing Library actually I was exploring that's why I thought let's also integrate with this kinds of projects okay now for this guys uh what I will do first of all let me show you see first of all you need to uh you need to import some of the library from this supervision okay as you can see I have imported some of the library so this is the things actually you need for the G video frame generator so what it will give you it will give you one particular frame okay it will give you one particular frame from this video so it will return actually so many frames from that actually you can take any kinds of frame okay so that is why you can use this particular method okay from the supervision itself then uh if you want to show frame inside the notebook okay you can use this particular method but if you want to show any kind of frame in the jupyter notebooks what you need to do you need to install some of the more package okay there actually is not required everything is written inside the uh supervision Library okay no need to worry about then detection then box annotator then color uh color palette okay so everything they have given okay as a functionality now let me import them and what I will do let me show you how things will happen so first of all I will be uh uh defining my models see what what it will return actually it will return all the classes name actually having uh in this model so let me just print them see guys so it has trained with something called Coco data set okay Coco data set uh Coco is a you can say object detection U Benchmark data set it is already trained with Coco data set and these are the objects are available inside Coco data set okay now here if you see I'm using vehicle okay I'm using vehicle uh actually uh a video here so for vehicle actually these are the class ID as you can see if I go to the two so two is a car then three is a motorcycle then bus airplane okay so I have taken only those ID which is available inside my video as you can see that's why I have created one class ID okay now what I will do I execute this particular code now here is the final code uh to perform the detection in just single video frame as you can see so what I can do actually I can write one comment so predict I'm just doing the predict on a single frame okay predict andate on a single frame okay and this is the final code and here I will give my I'll give my uh sourcecore one because uh this is the video I'm having currently first of all you need to get one generator so first of all you will be getting the frame of the video after that you will be defining the uh B uh box annotator inside that you need to define the color uh pette okay then thickness and text thick okay everything you can uh change here like how uh how much thick would be the uh like text okay then how much sck would be the you can say text Bott line everything you can change here and now you're creating one iterator now you're doing the prediction after that you are getting the detection boxes then you are assigning the label after that you are just uh uh what you are doing you are just showing on the notebook okay let me show you how it will show show so here if I execute see it will do the detection uh first of all it has take uh it has taken one particular frame from that video see this is the first frame of my video it has taken that uh frame and it has done the uh detection as you can see it is card now you can also uh change the thickness okay let's say you want uh this Tex thickness uh let's say if I reduce this thickness maybe this T should be a little bit smaller see guys t uh it is a little bit smaller now I think uh I can also reduce this thickness see all the actually customization option are available right now see this box thickness has been also reduced okay so that's how you can control this thing but whenever I was executing the command Okay command line so there actually you don't you didn't have any kind of control so that's why actually we are using the supervision library and it gives like so many functionality so we don't need to write so many codes for this I can directly use this supervision library and I can use it okay for my task and if you understand the python code I think you are understanding what is happening first of all we are getting the detection after that we are assigning the label and we are doing the uh you can say annotate and we are just showing on top of the notebook okay so these are the common code I think you saw inside any uh object detection code okay and here the main thing actually we're using called supervision library now guys this is for the one frame uh detection okay now if you want to do for the multiframe that means uh for all the video okay all the video frames what you need to do you need to write the same code inside a for Loop okay or inside of while loop so that it will take all the frame one by one it will perform all the jobs okay then it will save as a video but uh what I will do with that actually I will also integrate my tracker and counter Okay so because two task I have already defined as you can see I'm going to perform tracking and Counting operation as well because we know like how to do the detection okay so I instead of showing the detection of like this thing what I will do I will integrate my tracker as well as the counter with that particular code okay so for this what I will do uh I already written this particular code so let me just comment it out so here is the comment this is for the uh track detect and count for the whole video okay so here first of all you need to assign some of the parameter for your bite tracker okay so if you visit the bite tracker GitHub so they're telling if you are using B tracker you need to assign these are the parameter first of all okay you need to create one um class okay class entity inside that you need to Define these are the thing now I have already defined now here what I will do I will again check my current working directory so I'm inside my um content okay it's fine now I will use my second video so what I will do I'll just copy this name as it is so here is the name I think I can copy and uh maybe I can mention it here okay so now what I will do I'll just name it as Source path only okay Source path only and I will just copy this path and I can mention it here so this is the video I'm I'll be using okay for this tracking counting uh now what I will do I will again import some of the libraries from my supervision so as you can see I'm importing Point video info then linear counter okay so these are the thing are required so uh these are thing actually they have given in their documentation I've just copy pasted from them only okay I'll share my notebook so you can use this notebook as a template okay so let me execute now uh first of all what I will do I will set one uh uh I will set some variable so here I'm setting the start line and uh end line okay so what will happen actually whenever you will do the count operation okay so you first of all need to create one line okay on the video uh on the on the screen so whenever uh this car is uh you can say Crossing this line it will make a count operation for this this is the uh location I have given like from where this line will start and from where it will end and uh see guys this is the X and uh y uh for the starting point and this is the X and Y for the end point for the line I'll tell you whenever I'll do the final Direction I'll tell you and this is the target path that means with the help of this name actually my video will sa okay now let me execute now if you want to see the video information like uh what is the video width and length and the FPS everything you can see with the help of this video info see video info is already one method inside supervision Library uh so if you just call it and give your video path here it will uh give you all the information related video like how what is the width what is the height of the video uh what is the FPS and what is the total frames in this particular video so this is one of the like you can amazing uh open source Library I was exploring so you can use it but if you want to let's say create your custom python code for this you need to write tons of code to create a video information and all but using one particular line we can U get the video information okay so that is why actually it makes our task very easy now uh what I will do guys I need some utility related functionality so these are the utility related functionality you need uh because it will do the detection to boxes okay then it will perform track to boxes so basically whenever you will be do the detection okay so whenever you will pass that detection to the tracking so you need some other data type so this will convert these are the data type okay with respect to the input you will be giving for the next task okay that's why these are the utility related uh function we need Okay so this thing actually I already got from the documentation itself I just copy paste it okay no need to understand this part just try to copy paste the same code as it is now after that this is the final code so here if you see I'm using the same code I have written for the single frame but here everything I'm writing inside a full loop so I'm taking one by one frame I'm performing first of all as you can see detection after detection I'm performing something called tracking after tracking I'm performing something called Counting operation okay with the help of this supervision Library as you can see that is why we have imported so many things line counter line counter annotator video Shing okay then we have points so everything uh it will actually take care only we just need to use this particular for Loop and here we just need to specify my source video path okay everything it will take care see first of all I'm loading the video loading my bite tracker object bite tracker is the tracking U you can say model then I'm also taking the uh generator that means video frame okay I'm taking one by one all the frame and here is the um object I'm initializing and inside a for Loop I'm doing one by one for the all the frame and guys once uh everything is done so I'm saving uh the video with this name okay in my current folder okay now let me execute and show you how things will work so let me execute see guys it is first of all loaded the model then it has per uh started the detection tracking as well as the counting uh for all the objects I'm having in this video now once it is done I will show you uh so guys as you can see it is done now I got my final video here if you see video counting results. MP4 now I already downloaded this particular video on my Lo now let me just open it and show you how it will look like see guys this is the video now I think I can open it uh see guys this is the final results actually I'm having so first of all if you see it is detecting it is tracking see this is the tracking this is the tracking ID and once it is moving see it is counting okay so this cards is out that's why it is giving out and if it is moving from here that means in this uh card actually getting in okay so that's how see things are happening and this is like very amazing okay as you can see and let me show you that Bott line as well see guys this is the Bott line it is starting point and this is the end point that's why we have given this parameter I think now this thing is clear okay why we have given this parameter so this is the parameter guys I have given okay start line and end line okay so it's like very easy uh task actually if you're using this supervision library but if you're doing it manually so you need to write tons of code and it will be facing lots of issue okay so that is why you can use this roof flow supervision Library okay it's like very uh good library and you can uh do lots of thing with the help of the supervision Library you can go with this GitHub and we you can also go with the documentation you can learn even they have also given the tutorial as you can see like you can learn you can do also speed estimation then traffic analysis okay so everything you can perform with the help of this uh supervision Library okay and still uh this is in research as you can see the last comit was uh 12 hours ago only okay so every day they are doing some changes in this library and if you're having any issue what you can do you can also create a issue here and you can and update the issue okay they will uh take care about your issue and all so yes guys this is all about of our this object detection object tracking and object counting with the help of this yellow V8 and uh by TR and uh this rlow supervision Library okay I hope you like this particular video if you have liked this particular video make sure you have uh subscribed to my channel and just share this video with your friends and family and if you need anything from my side okay you can let me know in the comment okay I will uh feel free to uh create uh a Content regarding that uh particular topic okay so yes guys uh this is all from my side so thank you so much guys for watching this video and I'll see you next time
Info
Channel: DSwithBappy
Views: 1,046
Rating: undefined out of 5
Keywords: YOLOv8 Tutorial, Object Detection, Object Tracking Techniques, Computer Vision Tutorial, Roboflow Supervision, YOLOv8 Object Counting, AI in Object Recognition, Deep Learning Tutorial, YOLOv8 Implementation, Real-time Object Detection, YOLOv8 Setup Guide, Image Processing Tutorial, Computer Vision Projects, YOLOv8 Algorithm, Object Tracking, OpenCV YOLOv8, YOLOv8 and Roboflow, ByteTrack, Object Tracking using ByteTrack
Id: 75ET6mmDL14
Channel Id: undefined
Length: 30min 33sec (1833 seconds)
Published: Thu Jan 25 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.