简体   繁体   中英

ModuleNotFoundError: No module named 'utils'

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.

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.

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
  • 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')
  • eg '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 !!

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

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.

The simplest way is the solution described by Lovesh, just create a folder 'utils' inside your python files/tests that are using those utils. Put your utils file into the 'utils' folder and enjoy.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM