Running the Detector

To get started, move your mouse cursor over the [ ] box to the left of the first code snippet, underneath the Downloading Model Data header. It will change to a "Play" icon. Click on this icon.

At this point, you may be prompted to sign in to your Google account. You'll need to sign in before you can continue with this guide.

What should happen?

After typically 20 seconds or so, you'll see the notebook come to life. The previous output will vanish and you'll see it replaced with the result of running on your new runtime (see the section titled Aside below for more about what a runtime is).

When you see Setup Successful!, you know you've finished this step. You can open another copy of the notebook and compare it to our previous run, just to make sure it looks correct.

Aside: Behind the Scenes

Each time you open a Colab notebook, Google lets you temporarily use a computer in their datacenter to run your code. This computer is running a program called the runtime, which lets you play around with TensorFlow without having to worry about how fast your computer and without needing to buy an expensive graphics card.

When you close your Colab notebook, Google replaces your runtime with a brand new one, and releases your machine to someone else. This means that each time you come back, you'll need to set up the machine from scratch.

The first cell in the notebook does just this. It downloads the TensorFlow Model that will be used to recognize objects.

Configuring TensorFlow

Scroll down to the next code block, titled Configuring TensorFlow. Again, move your mouse over the [ ] box on the left, and click to run the code block.

When the code block finishes executing, you should see the following:

Download: file
Model configured

Optional: Visualizing the graph

The code you just ran sets up a TensorFlow graph--a series of processing steps that translate the image from your camera into object labels and bounding boxes. You can visualize the graph using a tool called [TensorBoard]. This step isn't strictly necessary but it lets you peek inside the network to see the complexity behind the scenes.

To do this:

  1. Under Optional: Visualize the Graph with TensorBoard, click Play.
  2. Wait a few seconds after the block finishes executing. You should then see the TensorBoard UI appear below:

Starting the Demo

Now, scroll to the final code block, titled Demo and run it in the same way. This block of code won't stop until you tell it to.

After you click the play button, your browser should ask for permission to use your webcam. In Firefox, it looks like this:

Be sure to click Allow.

Finally, scroll down and you should see video from your camera appear on screen. Above the video, you'll see the output from the Object Detector.

You might notice that the model is a bit laggy. This is due to the way computation is split up in this example--the picture has to be sent from Javascript running on your machine to Python running in Colaboratory and back. Were this running on one machine in one programming language, it would be considerably faster!

Tips and Tricks

Play around with the detector to see how it performs best. Here are some hints from my experiments so far:

  • Make sure the object takes up a significant part of the frame.
  • Try with a uniform background for best results.
  • Try changing the angle.
This guide was first published on Oct 07, 2019. It was last updated on Oct 07, 2019. This page (Running the Detector) was last updated on Oct 17, 2019.