Skip to content

Tensorflow Object Detection API on Windows - error “ModuleNotFoundError: No module named 'utils'” #3164

@MicrocontrollersAndMore

Description

System information

  • What is the top-level directory of the model you are using:
    models/research/object_detection

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow):
    No custom code, using stock example in models/research/object_detection

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04):
    Windows 10

  • TensorFlow installed from (source or binary):
    Binary via pip3, currently at Python 3.6

  • TensorFlow version (use command below):
    1.4

  • Bazel version (if compiling from source):
    N/A

  • CUDA/cuDNN version:
    Using CPU for the moment

  • GPU model and memory:
    Using CPU for the moment

  • Exact command to reproduce:
    See Stack Overflow link below

Describe the problem

I'm not 100% sure at this point if this is a bug fix or a feature request. For any Python script I write that uses the libraries in /models/research/object_detection/utils, I can only run a script from models/research/object_detection. If I run from anywhere else I get the error:

ModuleNotFoundError: No module named 'utils'

I have a detailed Stack Overflow post where I've listed out the steps I've followed and the remedies I've tried to no avail:

https://stackoverflow.com/questions/48247921/tensorflow-object-detection-api-on-windows-error-modulenotfounderror-no-modu

For the sake of brevity I'd rather not repeat the entire post here, please see this link for the full details. To make a long story short, I've tried adding the following paths:

C:\Users\cdahms\Documents\models
C:\Users\cdahms\Documents\models\research
C:\Users\cdahms\Documents\models\research\slim
C:\Users\cdahms\Documents\models\research\object_detection\utils

directly into a script via sys.path.append(), and also to PYTHONPATH (and then added PYTHONPATH to PATH)

I'm not sure if this is a bug or if there is some setting possible to make the /models/research/object_detection/utils content recognizable from a directory other than /models/research/object_detection, please advise.

--- Edit ---
Upon further consideration who knows what may happen to the Stack Overflow link above, so I'll repeat the error and full steps to reproduce here:

I'm attempting to get the TensorFlow Object Detection API:

https://github.com/tensorflow/models/tree/master/research/object_detection

working on Windows by following the install instructions:

https://github.com/tensorflow/models/tree/master/research/object_detection

Which seem to be for Linux/Mac. I can only get this to work if I put a script in the directory I cloned the above repo too. If I put the script in any other directory I get this error:

ModuleNotFoundError: No module named 'utils'

I suspect that the cause is not properly doing the Windows equivalent of this command listed on the install instructions above:

export PYTHONPATH=$PYTHONPATH:pwd:pwd/slim

I'm using Windows 10, Python 3.6, and TensorFlow 1.4.0 if that matters. Any suggestions on how to resolve this?

Here are the steps I've done so far specifically:

  1. Installed TensorFlow and related tools via pip3

  2. From an administrative command prompt, run the following:

pip3 install pillow
pip3 install lxml
pip3 install jupyter
pip3 install matplotlib
  1. Clone the TensorFlow "models" repository to my documents folder, in my case

C:\Users\cdahms\Documents\models

  1. Downloaded Google Protobuf https://github.com/google/protobuf Windows v3.4.0 release "protoc-3.4.0-win32.zip" (I tried the most current 3.5.1 and got errors on the subsequent steps, so I tried 3.4.0 per this vid https://www.youtube.com/watch?v=COlbP62-B-U&list=PLQVvvaa0QuDcNK5GeCQnxYnSSaar2tpku&index=1 and the protobuf compile worked)

  2. Extracted the Protobuf download to Program Files, specifically:

C:\Program Files\protoc-3.4.0-win32

  1. CD into the models\research directory, specifically:

cd C:\Users\cdahms\Documents\models\research

  1. Executed the protobuf compile, specifically:

“C:\Program Files\protoc-3.4.0-win32\bin\protoc.exe” object_detection/protos/*.proto --python_out=.

The compile was successful (no errors), and also I went to:

C:\Users\cdahms\Documents\models\research\object_detection\protos

and verified the .py files were created successfully as a result of the compile

  1. cd to the object_detection directory, ex:

cd C:\Users\cdahms\Documents\models\research\object_detection

then start the object_detection_tutorial.ipynb Jupyter Notebook:

jupyter notebook

  1. In the Jupyter Notebook, choose "object_detection_tutorial.ipynb" -> Cell -> Run all, the example runs within the notebook

  2. In the Jupyter Notebook, choose “File” -> “Download As” -> “Python”, and save the .py version of the notebook to the same directory, i.e.

C:\Users\cdahms\Documents\models\research\object_detection\object_detection_tutorial.py

The script runs as expected.

  1. Move the script to any other directory, then I get the error:

ModuleNotFoundError: No module named 'utils'

Clearly, the lines where this error is occurring are the imports for utils:

from utils import label_map_util
from utils import visualization_utils as vis_util

Here are some things I've tried to resolve the concern, none of which have worked:

  1. Add these lines to the script, just before the 2 above imports
sys.path.append("C:\\Users\\cdahms\\Documents\\models")
sys.path.append("C:\\Users\\cdahms\\Documents\\models\\research")
sys.path.append("C:\\Users\\cdahms\\Documents\\models\\research\\slim")
sys.path.append("C:\\Users\\cdahms\\Documents\\models\\research\\object_detection\\utils")
  1. Go to System -> Advanced system settings -> Environment Variables . . . -> New, added a variable with the name PYTHONPATH and these values:

untitled

  1. Also under Environment Variables, edited PATH and added PYTHONPATH

untitled2

  1. Pulled up a command prompt and ran the command "set", verified PYTHONPATH was there and PYTHONPATH and PATH contained the values from the previous steps:

untitled3

  1. Rebooted, then ran the script from any directory other than

C:\Users\cdahms\Documents\models\research\object_detection

again, still get the

ModuleNotFoundError: No module named 'utils'

Suggestions as to how to get

C:\Users\cdahms\Documents\models\research\object_detection\utils

to be recognized by Python when the script is run from any location ??

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions