How to Build an Object Detection Classifier with TensorFlow 2.0 on Windows/Linux

The AI Guy · Intermediate ·👁️ Computer Vision ·6y ago

Key Takeaways

This video demonstrates how to build an object detection classifier using TensorFlow 2.0 and Yolo v3 on Windows and Linux, covering the setup, configuration, and deployment of the detector for images and video.

Full Transcript

[Music] welcome everybody in today's video I'm going to be walking you through building your very own object detection classifier using tensorflow 2.0 I'll be walking you through the process and code from start to finish showing you the commands necessary so that by the end of the video you will have an object detector that will be able to detect classes of your choosing within images and videos in real time this tutorial is meant for people with either a Windows or Linux machine if you are new to the channel please subscribe to the channel and smash that like button down below I promise it will bless your object detector with good luck and make it work even better well not really but please do it let's get going alrighty so first things first we got to get the code so you're gonna head over to my repository the AI guys code and it's Yolo v3 I'll leave the link to the code down in the description below so you can get access to it easily and a quick disclaimer before we get into the video I forked this code from Hart Killa who had an implementation for tensorflow 1 and then I adapted his code for tensorflow 2 and added some stuffs for custom trained weights showing how to use custom trained weights so yeah so this is a Yolo version three object detection with tensorflow 2.0 if you don't know Yolo v3 is one of the fastest object detection frameworks it's in real time pretty much and if you want to learn more about that you can go here and go to my youtube video showing how to actually train a custom Yolo version 3 model as well as how to install Yolo and stuff like that and so yeah this is going to be how to build the object detection with tensorflow 2.0 so let's get into it first things first we're gonna want to go over and first click on this so we can actually clone it so we've copied it open up a command shell and just go get clone and we'll paste that in there so once you get the code you're just gonna want to CD into the repo and I recommend doing code dot to open up a vs code if you have it or any other code editor just to look at the code so we're gonna go ahead and do that and that opens up vs code and so we have a couple different scripts and a couple of different folders so first the tech dot pi is what actually runs the detection and you can do detection with images or video it works with both and then you can also have your Yolo version 3 which is the actual building of the model itself and then load weight so load weights is the big one it will take your Yolo v3 weights format and convert it to tensorflow model dot checkpoint files so that's really the big file and that's where we're gonna start so we'll just head back to our repo and follow the steps so first is to install the requirements so you're just going to go down your command prompt and pip install - our requirements dot txt and this was gonna go ahead and download all of the dependencies that you need I already have them all so you can see that it's already satisfied but that'll go ahead pip install - our requirements will get you all the dependencies you need to get yours tensorflow environment setup so if you're on linux you're gonna go ahead and download the pre trained weights we're using the weights for the cocoa data set if you don't know the coca data set it is a data set that is pre trained for over 80 classes of images so you can go ahead and google cocoa classes data set classes and it'll show you the list of 80 classes that are trained in the detector will work on straight out of the box so that's pretty sweet we're gonna take advantage of this but it's got loads and loads of classes and a variety of things like skateboard different fruits animals people cars like it goes on and on so if you're on Linux you're gonna run this command W get but I'm on Windows so you can actually just go ahead and click here it's gonna go ahead and get the Yolo v3 weights so we're gonna wait for that to download and then we're going to move it into our weights folder so it's a large file so I didn't want to put it in folder itself so I've just showed you guys how to download it but you're gonna put it in here and if you're using a custom I'll show you right now if you're using a custom classifier so if you check out my previous video here how to train a custom object detector for Yolo and get the weights you would put those weights into the weights folder and you would have to change a couple files like your cocoa name so that you know the classes you're pointing at as well as the weights themselves so the couple changes for you to allow you to do your custom trained weights but so if you want something in specific that's not already in the cocoa you go ahead and watch this video generate the weights file and come back and now and stand up your tensorflow object detector so it looks like our weights is downloaded so we're gonna open up our Yolo v3 where we download cloned it to so and I did it my C Drive my repos and this is the one we did and you're gonna go to the weights file weights folder and you're just gonna drag in your uo v 3 dot weights into here that's perfect so it'll be in your downloads so you can just open up and go to your downloads and then copy it in as well so we've gone ahead and we've got our weights so now we can actually load the weights so you're gonna open up your command prompt again and is a super simple command this will generate the tensorflow checkpoint files for the detector it's just Python load weights dot pie and you're just gonna go ahead and run the command doesn't take any parameters it works just like that and then so if you were to change it you would go down here if you a custom detector I mean you would go down here to your weights Yolo v3 dot weights and just change that to whatever your custom weights file is called so it's really easy to set it up for a custom detector as well but out of the box we're gonna use the Yolo v3 cocoa pre-trained one so that's work that's work you'll see model has been saved successfully and if you go back to your weights folder now before it only had Yolo feet so you don't weights and now you can see that we have tensorflow model dot checkpoint files so that shows that our model has been successfully built and we now have the tensorflow model files needed to do our detector so it's that easy and now we can head back to the repo and see that we can right away go into detection x' so detect up pi is the script that does the detection x' for us and it takes in a four parameters it takes in images or video you just have to say images if you're doing images and video if you're doing a video it takes in the iou threshold so this will be the threshold to be how close two objects are together if you want to merge them into one so let's say you had multiple elephants in one picture by setting that to a different value is just 0.5 is what I recommend if you're not trying to mess with that but if you change it lower higher you'll see that it'll impact whether it groups the elephant detections together or if it does just individual elephants so that's cool you can play around with that the third parameter is the confidence threshold so setting it to 0.5 means that for any of detections under fifty fifty percent confidence it will not show the detection so you can see that these ones are all high but it's a dog was forty three percent confident it would not show that so you can alter this one would meaning it has to be 100% confident and zero means that it would show all the deductions so you can play around that value as well and then finally your last parameter is just the image file paths that where your images are from the root directory of this uo v3 so you can see that you can just put milk you can put multiple images if you want and it'll run multiple detection z' so let's try that out I'm going to do Python detect dot PI and I will do images 0.5 0.5 and then there's these two images that are pre downloaded inside for you guys so it's data images dog jpg and we're just gonna go ahead and run this so right now it's running it through the tensor flow model and it's doing the detection using tensor flow this is great for if you want to package this up in a docker container and deploy it to production with kubernetes and I'm actually gonna working on a video right now to show that how you can package this tensor flow model up into the cloud and actually deploy it and hit endpoints that will run these detection for you so all your images will save and if you go your files and you go to yo v3 in the detection folder so if you run multiple files they'll all save here we open it up let me just drag it into the screen so you can see it so you can see that it successfully got truck bicycle and dog all with extremely high accuracy and if we go ahead and actually run that second image so I said it came with two inches it also came with office JPEG so this time I'm gonna run the same command but I'm actually going to do both images to show you that it indeed works with both office jpg run it and it'll save all of these to the detections older for you but like I said I'm gonna have a video coming soon to show you guys how to actually get this working in a docker file docker eyes this and be able to deploy it with kubernetes so you can see the detection czar lower and if we had set the threshold to 0.6 for confidence this would actually not be detected so you can see how you can play around that so we go back to the detection folder and we now have both we have the same one we had before dog and now we have detection 2 which shows an office space with chair detected TV monitor persons so you can see these are a couple these are would be three of the classes within the cocoa pre-trained data set but there is a bunch of more there is 77 more I guess there's 80 classes so you can play around and look up that and put a bunch of images so it's really that simple and now I'll get into an example showing you guys a video so we can do the exact same detect op PI command but this time with a video file and it'll load the video into our tensor flow model and run the detection Zahn so it's going to be the exact same command Python detect pi but this time we have the first parameter set to video then 0.5 and 0.5 for the thresholds and then now we point to data video and I have made a video called object dot mp4 and let's run that so this should run the detection z' on our video and then save our video in the detections folder that we saw the two images get saved in so hopefully this works we'll see it's yet so it's doing the video right now it's fairly slow on the video when it's doing the detection because I don't have the strongest GPU or computer itself but then you'll see that when we run it back it'll actually be in real time the detections it'll be full speed so hopefully this works I'm gonna let this finish and then I'll show you guys the detection so the video the video is done detecting it's been saved successfully a couple warnings but don't worry about those and then saves to the same folder all of v3 detections and it saves us detection is done it before so we'll open that up and I'll drag it in and I'll just rewind it for you guys so if I rewind it this is just me walking around it's not my sock was a surfboard this he's the remote the TV remote grabs the fork struggling on the fork a bit sees Bowl can do plates all types of cutlery and my back this is my backpack but it's not like it can't really detect the backpack because it's upside down and then it detects me as well so yeah you can see how it works well with videos as well and it can still recognize those eighty classes so I urge you to maybe that was shot with my mic my phone so just take a video and upload it do you detect all pie and see if it works so yeah that works with the video that's the example and then I'll my to-do list right now is to finish full migration so it is compatible with tear tensorflow 2.0 but there's a couple TF compat be ones that still default to the old functionality for certain like savers and assigning variables so I'm still working through those I'm going to update so it's fully migrated to TF 2.0 I'm also working on building the model training so that you don't have to train in the Yolo v3 architecture you can actually just train straight from this tensorflow architecture as well as my last but not least tiny Yolo configuration right now you can't load the weights for tiny Yolo so I'm working on that as well so make sure to check out keep checking this repo for updates and I'll make a new video detailing how to use tiny and stuff like that when it's fully uploaded so I hope you guys enjoyed this video on getting a object classifier up and running built with tensorflow 2.0 please drop a like on the video and show some support if you enjoyed this it took me a little while to create and also subscribe to the channel and make sure you can come back and get notified when the new video with the final modifications gets uploaded you won't want to miss it so thanks so much for listening guys and watching see ya [Music]

