Object Detection Using TensorFlow

Have you ever wanted to ride in an Autonomous Vehicle? Well, if you're going to, the vehicle must be safe and must be able to see what’s around it. This is where object detection comes in! I’ve recently been interested in seeing how computers identify objects. Humans can do it in less than a second, which shows how powerful the brain is, but computers could take more than 30 seconds and still be inaccurate. Over the years, this technology has been getting better with the rise of powerful computers. Now computers can do accurate detections in less than 3–5 seconds.

New York City Traffic

How It Works

Object Detection uses Machine Learning. The machine learns what an object is in an image by using CNNs which are Convolutional Neural Networks. These have been a bit different from Neural Networks.

Here are some videos to learn about Neural Networks

Convolutional Neural Networks
Convolutional Neural Networks

How To Detect Your Objects Using TensorFlow

First of all, if you don’t know what TensorFlow is, it is a free and open-source library for machine learning.

First, you need to go to a site called Google Colab; then, you need to create a new notebook.

Then to add code, you will need to click the “+Code” button in the upper-left corner.

The paste the following.

Then in a new cell…

The first piece of code simply downloaded Version 2.5 of TensorFlow and imported necessary packages we may need to use later.

Although the second piece of code looks like a lot of rubbish, it simply loaded all the models in for later.

Unfortunately, we still have to add a lot more code to add.

We will also need to download a BUNCH of files for the code to understand what’s GOING ON!

Next you need to write…

Now we need to set up some files…

The command above will give you something interesting. It’s a dropdown that lets you select a model. Now, WHAT IS A MODEL? Each model has a different way of finding what’s in an image. All of them use CNNs, but some are faster, and some are accurate.

My Favourite Models

  1. EfficientDet D4 1024x1024 - Fast and Accurate.
EfficientDet D4 1024x1024

2. Mask R-CNN Inception ResNet V2 1024x1024 - Slow, But Shows A Mask Of The Object.

Mask R-CNN Inception ResNet V2 1024x1024

For now, we’ll go with EfficientDet D4 1024x1024 since it’s fast and accurate. Also, we don’t need a mask around the object since it’s not helpful.

After you’ve selected EfficientDet D4 1024x1024, let’s download the model!

We now have to put this command.

Next, we need to download the image for our demo.

You can replace the existing URL with your own for the image.

Finally, we can run the detection and display and download the image.

Congrats! 🎉

To run it, do CTRL/CMD + F9 or go to Runtime in the toolbar and click “Run All.” It will take a while to run, but in the end, you will get excellent results!

Why didn’t I just use YOLO? If you don’t know what YOLO is, it is an alternative to TensorFlow. I prefer TensorFlow since it has a wide variety of machine learning tools such as Speech Detection, Object Detection, etc. YOLO only does Object Detection. Also, TensorFlow has accurate and fast models. YOLO was quick but wasn’t very accurate.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store