繁体   English   中英

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

[英]ModuleNotFoundError: No module named 'utils'

我正在尝试使用我的网络摄像头作为输入在 Tensorflow 中运行 object_detection API。

错误说:“从 utils 导入 label_map_util ModuleNotFoundError:没有名为 'utils' 的模块”

这与以下几行有关:

from utils import label_map_util
from utils import visualization_utils as vis_util

我试过“pip install util”似乎可以工作,但不能解决问题。 我还重新安装了多个版本的 protobuf,因为网上的其他问题似乎有这个作为解决方案。 安装 protoc 时我没有收到任何错误,所以我认为这不是问题。

我在 windows 10 和 tensorflow-gpu 上使用 python 3.6。

你从哪个文件夹运行你的python脚本?

为了能够直接访问“utils”模块,您需要在<models-master>\\research\\object_detection文件夹中运行脚本。

将 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
  • 不要在对象检测文件夹中运行脚本,而是通过编写在脚本中附加 tensorflow 对象检测的路径

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

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

  • 干杯,你做到了!!

我使用了一种更快的方法来修复它。

我从models\\research\\object_detection复制了utils文件夹并将其粘贴到与需要utils的 python 文件相同的目录中

安装没有通过,您会注意到项目文件夹中没有名为 model_utils 的模块。 卸载它pip uninstall django-model-utils然后再次安装它pip install django-model-utils在您的项目文件夹中一个名为 model_utils 的新应用程序。

最简单的方法是 Lovesh 描述的解决方案,只需在使用这些 utils 的 python 文件/测试中创建一个文件夹“utils”。 将您的 utils 文件放入 'utils' 文件夹并享受。

暂无
暂无

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

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