Attend FREE Webinar on Data Science for Career Growth Register Now
Digital Vidya's 10th Anniversary Celebrations Offer
  • This field is for validation purposes and should be left unchanged.

How To Work With Tensorflow Object Detection

 / 
How To Work With Tensorflow Object Detection

Are you looking forward to working with Tensorflow Object Detection? The image recognition market is expected to grow to $25.65 billion by the end of 2019. However, locating multiple objects in one image has always been a challenge in the field of computer vision.

However, with advanced deep learning techniques and object detection applications, there is more scope for object detection than ever before. The Tensorflow Object Detection API has been built on top of Tensorflow and represents a great leap forward in object detection.

What Is Object Detection?

Object detection is a technology that allows computers to identify object instances in images and videos. These object instances include cars, humans, bikes, TVs, dogs, and so on. If different objects within an image can be recognized, detected, and localized, then we can get a more holistic understanding of the image itself.

It has various applications in areas like security, surveillance, image retrieval, and advanced driver assistance systems. There are several methods of object detection, some of which are listed below.

(i) Deep Learning Object Detection (This is used in Tensorflow Object Detection)

(ii) Feature-Based Object Detection

(iii) SVM Classifications with HOG Features

(iv) Viola-Jones Object Detection

This article deals primarily with Deep Learning Object detection as the Tensorflow Object Detection tutorial is based on Deep learning algorithms.

The Various Applications Of Object Detection

Object detection technologies can have a transformative impact on several industries. Here are some key areas in which object detection can be applied. Tensorflow object detection is used in many of these areas.

1. Security

One of the most critical applications of object detection is insecurity. Whether it’s using image recognition to lock your phone or a retinal scan in high-security areas. Object detection also has important implications in police searches as images can be matched to government databases to narrow down on the identity of a criminal.

2. Inventory Tracking

Inventory tracking and quality checks on products are very challenging to do in real-time. This often results in lots of inefficiencies in the production and supply chain. Object detection can solve this problem by allowing for the automated, real-time inspection of products.

3. Self-Driving Cars

While self-driving cars combine a lot of different technologies, object detection is one technology self-driving cars would not be possible without. The control systems in these cars use object detection to identify the right paths and see the obstacles. The car automatically stops if the image sensor detects any living being on the road.

Tensorflow Object Detection Source - aarp

Self-Driving Cars

4. Facial Recognition

Facial recognition is another field where object detection is crucial. Google’s facial recognition system that groups all photos of one person together to Facebook’s “DeepFace” which can identify human faces in digital images quite effectively. There are various elements to facial recognition. The different features of the face (nose, mouth, eyes, etc) have to be dealt with separately and together.

Tensorflow Object Detection Source - Medium

Facial Recognition

5. Crowd Statistics

Object detection can be used for people counting at stores or during special events like festivals. This has massive implications as it can be used to conduct important analyses related to crowds. Of course, people counting is an especially challenging application of object detection because people keep moving in and out of the frame very quickly.

The Object Detection Workflow

All object detection algorithms, no matter how differently they work, operate on the same basic principle. Here’s what the standard object detection workflow looks like.

(i) Get the input images.

(ii) Extract features from these input images.

(iii) Use the features to determine the class of the image. This is done using different object detection techniques like Deep Learning, Viola-Jones, MatLab, or Open CV.

Here’s what the complete workflow looks like.

Tensorflow Object Detection Source - Cloudfront

Object Detection Workflow

Now that the workflow is known, let’s start with a  Tensorflow Object Detection tutorial.

What is Object Detection Tensorflow?

Tensorflow is Google’s open-source Machine Learning framework. It allows for dataflow and differential programming across several kinds of tasks. Tensorflow was originally developed by engineers from the Google Brain team, which is a part of Google’s AI(Artificial Intelligence) organization.

The TensorFlow Object Detection API is an open-source framework that’s been built on top of TensorFlow. It is an easy-to-use tool that allows people to build powerful image recognition software. Even people without a background in machine learning can use this tool.

We will be using a particular problem to demonstrate how to do a  Tensorflow Object Detection tutorial that will talk about how to set up and use Object Detection TensorFlow from scratch. We will be creating a traffic light classifier that determines if the traffic light is red, yellow, or green.

Register For a
Free Webinar

