Models: ImportError: No module named utils

Created on 23 Jun 2017  路  12Comments  路  Source: tensorflow/models

I'm getting an error when trying to run the object_detection_tutorial.ipynb in a jupyter notebook as:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-3-956de605e8fe> in <module>()
----> 1 from utils import label_map_util
      2 
      3 from utils import visualization_utils as vis_util

ImportError: No module named utils

I have followed the installation steps, and have compiled protobuf. I'm using a virtualenv.

awaiting response

Most helpful comment

in your python file, add this lines at beginning:

import sys
sys.path.append('/your/dir/to/tensorflow/models') # point to your tensorflow dir
sys.path.append('/your/dir/to/tensorflow/models/slim') # point ot your slim dir

All 12 comments

Hi @SaleheErfanianEbadi - what directory are you running the notebook from and have you set your PYTHONPATH correctly?

in your python file, add this lines at beginning:

import sys
sys.path.append('/your/dir/to/tensorflow/models') # point to your tensorflow dir
sys.path.append('/your/dir/to/tensorflow/models/slim') # point ot your slim dir

if you are running object_detection.
go to 'object_detection' dir and run your code! 'util' dir is within object_detection

import sys
sys.path.append('/your/dir/to/tensorflow/models') # point to your tensorflow dir
sys.path.append('/your/dir/to/tensorflow/models/slim') # point ot your slim dir

from utils import label_map_util

ModuleNotFoundError: No module named 'utils'

no working for me :(

if you are running object_detection.
go to 'object_detection' dir and run your code! 'util' dir is within object_detection

Why not run in other folder ???

Why not run in other folder ???

Because the utils folder is in the object_detection folder. You can import utils from another folder if you add object_detection to your python path first:
sys.path.append('/your/dir/to/tensorflow/models/research/object_detection')

Edit: If you do it like that, you will have to change some paths in the tutorial (because they are relative to the object_detection folder).

To be able to access the 'utils' module directly, you need to be running the script inside the \research\object_detection folder.

use "object_detection.utils" instase of "utils"

Why same module was named object_detection.utils and utils 8 lines later in object_detection_tutorial.ipynb?

I still have the problem of "no module named utils" even after adding both of sys.path

try to change your python version, if you use 2.7 than change your path to version to 3.7

sudo update-alterntives --config python

Was this page helpful?
0 / 5 - 0 ratings