简体   繁体   English

ModuleNotFoundError:没有名为“utils”的模块

[英]ModuleNotFoundError: No module named 'utils'

I'm trying to run the object_detection API in Tensorflow using my webcam as an input.我正在尝试使用我的网络摄像头作为输入在 Tensorflow 中运行 object_detection API。

The error says: "from utils import label_map_util ModuleNotFoundError: No module named 'utils'"错误说:“从 utils 导入 label_map_util ModuleNotFoundError:没有名为 '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.我试过“pip install util”似乎可以工作,但不能解决问题。 I have also reinstalled multiple versions of protobuf as other questions online appear to have this as the solution.我还重新安装了多个版本的 protobuf,因为网上的其他问题似乎有这个作为解决方案。 I don't get any errors when I install protoc so I don't think this is the issue.安装 protoc 时我没有收到任何错误,所以我认为这不是问题。

I'm using python 3.6 on windows 10 with tensorflow-gpu.我在 windows 10 和 tensorflow-gpu 上使用 python 3.6。

What folder are you running your python script from?你从哪个文件夹运行你的python脚本?

To be able to access the 'utils' module directly, you need to be running the script inside the <models-master>\\research\\object_detection folder.为了能够直接访问“utils”模块,您需要在<models-master>\\research\\object_detection文件夹中运行脚本。

add object_detection to the front of utils:将 object_detection 添加到 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不要在对象检测文件夹中运行脚本,而是通过编写在脚本中附加 tensorflow 对象检测的路径

    import sys sys.path.append('PATH_TO_TENSORFLOW_OBJECT_DETECTION_FOLDER')
  • eg 'PATH_TO_TENSORFLOW_OBJECT_DETECTION_FOLDER' in my ubuntu system is例如,我的 ubuntu 系统中的“PATH_TO_TENSORFLOW_OBJECT_DETECTION_FOLDER”是

    /home/dc-335/Documents/Softwares/tensorflow/models/research/object_detection /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我从models\\research\\object_detection复制了utils文件夹并将其粘贴到与需要utils的 python 文件相同的目录中

the installation didn't go through, you will notice no module called model_utils in your project folder.安装没有通过,您会注意到项目文件夹中没有名为 model_utils 的模块。 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.卸载它pip uninstall django-model-utils然后再次安装它pip install django-model-utils在您的项目文件夹中一个名为 model_utils 的新应用程序。

The simplest way is the solution described by Lovesh, just create a folder 'utils' inside your python files/tests that are using those utils.最简单的方法是 Lovesh 描述的解决方案,只需在使用这些 utils 的 python 文件/测试中创建一个文件夹“utils”。 Put your utils file into the 'utils' folder and enjoy.将您的 utils 文件放入 'utils' 文件夹并享受。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ModuleNotFoundError:没有名为 utils 的模块 - ModuleNotFoundError: No module named utils ModuleNotFoundError: No module named 'utils.coco_utils' utils' is not a package - ModuleNotFoundError: No module named 'utils.coco_utils' utils' is not a package ModuleNotFoundError:没有名为“utils.datasets”的模块 - ModuleNotFoundError: No module named 'utils.datasets' ModuleNotFoundError:没有名为“pandas_datareader.utils”的模块 - ModuleNotFoundError: No module named 'pandas_datareader.utils' ModuleNotFoundError:没有名为“sklearn.utils._joblib”的模块 - ModuleNotFoundError: No module named 'sklearn.utils._joblib' ModuleNotFoundError:没有名为“django.utils”的模块 - ModuleNotFoundError: No module named 'django.utils' ModuleNotFoundError:没有名为“utils.image_classifier”的模块 - ModuleNotFoundError: No module named 'utils.image_classifier' ModuleNotFoundError:没有名为“torch.utils.serialization”的模块 - ModuleNotFoundError: No module named 'torch.utils.serialization' ModuleNotFoundError:没有名为“torch.utils.benchmark”的模块 - ModuleNotFoundError: No module named 'torch.utils.benchmark' ModuleNotFoundError:没有名为“spyder.utils.iofuncs”的模块 - ModuleNotFoundError: No module named 'spyder.utils.iofuncs'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM