Object Detection Using YOLO-NAS. Detect Objects Like Pro. #Deci #YoloNas #Ai #ml #objectdetection

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome to my official Uranus course in this  course we will learn how to detect objects using   your learners on both image files and video files  we'll learn how to extract important information   such as the bounding box the class name and the  confidence value we will start off from scratch   where I'll teach you how to install all the  libraries we'll be using this particular video   if you are new here do me a favor by Smashing  the Subscribe button you can also share this   video with one of your friends so enough with  myself promotion stuff so let's get started okay farm so let's kick off by installing  all the libraries we need so if you are   using pycharm as I am using now then all you  have to do is to go to file then go to settings   then in settings yes click on the add package  button so you select python interpreter then   after which you have to select on the plus button  so yes click on plus and the first thing you have   to search is the super aggregate Library which  is the Euro Nas Library so super gradients   just click on it and then specify the version  and then you click install you can install the   latest version it also works so that's all I've  installed it already so that's all apart from this   you have to also install opcv python so you just  write a PCB python so we'll have to type it here so just click it and also install the latest  version then you have to also install torch   so it says for touch and just click install  package so these are the packages we need so   I forget we need to install cv02 to get a nice  test and the nice bounding box or the rectangle   so you say see result and also click on install  I've installed all this Library so I don't need   to reinstall them that's why I guess set their  names so you guys can go ahead and install them   so after that okay so let's let's for those  who are not using uh buy charm to install this   you just have to write CMP to pull off your  terminal then you can use pip to install them   so for instance you just have to type it install  Ed correctly then you are going to install super   price ingredients you do the same thing for CV so  you do the same thing for touch and you are good   to go so after that you have to just open any ID  you are using then we'll start off by writing our   code and all the codes we'll be writing in this  particular tutorial via my GitHub repository you   can leverage it and use it yourself including all  these files we are coming to use so let's quickly   go through the file system we have classes.tst so  this will be the classes file will read into this   code to be able to get the particular class you  are detecting so let me close it off then here we   just have some football videos of our football  footage we also have another video here then   we have the third video finally we have one image  will be running in French onto using you will not   so we look at how to run influence on images  as well so we start off by now importing our   installed libraries so first import you will  ask to test it from let me increase this   is from um super gradients dot  screen I'm going to import models   so with this you import your Lunas you will  do same for torch so we just import parts   import CB2 which is the OPC Library we'll  import CV Zone itself so this is Sim Zoom then finally water import the match  module to the function calculations I have to import numpy as well the reason I didn't  mention installing non-price that when you install   PCV numpy install by default so in case it  doesn't you can quickly install numpy as well   so now that we are done with our installation  first we are going to look at how we can run   influence on images so I'll just put a comment  there that work images yes like that so we are   working with images now so to run inference on  images the first thing you have to do is to get   the model we are going to work with so in this  case I'll just write our model is equal to models   and in here you have to specify the type of model  rank use it so before I specify the type of model   let me just write model dot get so the function  name is model.get then in here you have to put   them particular your nunch model you are using  so just as yellow V8 you will not have the small   model medium model and a large model the medium  and the small model runs faster so if you have ceu   not GPU you can run the small modules but with  the larger ones you need higher computational   power so we'll be using the small module this  time you know Nas we write yellow underscore   Nas then you also write underscore small to  show that you are using the small your module   then you have to specify that okay you are  using a pre-trained module so you specify three which is equal to Cocoa yes right open here  that means you are using all the items in the   Google data set which are in the classes dot TST  files here okay so this is how you load the model   that's all about loading the module then  to get a prediction or to run inference on   the image you can see our output is equal to  our model here then in here we have to pass   the listing to an image the path to an  image so just after the model.create and give it a path to the image you want to you  so in our case our image is test2.jpg so you just   have to type in there because you are working  in the same directory so I'll just type test   two dot jpg and that's all so in order to show  this image all we need to write is about output   dot show and that's it so once you write this  you can run this code and you will see that   will have some predictions hola and here we  go so you can see we are having traditions   a testing a car okay there is a bicycle  at that side too okay it's on a bicycle   handbag I doubt it there is no handbag in our  image so you can see the confidence is 26 27   so those ones are false detection so what we  can do is to specify that our confidence is um we want to take all detected objects that  has higher confidence so we can specify that one   too in the model dot predict function so you can  type here that our account s equal to zero point   60 so anything from 0.50 above 1 to the 30th on  that image and boom here you go so you can see   we have a cleaner detection now all the false  detections are gone pressing bicycle a car then   another bicycle at the corner there so voila this  works great so you can see it's very simple to   run influence on images using yellow Nas there  is nothing hard about it everything is simple   so kudos for the daisy company for making this so  easy for us to use so this is all you need to know   about running inference on images but before we  go if you also have a GPU you can you can then run   this using the GPU by writing this line of posts  you can just specify that our device is equal to   rch the device and in this case you  specify here Buddha you can do is touch but is available so in case you have a GPU and  it's available we are going to use this if   it's not available you can use else statement  to use the CPU so we do else Dot dot device   and then we specified okay we'll be using CPU  in fact we spell that correctly and that's it   so if you have GPU it will go ahead and use  the GPU if you have CPU it will go ahead and   use the CPU instead of the GPU so any of them  that you have it will choose automatically then   you can just come here to dot device or dot two  okay install the parenthesis specify a device   if you have GPU to choose it but in case you don't  have it to choose the CPU and work with it so run   once more and boom so you can see we have the  same results so that's it so this is how you   run influence using your Lunas on images so we'll  now move to how to run inference on video files for that I think we can comment this will come  down and that is it so for videos guess what we   first need to get the video from our webcam or  the video we have in our directory you just have   to read in this video file or send this Frame to  them your Nas module then this your Lunas model   will detect objects that it sees in this Frame so  let's start off by loading in this video into our   program so for that we create a captcha update  which is equal to cv2. in your capture and in   here we still specify the path to the video file  you want to use so what is football one dot MP4 and this is a particular video file we  are Reading Football 1.84 after winning   this you have to go ahead and show so we'll  say one two which is the same as wire one will get our video file called a video does it so after grabbing the video  here let's go ahead and show it   so we use the I am shoe function youtube.com and guess what you are  going to show our video file   after showing it you have to wait take  it every second so using the 2.8 key   I will put one in here which specifies that okay  will be taking a video frame one second each one   second we take a video frame that's it so with  this we should be good to go should be able to   read in our video file I'm boom here we go so  you can see we are reading the video file and   playing it with our program so the video file  you can see is very big so let's resize it   so we will see our video is equal to Simi  2.3 size I want to give you the size of 1080 you can choose any size you want depending  on the type of video file you are using   I will use it 740 so you want it to be like this  just run once again and this time around a video   has been resized successfully so now that we've  resized this video all we need to do is to send   this video to our model but before that I will  just copy this code here for loading in our model   so I will control C and place it down here so I can give some space here so it's the same  process we need to load the model once more   specify the one we are using and bear in mind  the first time you run this code to go ahead   and download this your bonus small model so you  should make sure your computer is hooked up too   the internet so that it will  download it successfully   so that's one thing you should know if you  want to use the large model you just have   to put l here instead of the S the medium  model then you just put M here that's good okay so now let's send this process video  to our frame so for that we say our results forward to our model that's pretty neat then in here what are we predicting we  are going to print it on our video file   so we just have to send in the video  file so our video file this video   you can specify other things as the confidence  just as we do so our confidence is equal to you   can do it 60 percent and then we are  taking everything as the first index so our bounding box information our confidence  and the class detect will be stored in this   result variable here so we can go ahead and get  all these steps from the result for example so   let's say you want to get our bounding box so we  need X BB box X equal to our result dot prediction so that's it result or prediction then once you  want to get the baby box and get do it dot DB   boxes then underscore X Y X Y so that's all you  need to write to get the bounding box information   now we'll move over to how to get the  confidence so we'll see our confidence what a result first prediction  so we just copy the same code   since it's the same thing we are  writing over and over so result.   credition dot confidence kind of  straightforward we do see for our so to get our labels which is the class games   it's also equal to result of prediction  Dot and we give it our limits so now these are all the necessary  or important steps we need from our   objectation model the bounding box that's the  position of everything that it has detected the   confidence how sure it is that okay whatever  it is detected is this or that then the name   of what it has detected which is the name so  once you've gotten this you can iterate over   them and then extract the actual values then  we use these values to draw the bounding box   so what we'll do is that we can see for I'll put  in our DB box our confidence and lastly our labels then in zip we zip it and then we are going to  zip all these three things so we just copy them   and put it in the zip function so after this we can just get our X1 value y1  value in X2 Y2 so this is equal to empty Dot whatever our DB box is that's it so for the confidence value  we have to um use the math library to   convert it to percentage so for that I'll  see our confidence equal to Mac dot seal all we have to do is to multiply it by 100.  so when you play like this whatever value   you get is in percentage so if you get 50 that  means 50 is 50 sure so we are just making sure   that it's in well it's not a floating  profile but it is in percentage Direct   then for the labels you can see our labels is  equal to integer value of whatever our labels are because it is fruit so we have to convert it  to integer and these labels are what we'll be   matching with the classes.txt file so this file  contains person bicycle so if the label is zero   that means what you have detected is a person  so let's go ahead and load in this class names   here then we'll map it successfully now if  we have detected the label here is zero then   whatever we are detecting is a person so I'll  come here and reading their classes.txt file   so let's begin with class names which is empty  list then we can open it as a file so we open   we want to open classes.tst  file which is also here   so once you open it in your  Rainbow so just put R here I want to read it as s the class  names now is equal to F dot read   since you would like to put each on a  different line with security lines so that's it okay so after reading this here we can come  down here and you see okay our class detect is equal to our class names in the key of our  label so if our label here is two it will just   go into this classes dot TST then install zero  one and two that means it's a card so get car   instead of the number two then we know what we are  actually getting okay so now it seems you are done   with getting all these values you can go ahead  and start drawing our rectangles on our object   being detected so I will come down here and I will  use see visual to draw a nice rectangle you can   use CV2 to draw the rectangle but I just want it I  just feel like that's if this one has a knight um   rectangle so I'll use it and to use that one then  we have to get the width and the height instead of   S1 S2 I2 so together width and the height all you  have to do is Right width I is equal to um x two minus X1 so you are subtracting X1 from X2 and  do the same thing for Y2 minus y1 as well and you   can get this with the height which we will use to  draw a rectangle so to draw it you can see we do   t Corner red and in here I want to draw  it on our video then I want to put it at x one y one yeah with and height so with this we are done  we can run this code now to check whether our   objects are being detected and we have a bounding  box across them but before we run it let's also   put the particular class name detected on it  so that we know we are getting a person we are   getting a ball and so on so also you see this one  for that resume Dot put text right so use the put   text rectangle function and then specify your  video specify the text you want to put on this   particular power video so here we are going to  put two texts that we will be putting the labels   and also the class name so Facebook the class name  for that you have to use F string so say F string   here then the first you want to put  is the class name or class detect then the second thing you want to put is the  confidence which in our case is confidence   then we can add the percentage sign  here so that we know it's in percentage go ahead and put the position where we want  this to be so it should be in your list so   we want to put it at X1 this positions  have checked so to put it at X1 Plus 8   and then I want to put it at y one  minus 12. so that would be cool if I go ahead and specify the skill too so the  skill is three by default I want to reduce it to   two so that doesn't drop big on our video footage  you can play with it to get different font size of   skin and with this now we can test it by running  our code so we are getting some errors here   CV2 dot rectangle DB box so that means you have  some mistake on line 40 so let's check this out   let me see so it seems um the mistake  is here we have to cast these values to   um integer values because as you are getting them  by default they are float so you have to cast them   to integer values so that we can use them so yes  come here before that I'll copy whatever they are   come to the next line paste it  and this is equal to eight of living box adding a zero then we'll do the same to the third index  so I'll just copy and paste this sound and boom here we go guys so we are having everything working together so you  can see the players have been detected   now see Cristiano Ronaldo dribbling  um other players as you do I play   so guys this works with only few lines of code we  are getting our objects in the video frame being   detected so all thanks to yolunas the team the  Desi company for doing or making this possible   will now continue to run inference on other video  files I have here so that you guys can judge the   Twins and yellow V8 which one works better to  your out of frames and now let's go to the top   instead of football.mp4 we can test um we  have test two there so test2.mp4 run it also okay so test two is an image so that's  test it should be test.mp4 so let's run it   that's why we got an arrow so guys  this works as well you can see it's   detecting the cars so this one feature I love  about your Lunas it detects things far away   before they even get closer to the camera  that means it's very good in doing that   so when you get closer then we get a nice  detection it's a car truck or we don't do   okay this is a car so this works great guys let  me have your opinions in the comment section as to   um yellow 8 and this one which works greatly let's  run it on the final video which is um video two dot MP4 so let me run this and here we go so  boom guys this is detecting quite well I'm   quite impressed with how accurate is detecting  the people immediately you see someone that's so guys this works this is very easy to implement  I have a tutorial session on the yellow ve2   how to do the same thing using your V8 so you  guys can watch both tutorials and compare then   let me know which one you think is better let me  put this way which one you think is more efficient   because I'm saying that yellow Nas is performing  here I don't know for you guys so you guys will   be the judge under the comment section so this  works I will be sharing the code and everything   on my GitHub repository if you like this tutorial  don't forget to share it with one of your friends   subscribe thanks for watching once again and  as usual I will see you in the next tutorial
Info
Channel: Tech Watt
Views: 1,029
Rating: undefined out of 5
Keywords: yolov8, segmentation, image segmentation, object detection, ai, machine learning, deep learning, pytorch, python, pytorch tutorial, computer vision, data science, pandas, programming, image processing, data processing, license plate detection, number plate detection, car detection, vehicle detection, image classification, python image classification, CNN
Id: dqHO1yDA-Os
Channel Id: undefined
Length: 28min 0sec (1680 seconds)
Published: Wed Jul 19 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.