Researchers have been studying the possibilities of giving machines the ability to distinguish and identify objects through vision for years now. This particular domain, called Computer Vision or CV, has a wide range of modern-day applications. From being used by autonomous cars for object detection on roads to complex facial and body language recognitions that can identify possible crimes or criminal activities, CV has numerous uses in today’s world. There is no denying the fact that Object Detection is also one of the coolest applications of Computer Vision.
Modern-day CV tools can easily implement object detection on images or even on live stream videos. In this article, we will look at a simple demonstration of a real-time object detector using TensorFlow.
Setting Up A Simple Object Detector
Tensorflow >= 1.12.0
- Install the latest version by executing
pip install tensorflow
We are now good to go!
Setting Up The Environment
1. Download or clone the TensorFlow Object Detection Code into your local machine from Github
Execute the following command in the terminal :
git clone https://github.com/tensorflow/models.git
If you don’t have git installed on your machine you can choose to download the zip file from here.
2. Installing the dependencies
The next step is to make sure that we have all the libraries and modules that we need to run the object detector on our machine.
Here is a list of libraries that the project depends on. (Most of the dependencies comes with Tensorflow by default)
In case if you find any of the module missing just execute
pip install in your environment to install.
3. Installing Protobuf compiler
Protobuf or Protocol buffers are Google’s language-neutral, platform-neutral, extensible mechanism for serializing structured data. It helps us define how we want our data to be structured and once structured it lets us easily write and read the structured data to and from a variety of data streams and using a variety of languages.
This is also a dependency for this project. You can learn more about Protobufs here. For now, we will install Protobuf in our machine.
Choose the appropriate version for your OS and copy the download link.
Open your terminal or command prompt, change directory to the cloned repository and execute the following commands in your terminal.
cd models/research \
wget -O protobuf.zip https://github.com/protocolbuffers/protobuf/releases/download/v3.9.1/protoc-3.9.1-osx-x86_64.zip \
Note: Make sure that you decompress the protobuf.zip file inside models/research directory
4. Compiling the Protobuf compiler
Execute the following command from the research/ directory to compile the Protocol Buffer.
./bin/protoc object_detection/protos/*.proto --python_out=.
Implement Object Detection in Python
Now that we have all the dependencies installed, let’s use Python to implement Object Detection.
In the downloaded repository, change directory to models/research/object_detection. In this directory, you will find an ipython notebook named object_detection_tutorial.ipynb. This file is a demo for Object detection which on execution will use the specified ‘ssd_mobilenet_v1_coco_2017_11_17’ model to classify two test images provided in the repository.
Given below is one of the test outputs:
There are minor changes to be introduced to detect objects from a live stream video. Make a new Jupyter notebook with in the same folder and follow along with the code given below.
When you run the Jupyter notebook, the system webcam will open up and will detect all classes of objects that the original model has been trained to detect.
Enjoyed this story? Join our Telegram group. And be part of an engaging community.
Provide your comments below
What's Your Reaction?
A Computer Science Engineer turned Data Scientist who is passionate about AI and all related technologies. Contact: email@example.com