1

I am using the TensorFlow object detection API in a Python project. In order to run the code in PyCharm I include the location of the TensorFlow git repository's models/research directory as a "Content Root". When I run the code at command line I include this directory location in PYTHONPATH. This is simple enough, but I'd like to eliminate the need for users to take care of this legwork if it's possible to have the TensorFlow object-detection module installed into the environment along with the other dependencies of my project's package.

I have tried adding the following to my requirements.txt to no avail (i.e. pip install requirements.txt hangs):

-e git+https://github.com/tensorflow/models.git#egg=research

I have also tried reading all lines from requirements.txt in setup.py for dependency links, but using this approach doesn't work either when I run python setup.py install.

In the Object Detection API Demo there is a clone of the repository and then an install via

cd models/research
pip install .

Can something like this be done via an appropriate entry in the requirements.txt and/or some code in the setup.py of my project?

My goal is to not get a ModuleNotFoundError when my code calls import object_detection, etc. if users haven't already installed the TensorFlow object detection API into their Python environment "by hand".

1 Answer 1

2

The egg=... parameter is used only to tell pip the name of the module. To install from the research subdirectory of the repository, append another parameter:

## requirements.txt
-e git+https://github.com/tensorflow/models.git#egg=research&subdirectory=research

And in the command line:

$ pip install -e git+https://github.com/tensorflow/models.git#egg=research\&subdirectory=research

(note the escaped & as it is a special character in most shells).

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

4 Comments

Thank you, @Seb, very helpful! This gets me almost all the way home. Unfortunately, I still need to somehow automate the protobuf compilation (as described here: github.com/tensorflow/models/blob/master/research/…) otherwise I get the following error: >>> from object_detection.utils import dataset_util, label_map_util Traceback (most recent call last): from object_detection.protos import string_int_label_map_pb2 ImportError: cannot import name 'string_int_label_map_pb2'
Which platforms will your users install this on? Would it be acceptable to just have a script (say, install.sh) that automates the installation?
This is a very good idea, I haven't thought of that. I have managed to purge my dependency on that protobuf (string_int_label_map_pb2) so now it's just down to installing the TFOD API from GitHub. I discovered that you can't use the solution in the answer within setup.py so there's always going to be that extra step involved besides the pip install from PyPI. Here's how I have things now, please advise if you think there's a better way to skin this cat: github.com/monocongo/cvdata#installation
Looks good to me! Just be aware that depending directly on another repository can of course always lead to stuff in your project breaking unless you specify a specific point in the target's commit history. I would consider the alternative of adding the tensorflow repository as a submodule in your own. This way you should be able to skip the extra step in the installation as it will be part of your project, and have full control over the compatibility between your code base and the tensorflow repository as you can update the submodule in line with your supporting commits.

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.