How to Install Tensorflow 2 Object Detection

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey welcome back Ben again today we're taking a look how to install a tensorflow 2 and how to do some object detection so to get right into this the first thing we want to do is go to the official tensorflow GitHub repo and we want to clone this repository this contains everything we need to do object detection and whatever else tensorflow does actually but for our purposes we're focusing on the object detection and everything we need is right here so we're just going to grab this and we're going to clone it into wherever you want to put it so I have a little place where I have to put my projects and when you clone it it's just going to make something called models because that's the base of this so I recommend making another folder and then putting something and then putting it underneath it so we'll just call this like the TF2 that's good so we're gonna go in here and I'm just going to open up a command prompt and clone our repo and that might take a minute because kind of a big Repository all right now we finally have that downloaded all right so we now have you can see it here now it's appeared under our projects we have models and if you go into this there's a whole bunch of things that we're going to be going through but before we get into that we need to download a few other things so the next thing we're going to get is a protobuf and we need that to install some of the protalk files that are included you don't really need to know what they are or what they mean but we need to know how to install them so to do that we're going to go to this website and I'm going to link all the addresses or all the websites I go to in the description and I'm also going to have a GitHub repo that has a lot of the things that I do in there so we need to get the version that goes with our platform in my case it's windows so go down here and click show and this might look different when you do it depending on when you're watching this but what you want to look for is on that matches your system so I want the protalk version whatever windows 64. I already have it so I'm not going to download it again but all you need to do is once you get it unzip it and we're just going to move it somewhere where we're not gonna lose it so I recommend putting it in your python directory that makes sense I'll show you I already have mine but if we go to app data and if we go back one and go to local and we go to where is it programs this is this python folder is where your python versions are stored so you can see I have 311 310 Etc and this is where I put my download that we got so once you extract it or unzip it you're going to get this folder so I'd recommend putting it in here you can put it wherever you want just make sure you don't delete it and you also know where it is because the next thing we're going to do is go into this go into bin and you can see we have a protalk file this is the actual exe so we need to be able to call this command further on the project so we need to add this to our path so we're going to do is just copy this address that we're at and we want to edit the path so if you just type in path you'll probably get it here otherwise you can go through the control panel and so it's going to be edit the system variables and we're going to go to environment variables down here and then here you're going to click the one that says path we're gonna do edit and you would just click new and paste that directory in there I already have mine you can see it on this one above python that folder we were in the Pro talk blah blah you can't see the whole thing but it ends there it is it ends in bin so same place as in here toss it in there so now you'll be able to call this protalk command from anywhere so make sure you hit OK on everything yours might say apply if you're just adding it I would say apply right here it's okay back out of that cool so Pro talk is set up and ready to go the next thing we need is anaconda anaconda lets you have a little python virtual environments and this is going to make our life 10 times easier so I highly recommend doing this and I'm going to be using Anaconda for this so you can just press this download button again I'm going to have this link down below and it's just your normal regular installer like anything else so go through the setup instructions I believe there's an option that says add to path I'd recommend doing that so just make sure you download that cool so once we have that we can actually go into conda so I'm actually going to close my other ones so I don't get confused so once you're installed you should be able to say anaconda and open up a command prompt for Anaconda specifically anaconda and you can tell you're in the right one because it's going to have this little prefix in front of your directory So currently we're in the base environment what we're going to do is we're going to make a new environment that's going to encapsulate everything we do so we don't mess up all of our external systems or anything else and it's going to keep it all together which is really nice so we're going to create a new environment so do that we're going to say conda create you can do dash n for name and then you're just going to give it a name so I'm going to call mine TF2 like that and then you're also going to say hip and python equals 3.9 and this just tells it we're going to be using pip and we're using python specifically 3.9 at the time I'm making this most of tensorflow 2 the dependencies that it has and the libraries require 3.9 or it's kind of like the middle ground of where everything works so I recommend using this one but if this one doesn't work if you get install errors later saying like wrong version you can change this to be a different version of python but as of the time I'm making this python 3.9 definitely works so we're going to hit enter this might take a second we're going to say yes or Y technically and this might take a moment all right and then it's giving us little instructions so to activate it we have to say conda activate and then the name you gave it so that's what we're going to do kinda activate TF2 and you'll know that has worked that has worked if you get this little thing this little prefix in front of it changes so whatever name you set should now be here so now we're kind of in our own little separate environment cool so while we're in here even though we just downloaded protobuf separately and put it in our path we also need to download it as a package just so that the environment and tensorflow itself knows what we're talking about because for some reason they can't talk to each other so we have to do it separately and instead of doing pip install we're actually going to do conda install install protobuf now I couldn't tell you exactly why you can't do pip Proto buff you can do it but it's not going to work for some reason it just really there's a couple things we're going to do another do this another time too where installing it directly into conda is like the more Surefire way to make it to work because we're putting it into the environment itself so by doing conda install Proto buff we're kind of doing it as like the whole environment so it just works better for whatever reason I'm going to explain why it does but it just does and over a pit cool so we got that that's cool we have our directory installed so now we are going to navigate to that project we made so a tf2 I'm just going to copy this directory and back inside of conda I'm just going to say CD paste that in there and now you can see we are under that project that I made and so next we need to go to models slash research just like that and if you do a dirt you can see there's a whole bunch of things in here which is good that's what we're looking for all right so now we actually need to write a tiny little Python program that's going to take care of all the rest of the Proto buff stuff for us so further in here they're under object detection there's a protos folder and it's full of files that have the dot Pro talk extension so we need to initialize those basically so this little Python program sorry we're going to do this is going to go to each one and activate it so I have this code off to my side but again this is going to be in my repo so let me just get a new one and let me copy it over I'm just using notepad plus plus because it's pretty small and I'm again I'm not going to go over it because it's pretty simple but we're just going to go save that into our project so where did I save it pie charm TF2 models make sure you put it under research because that's where we were at we were under models and then research so let's make sure you're putting it in the same place something's going to call this use protobuf dot pi that's important and you can see that worked as now everything kind of has the highlighting cool so now that we have that it's for Haas I'll do a Dura again and you can see that we now have Proto use protobuf in here same if we go into our directory in here it's in there great so now we're going to run that script so we're going to say python if you use underscore protobuf and then we're going to say object detection slash protos that's not going to autofill for me let's say protos and then protoc this is basically inputting the directory we're looking at and then this is the command the commands is protalk so that's what we had to edit the path so that we could say this otherwise you wouldn't be able to say Pro talk so we're going to do that there we go must have missed and there we go shouldn't be any output unless something went wrong and cool so that's all set whoops okay so now we need to copy a setup file so if you go into if we go back into the file explorer we want to go into object detection and then we want to go into packages and then TF2 make sure you're in TF2 and there should be one file in here so grab this we're just going to copy it and we're going to go back we want to be back under research make sure you're in research paste that in there and now back in our little environment we want to say pip actually whoops my bed I'm gonna say python Dash M pip install period this is just going to look for a Python program name setup or I think they can have another name too but it's going to look for our setup python file so we're gonna hit enter and this is going to take a long time I'll warn you that right now so I'm probably gonna do a little time cut skip because this can take a few minutes so I'll see you when this is done downloading all right that's finished downloading took a couple minutes and now we can continue cool so we have that uh we have to do another conda install because for some reason numpy is included in this but doesn't download correctly you can actually see it right here but uh you're almost certainly get an error later for this numpy because for whatever reason the install of numpy that comes with this is broken and I found that the best way to fix it is to do a conda install so we're going to say conda install numpy like that and it's going to ask us to confirm say yes that'll take a second again it's one of those things where it just works better if you do it directly in deconda I kind of tell you why but it solves a lot of problems all right so we have that so now we can actually test to see if everything is installed correctly so to do that there's actually a built-in testing file that they've included so I'm going to say python object detection slash Builders not there we go Builders slash [Music] um autofill no okay my bad model Builder a long one t f 2 underscore test by sorry okay there we go and you'll probably see some warnings if you don't have a Cuda GPU I do not that's okay and you can see these tests are kicking off and running take a couple of seconds nothing seems to be breaking so that's always good news and there we go and go if it ran successfully you should see something like this ran 24 tests uh the number of tests may be different depending on when in time you're doing this it might change but you should see a bunch of runs and oks and as long as there's no glaring issues like no air is popping out we should be okay so now we're going to move over to an IDE and uh well technically we've finished the install and since this has worked we have successfully installed tensorflow 2. so congratulations if you made it here and everything worked so just as an example I'm going to run through one of the example scripts that lets you test it and actually do some object detection on some real images so I'm going to open up a IDE I'm going to use pycharm uh you don't have to use pycharm but I like it so that's just the one I'm going to use and the rest of the tutorial will be more specifically towards that but you should be able to continue even if you're not using pycharm specifically and I'll show you how cool so let's go to our project so this is my project I'm just going to go up here and open this as a project for pycharm I'm going to trust it and again you could do this in vs code or whatever else you want to use I just find pycharm to be easy all right so we're in here and we're going to do is that again pycharm specifically I'm going to add an interpreter and you can actually add the conda environment we were using already which makes it really nice because we don't have to go back and forth between that terminal and here we can do it all inside of the pie charm so if we click on conda environment you should be able to do existing environment and you can actually see the one we're using is here you can see environments TF2 might be kind of small but it's right there if you don't see yours showing up you can use the dots to browse for it this path should be very similar if you installed it in the default location users your username Anaconda 3 environments and then you should be able to click on the one that you had so I really like that this the pyterm has this feature so we're going to do that and now one of the downsides by charm we're still probably happen in vs code too actually is that it needs to it's gonna like basically kind of configure itself to understand all the libraries and dependencies we have so you can see down here in the corner we have updating skeletons and this might change this takes like five to ten minutes which is kind of annoying so yours might be similar once you do that so I am going to cut the video and I will join you guys back when this is done loading okay cool okay cool looks like we have finished doing all those dependencies and updating so now we are ready to do some detecting so I'm going to open up so you can see the directory here render models we're going to go into research and then we're going to go into object detection this folder is kind of where everything happens as you might have seen so far and I actually have a couple of scripts I'm going to move over so I'm going to bring these two over and I'll show these to you guys I'm just going to paste these in here click okay don't need to add to GitHub okay so I've pulled these scripts from another example online from I think his name's Gilbert Tanner I'm definitely going to link him and actually the repo I'm going to share with you guys is a fork of some of his work so big shout out to him and his tutorial that he wrote up um a lot of this is actually based on that but I noticed that there were some discrepancies so the thing with like numpy and like protobuf he doesn't really explain how to do that or potential errors you might have so I thought it would be a good idea to kind of elaborate that on a video so again I'm definitely going to link all that in big Shadow to that code so and again since this is mostly an install video I'm not going to talk much about what this is what this is doing as for a lot of this we don't really need to understand the code as a lot of this is just setting up the models and whatnot but I'll show you guys how to put in some of your own images in your own model so to start we're going to use this model downloader and all this is going to do is download a model for us so I'm going to open our terminal real quick because you can see I'm missing wget and then here I'm actually going to say conda activate although I think it's activated by default just in case df2 I think by default it's activated if you do the method I did so we're going to say pip install wget and W gets just a library that can down links from online it looks like that worked so this dot this download link is from the model Zoo and this is where tensorflow has official models that you can use I don't want to use this model though so I'll show you guys how to get different models so if we go to here so this is the detection model Zoo again I'll link this below these are a bunch of models that you can use that are pre-trained which is awesome to use and they're kind of sorted by speed and this measurement I'm not really sure what that measurement stands for but it's kind of like the performance measurement so if you're doing this and you don't want to use the same one I'm using you can kind of get a you can make a comparison of the speed trade-off for the performance trade-off because you'll see some of these run really slow but they have a much higher rated performance so you can see this one it takes a lot longer like 133 milliseconds but it has a 48 score where some of these take like six seconds but their scores are much lower so the one that we're going to use this is SSD mobilenet this is a good standard one to play with because it's pretty fast and it also works pretty well so this is a good one for us to test with so to download this model we're just going to right click it on this link we're going to copy the link address we're going to bring you back over here I'm going to paste that in and we're going to copy this last half and we're going to put it into this the f this second half of the program just unzips the file we get the file we get is a tar gz which you can't unzip normally on Windows you have to use a tar file because it's a special thing so all it's going to do is it's going to extract that folder and just put it into our directory so let's run this if you're not in the IDE or using a different IDE you can also just run this in the terminal by just saying python model downloader after you've edited it wherever but I'm just going to run mine from right here but again you can run it from the conda terminal if you want to also and we can see that finished some of the bigger models take a lot longer to download and you don't really get any uh message here about download so don't be afraid if nothing's really happening for a couple of minutes if you download a different model eventually it'll either time out or actually download it and you can see on the side now we have SSD mobilenet down here so I downloaded the tar and then it extracted it into this folder here which is what we want great so now we have that we can open up this other file so I've made a couple edits just for the sake of this tutorial specifically I removed some of this and I made it so that we can actually view the pictures uh because technically this was originally made for a Google collab or a Jupiter notebook and the map plot lib doesn't have like a GUI feature so just to make it easier instead of trying to show it we just saved the figure to an outputs folder and we can view it after we run it so that reminds me we actually need to go to our side here so under object detection let's make a new directory we call it outputs I mean you can call it whatever you want that's just what I used here because I said we're going to save it in a folder called outputs and to run this command to run this program sorry we have to oh I didn't jump we have to tell it a couple things let me just paste it in here so we're just telling it the file this is what I originally I think this since I copied this over this is actually wrong my bad let me fix that um so the first one's just the name of the file the second is the model as you can see I have that model already in there what is this is called Tech underscore from image like that so see Dash m is the model we want to use just make sure you do the slash save the model if we go to this folder over here where we have it you can see another folder saved model and what this program is looking for is technically this saved model dot PB so we just need to tell it to look in this folder oh we also have a thing for labels and these labels are what's going to be the thing that shows up on the screen that says what each object is so we can get that from data and there's a whole bunch of different labels in here for our purposes we're just going to use the MS Coco label map and that's just going to be basically all the labels for normal everyday objects and then this is going to be where our test images come from and you can see we also have a test images folder in here I'll actually open that up so you can see what it is ahead of time I think that's like a dog and stuff yeah so these ones are some dogs beach pitcher and some wood shop cool so we're gonna run this oh whoops I messed up I says detect from image pi cannot be found I oh you know why I'm in the wrong directory silly me we need to this is the whole idea of everything happens under object detection of course I didn't put myself in there so we need to go to CD models research object detection there we go there we go my bad again you may see some errors about Cuda if you don't have a Kuda GPU and again that's fine if you don't have one just like me we're running this all on CPU depending on the model you use this will take longer like we saw on that page you could see like the uh the millisecond reading so this one's pretty fast so it shouldn't take too long and that's done so we told it to save in outputs and you can see now there's some things in our output folder so we're going to view it in the Explorer though test images go back one and outputs and you can see that these pictures are now a little different so we're detecting some dogs seeing a person in the background very nice this one has a lot of stuff going on got some kites people lots of things going on so cool this definitely worked this one's a little low res once it spits it out but I can tell this is a person so awesome we have successfully detected objects using tensorflow 2. and you know the sky's the limit from here um and that original repo that we have he also has uh Gilbert Tanner has some examples on detecting from a webcam that you can do also that's very similar to this or I might make a video that also does it so yeah definitely let me know if you guys want to see some more things involving tensorflow 2 object detection we could do training a model from scratch to detect custom things we could do like the webcam if you want attacked from a video a set of pictures you know let me know in the comments and uh that's all I got so if you like the video like I said leave a comment leave a like subscribe thanks for watching and I'll see you in the next one foreign [Music]
Info
Channel: Lazy Tech
Views: 24,464
Rating: undefined out of 5
Keywords: tensorflow, tensorflow 2, object detection, tensorflow 2 object detection, object detection api, numpy, protoc, protobuf, python, machine learning, object recognition, custom model, ai, Artificial intelligence, Neural network, Tensorflow object detection, Image, Image classification, Anaconda, Video object detection
Id: rRwflsS67ow
Channel Id: undefined
Length: 26min 33sec (1593 seconds)
Published: Sun Dec 18 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.