YOLOv4 in the CLOUD: Install and Run Object Detector (FREE GPU)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] what is going on guys first off I hope everyone is safe and well I've got a wonderful video for you guys today today we're gonna be going over the amazing Yolo version for which if you are unaware of it came out late last month it's a heck of a lot faster than you low low version three and more accurate and it has a lot of new features and parameters so we're gonna be covering that today and how to run it in the cloud utilizing a free GPU your that's right if you're stuck with out a GPU that is no longer a problem you have a free GPU in the cloud and we're gonna be running this in Google collab I'm gonna show you guys how to install all the dependencies get everything up and running similar to a previous video I did on yellow version 3 but this one has a lot more in store for you guys you guys gonna be able to run on video in the cloud as well as have a lot more parameters multiple images you can run it on at once and stuff like that we're gonna be taking advantage of the new Yolo version for weights and we're gonna be running our own detectors in the cloud totally for free so I hope you guys follow along and enjoy the video it's gonna be a pretty packed one with info so stick around for the whole thing and let me know what you think down below in the comments means a lot Thanks so in order to access the notebook itself and to follow along there's two ways you can do so the first is to click on the link in the description for the notebook and it'll pop up something like this and then all you're gonna do is go ahead and click open and playground and once you click that it'll go ahead and bring you into a version that you can actually connect to a runtime and access the GPU and run in the notebook yourself and I recommend then just copying it to the drive and that will prompt you to log in to your Google Drive and actually save the club notebook that you are working on in your own Google Drive so if you don't have a gmail account it's easy to set one up and I don't even know if you need a gmail account to connect to Google Drive you might be able to sign up with a regular account so that's the first method method it's just click on the link and then playground and copy to drive and then you can follow along here and then the second method is actually to just go to the repository the AI guys code you'll be for cloud tutorial either clone or download the repository and all the code as a zip file and actually you can access all the images and videos that I use in this tutorial right here you can download the exact images I use in the videos I use to follow along exactly as I do and everything else you can find is here and then you download it or clone it and then you just open up Google collab and go to file and upload the notebook file and then you should have you will have it here as well you might miss some of the photos as they might not upload properly straight from the github repository but so I recommend the Google Drive method but once again it's always good to have the exact images and videos that I follow along with so either of these two methods works alright so first things first to get the most out of this tutorial you're going to want to enable your GPU your free GPU in order to run Yolo version 4 with GPU acceleration and have it run up to a 100 times faster than if you didn't enable GPU so I have some pictures here to how to show how to do that I'm going to show you two quickly so you go to edit notebook settings and then this will be set to none and you're gonna go GPU and save and then it's going to go up here and say connecting initializing and then if you see this checkmark with RAM and disk it means success successfully enabled your GPU and you're now good to go with the rest of the tutorial so after that we're gonna clone and build darknet this is the famous framework that allows us to actually run our Yolo detections so it's pretty easy and quick it's just couple commands here just these four commands and if you want you can just go to runtime and run all and that'll actually start kicking off running all the cells otherwise you're going to have to go up in this corner and click the play button and that will run one cell at a time but if you click the runtime run all kind of speeds it up a bit so it's cloning and Alexei B's famous darknet repository which has all the code and then we're gonna go and change the make file so if you actually go to the files now darknet wasn't here originally but we've cloned it in to our cloud vm or co-op workspace and we now have darknet and all the code and this make file is what actually builds darknet from the binary files and allows us to that have an executable that we can call to run yellow detection x' so this second cell actually just in line changes and enables OpenCV and then also GPU so it's gonna build darknet with GPU acceleration so that's gonna go ahead and allow us to run all of our detections much much faster and then we're just verifying that we have cuda I indeed have cuda version 10.1 on your Google Cloud workspace so you all should also have either ten point o or ten point one it doesn't matter and then this last make command is actually what builds darknet for us so that we can run you although and there's might be a bunch of warnings but don't worry that's normal and it is still we're gonna work so once it's done we're gonna let it finish and then we're gonna download the pre trained Yolo version for weights so we although version four I was actually pre trained on 80 classes of the cocoa dataset which is a huge data set of over millions and millions of images so it's already trained on 80 classes and it allows us to easily just grab the weights and begin running yellow version for detection x' so that's what we're going to do so it's really quick and went and got it perfect we now have we should be able to see if we close the darknet and open it again we now have Yolo v4 dot weights so it's already now in with our darknet folder so that's good to go then after that we define a couple of helper functions that if you saw my previous video be aware of so M allows us to open images within google collab because the native OpenCV viewing of images doesn't work we get a warning so we have to write our own function and then there's also this upload function which allows us you'll see later to upload a file from your local machine and as well as download which allows you to download a file to your local machine so now that we have that our next step is to run our detection with darknet in Yolo v4 so it's really quick you can see we're already to the step we're about to run detection x' and you can actually go ahead and see all the different classes that come pre trained so if you just click on these or hover over them it'll show you what you can detect so with bird dog horse you can just go through and play around so you might not even have to create a custom detector it might already be included in the cocoa data set which is huge so now if you follow along I've shown you guys and what you have to run for the commands the pre trained model config files and data files are already in the darknet repository for us so all you literally have to do is run this SEL darknet detector test that's the command point to the data file the config file and then the weights that we downloaded and then to an image and if you actually check the pre downloaded repository there's a bunch of images in this data folder giraffe Eagle dog person scream horses a bunch of already images that you guys will have when you download the repository so you can see that you get these warnings this is it trying to open the image by itself but we got to come a bunch of warnings because OpenCV you can't automatically to do the detection x' and open the image at the same time in google collab on your local machine it would be able to so that's why we have em show right after cell right here G OH puts the image for us and we can see it was detected a dog with 99% accuracy person with 100% and a horse with 98 and that's exactly what we have here printed drawn on the image and every time you run dark net detector test it saves your detection x' to predictions dot jpg so if i close and open it back up we should see predictions JPEGs somewhere in this folder I'm pretty blind there it is right here predictions JPEGs so that's where it'll save your detection on each image until you do another one and then it will overwrite it so we can see that yellow version 4 is working and it predicted the image in 32 point 7 milliseconds which is unbelievably fast not even a fraction of a second like literally just 32 milliseconds so extremely extremely fast then this cell here is just 2 when you run the run all this will fail and stop from running more more cells because that requires you to have your Google Drive linked which I will now show you so there's two different ways you can run images or detection zhan images within your Google club notebook you can either upload local files or access Google Drive files that you have on your Google Drive immediately to use so there's these two different ways two different methods both work exactly the same I recommend a little Drive way just because you can easily do it and have the predictions actually saved to your Google Drive as well and output videos so that's pretty much why it's easy to have all your stuff in one place so first method is the local files so you can either go here and upload directly to your session or you can also do this command that I've shown one of the helper functions upload so if you run the SEL here it's gonna run the upload and then you can see that it's trying to upload a file so I just choose a file I'm gonna go to my downloads and I will choose this highway image so now I've uploaded the highway image to my root directory so if we go back and back we can see it's here in the root directory of the workspace so now we can actually run our yellow version for detection x' right on image that I just uploaded so we're gonna go ahead and run this next cell and it's gonna it's gonna do it on any image that you uploaded so make sure to change this highway JPEG because it won't be necessarily the same but if you took the highway JPEG from they might get hep repository then you can actually do it straight on this image as well so we can see 32 milliseconds it detected all these cars and a truck and then if we actually look because we'd ran the em show function we can see that indeed found all these cars and truck on this highway image which is pretty sweet and it did it once again extremely extremely fast so that's the local method the next method is through Google Drive which is really really cool so you can actually mount your Google Drive into this collab workspace and access all your Google Drive files in the collab so we're gonna go ahead and do that so we're gonna mount it so we're gonna go ahead and run this command and then you're gonna hit this link and it'll show you an authorization code and then you're gonna paste it in here so click on the link choose my account and you're gonna allow this just allows you to see all your files copy click the copy button and then come back in here and paste it in and then hit enter and that's gonna activate now that your Google Drive mounted in to this notebook which once again is really useful and then this next cell creates a symbolic link so instead of it being normally my space drive I'm just gonna replace this whole string path with my drive to make all my stuff way easier later down the line when I refer to images I don't have to refer to them as my drive slash images or whatever instead of content G Drive my drive just makes things a little easier and now you can actually see that once I run this LS command you can actually see the folders that I have within my Google Drive so if I go to my Google Drive I have images videos Yolo v3 and you go with v4 as folders and that's actually exactly what I'm seeing so I've successfully mounted my Google Drive into the collab workspace so now I'm going to head back into the darknet folder because we backed out of it and I can now run on an image that I have in the images I have this street picture so I'm going to go ahead and actually run the detection x' right into my Google Drive so this is what I said the my drive comes in handy because otherwise I would have had if you didn't do this command you would have had to paste this whole path in here so just a little time saver so we're gonna go ahead and run it and we should now see that it did it on that street image so once again 32 milliseconds and there's all these detections it was a busy photo lots of stuff going on and there we go you can see a car people cellphones handbags backpacks traffic lights even so you can four and the pre-trained weights that come ready to go out of the box on tons and tons of classes so we're really seeing the power of that and how unbelievably fast it is so you can also download files for to your local machine or Google Drive from the cloud VM so now we're gonna go ahead and do that so to your local machine all you have to do is run the download helper function and then point to the image or file you want to download so it's as easy as that we're gonna go ahead and run that cell and you can see it downloaded the predictions JPEG to my local machine not going to go ahead and open it you're gonna have to believe me that it worked and then also you can do this copy command to copy files from your collab workspace to your Google Drive and it's gonna call the predictions JPEG it's gonna rename it detection one and you can just keep changing this and running it as you do new images and it'll save them all to your Google Drive so go ahead and run this cell and now if I go back to my Google Drive and back into this images folder oh there we go I saw it that appear back to the images folder we now have the save predictions JPEG under the new name detection one that I just called it so it successfully saved it to my Google Drive so which you can see how it's pretty enough T to use the google drive and everything is saved instantly into whatever folder you want I have images folder so that's where it's saved and under detection one so next you can actually run Yola version 4 on video in the cloud which is something I didn't cover in my previous tutorial and you'll yellow version 3 so this one is actually gonna be able to run video in the cloud which is pretty pretty sweet so I'm gonna upload a video and I'm also going to do it through Google Drive so I'm going to show you both types again so uploading I'm just gonna upload this test video that I have mp4 I pretty sure it has to be mp4 I'm not 100% certain but I'd recommend mp4 and then once it's done we will run this command which is similar but it's gonna has a file name saving at two results dot avi so it's gonna save the video showing the detection displayed to the results dot avi you can change this name to whatever you want but make sure you run it with these flags that this don't show one is key because other otherwise it will keep trying to output the video and show you and as it goes in real time but that doesn't work in collab so keep away from that so now we can run the command and you're gonna go ahead and see that it's loading up the weights and it will actually run going through frame by frame and it's pretty pretty pretty quick so you're actually gonna see that it's going through and doing the detection and it's adding it at an average SPS of twenty one point two frames per second so that's actually really fast and it's faster than what Yolo version three was the previous version so I think it's around 12% faster and it's gonna go and through and then it will save it in this folder as results dot avi and then once again if you want to you can just download it to your local machine or do the Google Drive saving so I'm gonna show you right now after it downloads that well I can open it up for you guys still downloading actually so we're gonna go ahead and let it wait one sit down with multiple files Wow so let's go ahead now and go to my downloads and we can open it up and let it play and we can see that indeed is working and it actually detects the percentages on the screen as well so it's just a six second clip once again if you want to access this video you actually can do that by downloading it from my repository that the link is in the description of this video so now we're gonna do it straight in Google Drive we're gonna take the video from our Google Drive I'll show you that it's in this videos we have the exact same video and then we're actually going to save the results immediately to our Google Drive as well so it's gonna save it to the same folder and once again Stan we call the results API so the difference between the command for images and video is this demo part demo means it's a video and test means it's an image so this one command replaces the previous three that I showed you and it'll go ahead and save it directly to our Google Drive which is pretty sweet don't have to worry about running that download command and if you accidentally close your Google Cloud workspace and it shuts down you won't have that results that AVI file saved here like won't people access it again if you didn't download it but running it straight into your Google Drive allows you to always have it saved so let me just go to my Google Drive video and once again we have the exact same file with the detection Zoe up saved now to directly to our Google Drive so next we have certain custom parameters and flags that you can add to the darknet detector test command in order to run it with certain customizable and flexible outcomes so you can actually have a very or you can actually stack them and add multiple flags at once or just one so there's this threshold flag which is pretty cool it allows you to run the detector and only output and show the detection x' for detection so that are above the confidence threshold that you set so if I run just without the flag on this dog jpg that you have in the data folder you'll see that it outputs for detection it has bicycle dog truck and potted plant and potted plant it's low accuracy and it's actually a garbage can with this tree hanging over top and it thinks that that is a plant because of the base and the leaves which we know it's not good and it's actually not an accurate prediction and as it says it's only 33% certain that that's a potted plant so to remove the low percentage detections we can actually add this Thresh this threshold flag - Thresh and then a value so this will say only output detections and show-me detection x' above 50% confidence so we run it on the exact same image now on dog jpg which you guys all have so this will work for you guys you'll now see that it has indeed removed the potted plant because it was under 50% it was at 33% and it no longer detects the potted plant which is good because it was not a potted plant it was a garbage can so the next parameter you can add is the output bounding box coordinates this flag is - external output and it allows you to it shows you the coordinates of the bounding box as well as the height and width so we're gonna add that flag and just run the command we're gonna run it on person JPEG this time and you'll see that it comes back with a little bit extra information so here is what external output gives you it puts this information here it gives you the the top-left corner I believe of the bounding box and then the width and height which you could use to then draw on the image but it already does it for you but if you were trying to create some application that needs the coordinates this is one way to do it and to get it so it would actually give you these coordinates here the top left corners and then also give you the height and width so that you could have the other another corner as well so another flag that's useful on a local machine but not necessarily in the Google collab is that don't show that don't show flag - don't show allows you to run character their detection the detector and not show the image afterwards because by default it tries to open the image after every detection it tries to show show you predictions jpg and that causes this this warning that I showed you the beginning connection refused and that's why we use the helper function in show to output our detection x' so by running this it will see that we don't end up having those warnings anymore so we no longer have the warnings that we had above so if I go up here we had these warnings could not and got unable to knit server we no longer get those because it's no longer trying to open the image directly with OpenCV in the cloud workspace so the last thing I have for today is step 9 which is multiple images at once so you can actually run you over for object detection x' on multiple images just through one command so what you have to do is just set up a dot txt file it can be called whatever it wants and then you're gonna do like this example here so once per line you're gonna have a path to an image from whichever wherever you're running the command so if I was running the command from this darknet repository I could upload the txt into here and then if I wanted to have an example I could do it on these images in this file here giraffe eagle and dog and I would just have as my file path data slash dog jpg but for my example I'm going to be using this images txt file that I have in my root directory or home directory of my Google Drive and I will be running it on these three images here you saw I run I ran it on a couple of them already earlier but I'm gonna show you that I can run it on all three at once using one command so you can save your results as a JSON file or as a txt file so I'm gonna do both so I will run it first as this JSON file and you're gonna see that it runs perfectly on all three images so it's got the first image straight and then it's got the second image highway and after you might that's all three I think yeah that was plane first up here then Street and highway so it's got all three and did all these detection x' and then if I download the result JSON file and show it and folder and I will open it with notepad plus plus you can see that it returns in this nice pretty nice format where you have it shows you that it was the first image second image through the frame ID and then it gives you the class ID the name and the relative coordinates all in a JSON body so yeah feel free to investigate using the JSON way but now I'll show you the second way it's the results as a txt file so same same thing and then you can download result txt as well and you can feel free to change the where it saves it so instead of out result but JSON you could have that as my Drive result that JSON and it would save into your Google Drive so that's like I said I got it makes it easier instead of having to do the download right after and in case the workspace shuts down you don't lose that file so now let's go download the txt and we're gonna go show and folder and then open that with notepad plus plus as well so you can see this is a little bit different and not as clean it actually outputs everything that's in that output window so it's a little bit less clean and it really it just writes exactly what's in the output window straight to the results dot txt instead of outputting it here in the display it just puts it into the text file so that's it for this video but I will have shortly coming up how to train your own yodel version for custom object detector as an add-on to this cloud workspace and show you how to do it completely in the cloud using utilizing the free GPU but I hope you enjoyed this video and feel free to smash the like button and subscribe to the channel so you can see my videos as they come out means a lot and it helps me grow so if you enjoyed it please like thank you [Music]
Info
Channel: The AI Guy
Views: 57,034
Rating: undefined out of 5
Keywords: yolov4, yolov4 cloud, darknet, object detection, yolo, custom object detection, train yolo in cloud, object detection classifier, google colab, cloud, install yolo, yolov4 tutorial, yolov4 cloud tutorial, yolov3, yolo v4, yolov4 darknet, deep learning, tensorflow
Id: mKAEGSxwOAY
Channel Id: undefined
Length: 27min 40sec (1660 seconds)
Published: Wed May 20 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.