Object detection is a fantastic technology of machine learning, and many organizations use it for their benefit. The face recognition system in your phone, driverless cars, and the crowd statistics, they all have one thing in common: they use object detection.
If you’re learning machine learning, you’d surely want to get familiar with this technology. In this article, you’ll learn about TensorFlow object detection and how you can perform the same. Be sure to check the example as you can try it out yourself and experiment.
What is Object Detection?
The name of ‘Object Detection’ is self-explanatory. It refers to finding real objects in images (or videos). These objects could be cars, TVs, or even humans. With object detection, you can localize, recognize, and detect multiple objects in an image. Object detection finds applications in many industries. From surveillance to product quality inspection, you’d find plenty of areas where experts use this technology. You can perform object detection in the following ways:
- Deep learning method
- Viola-Jones method
- Feature-based detection
- SVM classifications (through HOG features)
In this article, we’ll focus on TensorFlow object detection. And TensorFlow performs this through deep learning. So in our tutorial, we’ll use that method.
TensorFlow: An Introduction
It’s also important to be familiar with what TensorFlow is. It’s an Open Source Machine Learning framework and a product of Google. You can use TensorFlow to perform dataflow programming. Its name is made up of ‘Tensor’ and Flow’, both of which are vital components of this technology. Tensors are multidimensional arrays, whereas the flow stands for the dataflow programming you perform.
Also learn: Most Popular 5 TensorFlow Projects for Beginners
TensorFlow Object Detection Tutorial
Before you work on this tutorial, you must be familiar with the following topics:
In this TensorFlow object detection tutorial, you’ll need to use OpenCV. You’ll also need to use the camera module so you could use a webcam’s live feed to detect the objects in the image.
We’ll use the Common Objects in Context dataset. It has around 330,000 labeled images. You’ll also have to import all the necessary libraries, including NumPy, to perform this task. But we’ve shared all that in our final code.
You’ll have to add a model to perform the object detection. Here’s how you’ll add it:
MODEL_NAME = ‘ssd_mobilenet_v1_coco_2017_11_17’
MODEL_FILE = MODEL_NAME + ‘.tar.gz’
DOWNLOAD_BASE = ‘http://download.tensorflow.org/models/object_detection/‘
PATH_TO_CKPT = MODEL_NAME + ‘/frozen_inference_graph.pb’
PATH_TO_LABELS = os.path.join(‘data’, ‘mscoco_label_map.pbtxt’)
NUM_CLASSES = 90
First, we’ll need to add the OpenCV library and then the camera. Use the following code:
cap = cv2.VideoCapture(0)
Then use the following code to load the images:
ret, image_np = cap.read()
OpenCV will help us with the final image show. So use the following code for that purpose:
cv2.imshow(‘object detection’, cv2.resize(image_np, (800,600)))
if cv2.waitKey(25) & 0xFF == ord(‘q’):
Now you can perform object detection with TensorFlow as well. Just follow this example, and you’ll be good to go. If you have any questions on this topic, let us know in the comment section. We’d love to help you out.
On the other hand, if you want to learn more about Machine Learning, check out our machine learning courses for that purpose. What did you think of this article? Let us know.
If you’re interested to learn more about machine learning, check out IIIT-B & upGrad’s PG Diploma in Machine Learning & AI which is designed for working professionals and offers 450+ hours of rigorous training, 30+ case studies & assignments, IIIT-B Alumni status, 5+ practical hands-on capstone projects & job assistance with top firms.