Reputation: 1535
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=.
Upvotes: 2
Views: 7342
Reputation: 335
Runs:
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
# 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 .
Upvotes: 0
Reputation: 41
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
Upvotes: 4
Reputation: 38619
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
.
Upvotes: 5