Date: 21st Nov, 2019 (Thursday)
Time: 3 PM (IST/GMT +5:30)
  • This field is for validation purposes and should be left unchanged.

How To Install It?

You will have to install both TensorFlow and TensorFlow GPU. To download TensorFlow and TensorFlow GPU, you can use either pip or conda commands.

1

2

3

4

# For CPU

pip install TensorFlow

# For GPU

pip install TensorFlow-GPU

(i) We then install the other libraries we will be using, once again using pip or conda

1

2

3

4

5

6

pip install –user Cython

pip install –user contextlib2

pip install –user pillow

pip install –user lxml

pip install –user jupyter

pip install –user matplotlib


(ii) The next step is to install Protobuf (Protocol Buffers). Protobuff is the mechanism Google uses to serialize structured data. It’s a sort of simpler and faster version of XML. It’s best to download Protobuf version 3.4 or above. Protobuf is extensible, and both language and platform-neutral.

(iii) Now you need to Download TensorFlow’s Model from Github.

(iv) You can also install TensorFlow and the libraries from this link. You simply need to open installation.md and install TensorFlow and all the required dependencies. Even if TensorFlow is already installed on your laptop, you have to still add the specific libraries.  You can do this by following the “Add Libraries to PYTHONPATH instructions. You can navigate a terminal console to the models/research/ folder and use this command.

export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim

Register For a
Free Webinar

Date: 21st Nov, 2019 (Thursday)
Time: 3 PM (IST/GMT +5:30)
  • This field is for validation purposes and should be left unchanged.

Testing A Model

The next step is to test anyone’s model that is used in Object Detection TensorFlow. To do this, go to the models/research/objection_detection/ folder, and open the jupyter notebook object_detection_tutorial.ipynb. You then run this notebook. Make sure you run the entire notebook and don’t move the file out of the folder. If you do so, some visualization import statements may fail and the model won’t run as expected.

Make sure you have a few sample images of the traffic light turning different colors. You can place them in the tests_images folder. For the sake of uniformity name them as image3.jpg, image4.jpg and so on till imageN.jpg. Remember the more images you have, the better the testing.

In the Jupyter notebook, you need to now change the line under the detection heading. It should now say:

TEST_IMAGE_PATHS = [ os.path.join(PATH_TO_TEST_IMAGES_DIR, ‘image{}.jpg’.format(i)) for i in range(1, N+1) ]

N is, of course, the last number of the images that were placed in the folder. On running the notebook now, you will be able to see that al the images in the folder have been classified. This will help you figure out how accurate the model you tested out really is.

Tensorflow Object Detection Source - Medium

Testing A Model

As you can see from the images above, the first model that has been tested is effective in 50% of the cases. It is able to classify the traffic light in Image 1 but not in Image 2.

Selecting A Model

As you can see in the table given below there are many models available in TensorFlow Object Detection. These models have different speeds and different mAPs (Mean Average Precision). The mAP indicates the performance of the model on a particular dataset. The conventional wisdom is that models that are slower tend to be more accurate.

However, there are a number of other factors which also affect the performance of the model. For instance, some models perform better on small objects than others. You can study the different models in-depth to understand these differences.

An easier way to select the right model would be a small trial and error. Use some sample images and check the performance of each model for these images. To do this, you just need to replace the MODEL_NAME in the notebook. Use the specific download location of the model. This can be found in the detection_model_zoo.mb file which is in the g3doc folder. For the traffic light classification, the R-FCN model worked best. Here’s the result it produced for the sample images.

Tensorflow Object Detection Source - Medium

Selecting A Model

Image Source

Here’s a video tutorial that will also help you master Tensorflow object detection.

Conclusion

Tensorflow’s Object Detection API is one of the easiest to learn and use. It represents a huge leap in Object detection and image recognition. This will have massive implications for different areas where it is used.

Unfortunately, TensorFlow’s Object Detection API is still relatively new and documentation is not as extensive as it should be. However, with the help of this article, it should be easy enough for you to set it up and start using it. If you are a machine learning enthusiast, the Tensorflow Object Detection API is one of those tools that can really give you a competitive edge.

To accelerate your career in Data Science, join our Data Science Master Course for more lucrative career options in Data Science.




Your Comment

Your email address will not be published.