2
votes

I succesfully executed in Google Colaboratory a notebook of training model and image recognition in Tensorflow. Now I want to start a new notebook with Object Detection Api. When I execute my code I get following error:

ModuleNotFoundError: No module named 'object_detection'

How can I install Object Detection Api in Colaboratory? I follow the install instructions but I can't execute:

# From tensorflow/models/research/
protoc object_detection/protos/*.proto --python_out=.
3

3 Answers

5
votes

Here is an example notebook that shows the installation and configuration of the TensorFlow object detection API:

https://colab.research.google.com/drive/1kHEQK2uk35xXZ_bzMUgLkoysJIWwznYr

The departure from the install instructions on the site include modifying sys.path directly and executing model_builder_test.py using %run. The reason for these differences is that when running in Colab, you're already in a Python interpreter, so you don't need to worry about modifying the environment for a future shell invocation of python.

4
votes

You just forgot to Add path the slim folder

If you run locally https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/installation.md:

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

On the Colab:

import sys
sys.path.append('/content/base_folder/slim')

Notes: The Google Colaboratory also required to install some necessary packages firstly:

!apt-get install -y -qq protobuf-compiler python-pil python-lxml

My example: https://colab.research.google.com/drive/1EFtTACXnWUoaGGAVqCwYS_JS-6Jr6upg#scrollTo=Z2GjW06y_6gO

0
votes

Try this :

!pip install tensorflow-object-detection-api