16

I'm trying to run the object_detection API in Tensorflow using my webcam as an input.

The error says: "from utils import label_map_util ModuleNotFoundError: No module named 'utils'"

Which relates to the lines:

from utils import label_map_util
from utils import visualization_utils as vis_util

I've tried "pip install util" appears to work but doesn't solve the problem. I have also reinstalled multiple versions of protobuf as other questions online appear to have this as the solution. I don't get any errors when I install protoc so I don't think this is the issue.

I'm using python 3.6 on windows 10 with tensorflow-gpu.

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
  • 4
    Possible duplicate of [from utils import label\_map\_util Import Error: No module named utils](https://stackoverflow.com/questions/46494160/from-utils-import-label-map-util-import-error-no-module-named-utils) – Tim Woocker Mar 28 '18 at 22:25

7 Answers7

9
  • Instead of running script inside object detection folder append the path of tensorflow object detection in your script by writing

    import sys
    
    sys.path.append('PATH_TO_TENSORFLOW_OBJECT_DETECTION_FOLDER')
    
  • e.g 'PATH_TO_TENSORFLOW_OBJECT_DETECTION_FOLDER' in my ubuntu system is

    /home/dc-335/Documents/Softwares/tensorflow/models/research/object_detection

  • Cheers, You done it !!

Kamble Tanaji
  • 487
  • 6
  • 12
9

add object_detection to the front of utils:

# from utils import label_map_util
# from utils import visualization_utils as vis_util

from object_detection.utils import label_map_util
from object_detection.utils import visualization_utils as vis_util
sailfish009
  • 2,561
  • 1
  • 24
  • 31
8

What folder are you running your python script from?

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

drec4s
  • 7,946
  • 8
  • 33
  • 54
3

I used a quicker method to fix it.

I copied the utils folder from models\research\object_detection and pasted it within the same directory as the python file which required utils

Lovesh Dongre
  • 1,294
  • 8
  • 23
2

the installation didn't go through, you will notice no module called model_utils in your project folder. uninstall it pip uninstall django-model-utils then install it again pip install django-model-utils a new app called model_utils in your project folder.

lvingstone
  • 171
  • 8
2

I used to quick method

!pip install utils

it workes properlly

avadhdtu
  • 21
  • 2
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 07 '22 at 11:09
0

faced similar issue download utils.py file and copy it in your project folder

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 28 '23 at 09:15