MITB Banner

Introductory Guide To Real-Time Object Detection With Python 

Share

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

Pre-requisites:

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)

  • Cython
  • contextlib2
  • pillow
  • lxml
  • matplotlib

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.

Head to https://github.com/protocolbuffers/protobuf/releases

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 \
unzip protobuf.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.

Share
Picture of Amal Nair

Amal Nair

A Computer Science Engineer turned Data Scientist who is passionate about AI and all related technologies. Contact: amal.nair@analyticsindiamag.com
Related Posts

CORPORATE TRAINING PROGRAMS ON GENERATIVE AI

Generative AI Skilling for Enterprises

Our customized corporate training program on Generative AI provides a unique opportunity to empower, retain, and advance your talent.

Upcoming Large format Conference

May 30 and 31, 2024 | 📍 Bangalore, India

Download the easiest way to
stay informed

Subscribe to The Belamy: Our Weekly Newsletter

Biggest AI stories, delivered to your inbox every week.

AI Courses & Careers

Become a Certified Generative AI Engineer

AI Forum for India

Our Discord Community for AI Ecosystem, In collaboration with NVIDIA. 

Flagship Events

Rising 2024 | DE&I in Tech Summit

April 4 and 5, 2024 | 📍 Hilton Convention Center, Manyata Tech Park, Bangalore

MachineCon GCC Summit 2024

June 28 2024 | 📍Bangalore, India

MachineCon USA 2024

26 July 2024 | 583 Park Avenue, New York

Cypher India 2024

September 25-27, 2024 | 📍Bangalore, India

Cypher USA 2024

Nov 21-22 2024 | 📍Santa Clara Convention Center, California, USA

Data Engineering Summit 2024

May 30 and 31, 2024 | 📍 Bangalore, India

Subscribe to Our Newsletter

The Belamy, our weekly Newsletter is a rage. Just enter your email below.