Original Description

Learn how to build your very own object detection classifier with TensorFlow 2.0! This video will walk you through the process and code in order to setup your own TensorFlow 2.0 detector that will be able to run detections on both images and video in real-time! This detection classifier gets converted from YOLOv3 architecture into TensorFlow's model .ckpt files in order to run the detections. #tensorflow #objectdetection #yolov3 -----Resources----- Get the code here: https://github.com/theAIGuysCode/yolo-v3 How to train custom yolo weights: https://www.youtube.com/watch?v=zJDUhGL26iU In this video I cover: 1. Setup and Install Dependencies 2. Convert YOLOv3 weights into TensorFlow model .ckpt files. 3. How to run object detections on both images and videos! Stay tuned for current upgrades which include: - Finish migration to full TF 2.0 (remove tf.compat.v1) - Allow model training - Tiny-Yolo Configuration If you enjoyed the video, toss it a like! 👍 To Subsribe: https://www.youtube.com/channel/UCrydcKaojc44XnuXrfhlV8Q?sub_confirmation=1 Thanks so much for watching! - The AI Guy
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from The AI Guy · The AI Guy · 10 of 28

1 How to Setup a Machine Learning and AI Environment
How to Setup a Machine Learning and AI Environment
The AI Guy
2 Introduction to Machine Learning | | Learning ML with Scikit | Iris Dataset
Introduction to Machine Learning | | Learning ML with Scikit | Iris Dataset
The AI Guy
3 Introduction to Machine Learning | Learning ML with Scikit | Iris Dataset | Part 2
Introduction to Machine Learning | Learning ML with Scikit | Iris Dataset | Part 2
The AI Guy
4 How to Install OpenCV on Windows | OpenCV Python Tutorial | Setting up Computer Vision
How to Install OpenCV on Windows | OpenCV Python Tutorial | Setting up Computer Vision
The AI Guy
5 How to Build and Install OpenCV from Source | Using Visual Studio and CMake | Computer Vision
How to Build and Install OpenCV from Source | Using Visual Studio and CMake | Computer Vision
The AI Guy
6 YOLOv3 Object Detection with Darknet for Windows/Linux | Install and Run with GPU and OPENCV
YOLOv3 Object Detection with Darknet for Windows/Linux | Install and Run with GPU and OPENCV
The AI Guy
7 Creating a YOLOv3 Custom Dataset | Quick and Easy | 9,000,000+ Images
Creating a YOLOv3 Custom Dataset | Quick and Easy | 9,000,000+ Images
The AI Guy
8 Train YOLOv3 Custom Object Detector with Darknet | Aimbot and Security Camera | Fast and Easy
Train YOLOv3 Custom Object Detector with Darknet | Aimbot and Security Camera | Fast and Easy
The AI Guy
9 Create Labels and Annotations for Custom YOLOv3 Google Images Dataset | LabelImg Tutorial
Create Labels and Annotations for Custom YOLOv3 Google Images Dataset | LabelImg Tutorial
The AI Guy
How to Build an Object Detection Classifier with TensorFlow 2.0 on Windows/Linux
How to Build an Object Detection Classifier with TensorFlow 2.0 on Windows/Linux
The AI Guy
11 YOLOv3 in the CLOUD : Install and Train Custom Object Detector (FREE GPU)
YOLOv3 in the CLOUD : Install and Train Custom Object Detector (FREE GPU)
The AI Guy
12 A.I. Learns to Play World's Hardest Game (QWOP)
A.I. Learns to Play World's Hardest Game (QWOP)
The AI Guy
13 How to Build Object Detection APIs Using TensorFlow and Flask
How to Build Object Detection APIs Using TensorFlow and Flask
The AI Guy
14 Getting Started with Azure Machine Learning Studio
Getting Started with Azure Machine Learning Studio
The AI Guy
15 Real-time Yolov3 Object Detection for Webcam and Video (using Tensorflow)
Real-time Yolov3 Object Detection for Webcam and Video (using Tensorflow)
The AI Guy
16 How to Build an Object Tracker Using YOLOv3, Deep SORT and TensorFlow
How to Build an Object Tracker Using YOLOv3, Deep SORT and TensorFlow
The AI Guy
17 YOLOv4 in the CLOUD: Install and Run Object Detector (FREE GPU)
YOLOv4 in the CLOUD: Install and Run Object Detector (FREE GPU)
The AI Guy
18 YOLOv4 in the CLOUD: Build and Train Custom Object Detector (FREE GPU)
YOLOv4 in the CLOUD: Build and Train Custom Object Detector (FREE GPU)
The AI Guy
19 YOLOv4 Object Detection with TensorFlow, TensorFlow Lite and TensorRT Models (images, video, webcam)
YOLOv4 Object Detection with TensorFlow, TensorFlow Lite and TensorRT Models (images, video, webcam)
The AI Guy
20 How to Build a Custom YOLOv4 Object Detector using TensorFlow (License Plate Detector)
How to Build a Custom YOLOv4 Object Detector using TensorFlow (License Plate Detector)
The AI Guy
21 Counting Objects Using YOLOv4 Object Detection | Custom YOLOv4 Functions with TensorFlow
Counting Objects Using YOLOv4 Object Detection | Custom YOLOv4 Functions with TensorFlow
The AI Guy
22 Object Tracking Using YOLOv4, Deep SORT, and TensorFlow
Object Tracking Using YOLOv4, Deep SORT, and TensorFlow
The AI Guy
23 Crop and Save YOLOv4 Object Detections | Custom YOLOv4 Functions with TensorFlow
Crop and Save YOLOv4 Object Detections | Custom YOLOv4 Functions with TensorFlow
The AI Guy
24 License Plate Recognition Using YOLOv4 Object Detection, OpenCV, and Tesseract OCR
License Plate Recognition Using YOLOv4 Object Detection, OpenCV, and Tesseract OCR
The AI Guy
25 YOLOv4 in the CLOUD: Build Object Tracking Using DeepSORT in Google Colab (FREE GPU)
YOLOv4 in the CLOUD: Build Object Tracking Using DeepSORT in Google Colab (FREE GPU)
The AI Guy
26 How to Use Webcam In Google Colab for Images and Video (FACE DETECTION)
How to Use Webcam In Google Colab for Images and Video (FACE DETECTION)
The AI Guy
27 Real-time YOLOv4 Object Detection on Webcam in Google Colab | Images and Video
Real-time YOLOv4 Object Detection on Webcam in Google Colab | Images and Video
The AI Guy
28 Getting Started with Agent Development Kit Tools (MCP, Google Search, LangChain, etc.)
Getting Started with Agent Development Kit Tools (MCP, Google Search, LangChain, etc.)
The AI Guy

This video teaches you how to build and deploy an object detection classifier using TensorFlow 2.0 and Yolo v3, covering the setup, configuration, and deployment of the detector for images and video. By following this tutorial, you'll learn how to use pre-trained weights, generate TensorFlow checkpoint files, and update model training for the YOLO v3 architecture.

Key Takeaways
  1. Clone the repository using git clone
  2. CD into the repo and open VS Code
  3. Install dependencies using pip install -r requirements.txt
  4. Download pre-trained weights using W get command
  5. Run Python load_weights.py to generate TensorFlow checkpoint files
  6. Configure detection script with images or video, iou threshold, and confidence threshold
  7. Run Python detect.py with image file paths and thresholds
  8. Run video detection using the same command with a video file
💡 The YOLO v3 architecture can be used for object detection in images and video, and TensorFlow 2.0 provides a compatible platform for deploying the detector.

Related Reads

Up next
SAM 2 Segment Anything - Image and Video Segmentation #computervision #objectsegmentation #sam #meta
Abonia Sojasingarayar
Watch →