YOLOv3 Object Detection with Darknet for Windows/Linux | Install and Run with GPU and OPENCV

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

Try https://github.com/ultralytics/yolov3 or the iDetection app for realtime YOLOv3 on iOS: https://apps.apple.com/app/id1452689527

👍︎︎ 1 👤︎︎ u/glenn-jocher 📅︎︎ Mar 04 2020 🗫︎ replies
Captions
[Music] hey everybody hope you're all having an amazing day and I have a great video for you today in today's video I will show you how to get Yolo v3 up and running on your local machine so that you can start to perform amazing object detection such as these by the end of the video you'll be able to run these detection yourself and have a better understanding of how Yolo v3 works and how to play around with it I'll be showing you the best ways to get Yolo v3 for both Linux and Windows machines so we've got you covered on both basis and I'll also be showing you how to enable GPU so that you can perform these object detection on both images and video in real time and get detection results back in milliseconds so let's get right into this video so first things first we need to get our hands on the code and so the way the Yolo v3 works is it works on top of an framework called darknet which gives it the capabilities it needs to be able to run the object detection so the repo we're gonna use is Alexi a bee's version of darknet so the original version version of darknet by joseph redmond doesn't really support Windows very well or at all really but Alexi a bee has kindly gone through editing and optimizing darknet for Windows as well so this repo works amazing for Windows and Linux so that's why we're gonna go ahead and click on the clone or download copy of the link and we're gonna go ahead and clone the code if you don't have get installed and of course you can just download the code and a zip and extract it to a folder so I'm gonna go ahead and clone it open up a command prompt or she'll get clone and paste that in there and it'll create the the repository for you I'm just going to show you guys where I'm doing this so I'm just doing it straight on my C Drive and repos folder and then there's darknut so as we can see it has properly cloned the code so now we can move on to the next step so if we scroll down and Alexia B's repo to readme and look at the requirements that's really what the next step is so you can decide whether you want to enable CUDA or OpenCV to be used with your Yolo v3 both of them help optimize so I recommend using both GPU CUDA allows you to accelerate the processing so detection x' instead of taking over 10 seconds will take under a hundred milliseconds which is crazy about 100 times faster and then aswell OpenCV allows it so that you can see or object detection in real time instead of having it to save it to a file and then opening the file and seeing your detection x' on the image so they both help greatly and I recommend trying to get both up and running and that's what we'll do next so firstly you're going to want to see it if you're computer has a GPU so you're going to go to device manager open it up and go to display adapters right here and if you have an NVIDIA GeForce or some type of Nvidia name driver then that means that you have a GPU on your machine so I have the GeForce GTX 16 50 GPU so next things for next things next you're gonna want to go to google and just look up cuda and then you're going to want to go to CUDA Wikipedia so CUDA is what you have to install with your driver in order to get things to work properly so you're going to scroll down and you're going to look at the toolkits so you're going to go and find your Nvidia driver on this list the newest versions are at the bottom so I had a 1650 or 1660 so they're both under the Touring model 7.5 and I can see that the Touring model means that I should be getting the CUDA SDK 10.0 which is the latest version so so if you found your cuda version and you now know what version you need you're gonna want to go to cuda download just google cuda download and then put the first link so this is automatically going to go to the latest version of the cuda toolkit if you need an older version you're gonna want to go to the legacy releases and find the version of your choice I actually have 10.1 downloaded but if you go back you can either choose the window or Linux version the version of whatever operating system you're gonna want and once you've downloaded it you're going to want to click on documentation and follow these steps the install guides for Windows or Linux whichever version you're on and follow those all the way through and now we can move on to the next step which is open CV so as I said before open CV allows you to view your object detection right away in real time as you're running the program and not have to save it to a file first and then open it so I recommend downloading open CV it can also help increase the detection time I'm actually gonna refer back to my previous video on my channel I showed how to download and install OpenCV from source so that's what you're going to want to go ahead and check out my video if you don't have open CV downloaded it'll show you the steps but you're going to want to tweak one thing when you're building the from source using C make you're going to want to scroll down and if you have CUDA if you've just downloaded CUDA and have the toolkit installed you're gonna want to click this with CUDA box and check the with CUDA box and then configure and generate the code this will enable your GPU with open CV and allow us to get that optimal performance when running Yolo v3 another tip when you're building open CV from source and enabling with CUDA once you've configured once you're gonna see this CUDA our spin property come up and it's gonna have all these different versions but I'm what you're gonna want to refer back to the CUDA Wikipedia that I showed you earlier and based on your driver and your GPU you're gonna want to check the version on the left side and see which one you are because if you're a 7.5 like I am or even a 6 or something you don't need all those previous versions and what it open CV will try to do is it'll build the architecture for all these versions so if you have like a 7.5 like I do you're just gonna want to go and get rid of everything below 7 or if you're 6 something you're gonna get everything below 6 and then generating the code from this will only build those architectures that you know you have and it'll help the build time of open CV with CUDA drastically decrease so that's kind of a best practice I recommend for you guys so now we can get back to actual darknet code so we're going to open up our where we put the code darknet and we're gonna look for the build file folder so right now this only has one folder in it so we're actually gonna want to build darknet from source now using c make and that'll generate the executables that we need and the solution folders we need to get Yolo v3 the last little piece of it together and running so now that we have all the requirements and dependencies downloaded and installed we're gonna go ahead and go over to the official Yolo v3 site so this you love you three thright is by the creator of Yolo you only look once and his name was joseph redmond so he has a demo if you want to see a cool video of him using Yolo v3 and he explains the process and everything he did and he shows you actually how it works but he only did it for Linux so if you're on Linux I recommend you now come over here and so he gives the steps of how to actually run you lo v 3 with Linux and on Linux if you're on Linux you're fortunate enough because it's extremely easy on Linux for those of you are on Windows such as my end like myself it's a little bit harder and we're gonna get into that but if you're on Linux all you have to do is do the command make and then you also have to grab the wait so you guys can do this double you get command and download the wait so if you're on Linux go ahead and run this command and get the wait files the wait file that shows has all the weights for the layers of the Yolo architecture so that all allow you to run your detection and we can actually grab it now even if run Windows so I recommend just downloading it by clicking this button and it's gonna go ahead and download and once it's downloaded you're gonna just want to copy it over to the root directory of our darknet project so I'm going to wait for that to download and then I'll copy it over so once our weights file is done downloading we're gonna go ahead and move it over from our downloads folder into our home folder of our darknut so we're gonna go ahead and drag it to copy it over perfect now it's in our dark net and now we can go back to the website the hola v3 official website and so there you can see different Linux the command is make so we're gonna go ahead and look at the make file that helps to generate when you run make so we're gonna just right click and open it with our notepad or any text editor or anything like that so as you can see off the bath or all these parameters at the start so this is where you set whether or not you want the make file to make darknet with GPU or with OpenCV so by default it's gonna do none of those but if you went ahead and installed CUDA and stuff like that then you're gonna want to go ahead and put a 1 so that will run it with GPU and if you have your GPU you're also going to want to do CUDA in a food NN but I would recommend not doing the half to start the half can add to a lot of complications so I would leave that as a zero and off and then if you also if you did open CV and built open CV from source you can go ahead and put open CV as a one and then you'll just save that close it and then from your command terminal you're gonna go ahead and run the make file by the command make and then you can actually go ahead and do your detection right away so for Linux it's that simple and this is the command you're gonna want to copy in and run and if you see an image with a dog a bike and a truck pop-up then you've successfully done it and it's that easy with Linux so if you're on Linux you're fortunate enough but if you're on Windows now is when I'll get into how I did it on my machine extremely fast and the best practices for doing it so let's get into that so if you're on Windows and you've just downloaded the weights file as I showed you you're gonna want to go ahead and open up CMake and you're gonna put in as the source code just the root directory of darknet and then for your build directory you're just going to go into the root directory and go to the build folder so that's it and then you're going to go ahead and click configure set it to whatever architecture you're on I'm a x60 64-bit machine and click finish and then you're going to go ahead and that's going to construct configuring and we'll come back when it's done configuring and show you the modifications to the parameters that you need to perform in order to either get GPU or OpenCV to be built with the source code so when it's done configuring as usual everything is going to pop up in red to tell whether or not your GPU work properly you should see that your seem a cuda compiler shows CUDA and the version that you downloaded and for the rest of this we're gonna go down and scroll down down down and we're gonna look at the enable CUDA so if you have CUDA and you downloaded your GPU Nvidia CUDA you're gonna want to go ahead and click enable CUDA and enable CUDA CUDA n but I I prefer like I said for Linux I prefer not doing the CUDA half so I'm gonna go ahead and unclick that one I find I actually get faster results when I disable that and then the next one is open CV if you've gone ahead and built two open CV from source and you have it working then you're gonna want to go in and enable open CV as well and now that's it you should have all of your GPU and CUDA files should automatically link so now we can go ahead and configure again and hopefully this time we don't get a new read fields and then we can generate so we can see perfect we don't have any red field so that means we're good to go ahead and generate the code so we're gonna go ahead and generate it's super quick it's done and if we head back now to our root directory of our darknet and in build we're gonna see that we have a lot more and we have a darknet solution folder so we're gonna go ahead and open that with Visual Studio and this is where we can actually build the code and then after that install it and have our final test to see whether or not we have successfully gotten Yolo v3 with darknet downloaded and installed so you're going to want to go ahead and change the version to release this optimizes it and then you're going to right click on all build and go to build so we're gonna let this run and then I'll come back and show you what the next step is so hopefully if all goes well fingers crossed you'll see that you'll get your build all succeeded none failed some common errors that I see here are that the dot Lib like it's missing an open TV I can't find an open CV dot Lib file and if that's the case you'll probably have to open up your folder for open CV and I find that if you go into open CV build install whichever compiler you used and then the VC 16 and the Lib is where you'll find all the dot libs that are attached with your open CV build and remember this is in your open CV wherever you build open CV from and then you're going to want to just right click whatever project it was that had the error go to properties and then go to linker and add it here to your additional libraries and that will usually fix it if that doesn't fix it and it's not a linker issue then you can add it to your additional include directory right up here and if it's a different file like not a dot Lib and it's a dot CPP or HPP just look in the open CV folder for wherever that file is and add that file path to the linker or the C C++ directories so once your build is complete you're going to want to go and right-click over install and then now you're gonna build the install and this will create the darknet executable that will allow us to do our u OV e 3 detections so we're just gonna build this this one should be pretty quick perfect one succeeded six up-to-date because it did not rebuild the other projects just to install itself so one succeeded so now we can actually run our detections so if you go back to your darknet root folder you should now see that there is a darknet application file so this is our darknet dot exe that we can executable that we can run and now do our detections with so we are going to open up a command prompt or B shell and now we can run this to this test command to see whether we have correctly installed darknet with Yolo so we're gonna do for us since we're on Windows we do exe not just the dot slash darknet detect and the first parameter is the config file so this is where the default Yolo config file gets placed in the config directory and then this is where you ever you downloaded the Eulalie through Yolo v3 weeds to earlier so put those in and then data folder is where there's a bunch of examples of images you can run the classifier on so this is just a picture of a dog with a bicycle and a truck so we're gonna go ahead and run this and looks like it's working this is through all the convolutional layers and if you have open CV enabled this will pop up right away where you can see the detection and so it saved two predictions dot PNG so if you just open up the folder and let's see if we can find it predictions oh it's a jpg and we'll bring that in and you can see that it has run the Yolo v3 detection and has found a dog a bicycle and a truck and if you actually go back to your command prompt it will give you the accuracy values so the bicycle was 99% accurate 100% accurate was the dog and the truck was 94 as long as well as with the time that it took so it took 87 milliseconds so you can see how fast that is it's real time detecting it right away and if you did not have GPU enabled that would be anywhere between like 7 to 11 seconds but with GPU you can see that it's down 2 milliseconds which is incredible so now you can go around and pretty much change this data dog slash dog jpg to any picture you want to detect on right now and so the detect command is actually a short form of a longer command that is being done so it's right here detector test is the long one detector test configure the config the data the config Yolo architecture the weights and the dog so you see that by default it actually loads in the cocoa dataset so this is has about 80 labeled in classes that you can distinguish between so you can see in our past example that bicycle dog and truck are within the cocoa pre train model and there's a bunch of other things if you want to check out what all can be detected using the cocoa classifier just Google cocoa dataset images and it'll show you all the classes and all the different types of things you can detect using the pre trained cocoa model so I'm gonna show you guys just what the Yolo v3 config file actually it looks like so if I go ahead and open to go to my config file go don't find the Yolo v3 here it is and we're gonna right click and edit notepad so you can see that it's set to testing which is perfect because that's what we're doing we're just testing the detector and it's just gonna do it once but if you're gonna train you can actually train your own custom model which I will actually show in a future video and this is kind of the architecture that shows all the different convolutional layers that the Yolo v3 architecture has and then there's also yo layers within here so they're all preset I wouldn't mess around them too much unless you're trying to become an expert with Yolo v3 and I'll show you how to mess around with them for a custom detection like I said in the few in a future video so let me know down below if you want to see that video so hopefully that'll make me get it done faster but yeah so it's set to testing on one image automatically so that's what you want for your your classifier there's a bunch of other models like tiny dot config which is a lot smaller for your memory memory so you can use it on more portable devices if you need like you could actually have it on a phone or camera yeah but you can I I'm urge you to play around with all these different types of configs just google them and look them up but Yolo v3 dot config is the standard pre-trained that works with the coke Oh dataset that you just pointed it to so I think that's pretty much it I'll just show you guys a couple more examples and how you can actually do it within with video but what you're gonna actually want to do if you're looking to see all of the functionality that you can do in all the different commands I urge you to go back to the beginning where we went to Alexia B's darknut his readme will explain to you guys a little bit more in depth what you can do and certain commands you can run in order to either suppress certain things or hide certain things so now I'm going to show you guys how to use the yellow v3 object detection on a video so it's pretty similar this last command it's gonna start with dot slash darknet exe detector instead of tests it's now demo and then you're gonna do the same stuff same parameters so you pointed out the cocoa pre-trained data your Yolo v3 config the Yolo v3 Waits but now you do the flag external output so this will show you the object detection happening in real time and then you point to the video so I have this video I put in this test folder you can use any video here like a video of yourself you walking on the street that's what you'll see in this video it's somebody walking the street in Asia and then this flag out underscore file name it'll actually save that your object you love v3 object detection overlaid on the video so that you can watch it back and see how it did and then this results dot avi just saves it as a result study VI file but you can call that anything you want so if we run this if we run it you'll see it'll load in the architecture so all the weights and layers and then as you can see it's running it as frames so it's going about 12 frames per second it slows down but you can see that it's detecting people car bicycle backpack and in real time so you'll see that when we actually get this saved to our results that avi file and play it back it'll be at full speed but the OL over three slows it down slightly so that it has time to do the detections so you'll see that once it actually finishes and we open it up the results are avi it will be in full speed and less blurry this is just a way for Yolo to do it easier so as it finishes up we'll get to see the video outputted with the overlay on top at full speed so now that the video detection is done we open up our folder and now we can just look for our results dot avi file so here it is we open it up and you can see that it's actually in real time as somebody as if it was just doing the texture on someone's phone walking down the street which is pretty cool it's pretty amazing what you all over you three can do so you can play around and use your own videos I'm sure you exit out of here and I'll actually show you guys another example with a image just so you can get more feel for it so I'll just change it so I was like I said you're gonna change this back to test keep these keys you don't need the external output you actually can do it for images if you want it'll just give you the bounding boxes and stuff like that which is cool and then so I'm gonna point this out one that you guys will have this is when it comes with it when you download it data horses JPEG oh I see an error there can't have two of those dollar signs and I need to do it dot slash direct net exe there we go and this will be a picture of a couple horses boom perfect so I think that almost wraps up the video guys once again if you want to learn more commands and how to play around a bit more you can always go back to the Lexy ABS darknet video but thanks again for watching guys if you enjoyed the video feel free to subscribe and like to the video what it means a lot to me and comment down below what videos you guys want to see if you want to see more Yolo view 3 videos maybe custom detection how to annotate your training images any sorts of stuff just let me know in the comments below thanks guys [Music]
Info
Channel: The AI Guy
Views: 82,238
Rating: 4.9333334 out of 5
Keywords: yolo, yolov3, darknet, deep learning, object detection, computer vision, install yolo, machine learning, opencv, gpu, cuda, ai, cnn, machine vision, neural networks
Id: saDipJR14Lc
Channel Id: undefined
Length: 26min 6sec (1566 seconds)
Published: Thu Dec 19 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.