2

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=.

4 Answers 4

5

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Bob, following Tensorflow documentation, we should add to PYTHONPATH even "tensorflow/models/research/", so I would add to cell 23: sys.path.append('/content/models/research')
4

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

Comments

1

Try this :

!pip install tensorflow-object-detection-api

1 Comment

this is the one that succeeds, if you follow this tensorflow tutorial--tensorflow.org/hub/tutorials/tf2_object_detection . Before importing the object detection tools, run the above code. The errors disappeared for my case
0

Runs:

  • step 1:

import os
    import pathlib
    
    # Clone the tensorflow models repository if it doesn't already exist
    if "models" in pathlib.Path.cwd().parts:
      while "models" in pathlib.Path.cwd().parts:
        os.chdir('..')
    elif not pathlib.Path('models').exists():
      !git clone --depth 1 https://github.com/tensorflow/models

  • Step 2:

# Install the Object Detection API
%%bash
cd models/research/
protoc object_detection/protos/*.proto --python_out=.
cp object_detection/packages/tf2/setup.py .
python -m pip install .

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.