Python 从 utils 导入 label_map_util 导入错误:没有名为 utils 的模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46494160/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
from utils import label_map_util Import Error: No module named utils
提问by saikishor
I am trying to run the object_detection.ipynb
type program but it is a normal python program(.py). It is working very well but when running inside the ..models/research/object_detection
folder, but the main issue is when I am trying to run this code in another directory with proper sys.append
, I am ending up with the following error:
我正在尝试运行object_detection.ipynb
类型程序,但它是一个普通的 python 程序(.py)。它工作得很好,但是在..models/research/object_detection
文件夹内运行时,但主要问题是当我尝试在另一个目录中运行此代码时sys.append
,我得到了以下错误:
Traceback (most recent call last):
File "obj_detect.py", line 20, in
from utils import label_map_util
ImportError: No module named utils
回溯(最近一次调用最后一次):
文件“obj_detect.py”,第 20 行,在
from utils import label_map_util
导入错误:没有名为 utils 的模块
If I trying to import the file from ..models/research/object_detection
folder into a python program in a different directory, then I end up with more errors as follows:
如果我尝试将文件..models/research/object_detection
夹中的文件导入不同目录中的 python 程序,那么我最终会遇到更多错误,如下所示:
Traceback (most recent call last):
File "classify_image.py", line 10, in
import object_dt
File "/home/saikishor/Tensorflow_Models/models/research/object_detection/object_dt.py", line 18, in
from utils import label_map_util
File "/home/saikishor/Tensorflow_Models/models/research/object_detection/utils/label_map_util.py", line 22, in
from object_detection.protos import string_int_label_map_pb2
ImportError: No module named object_detection.protos
回溯(最近一次调用最后一次):
文件“classify_image.py”,第 10 行,在
import object_dt
文件“/home/saikishor/Tensorflow_Models/models/research/object_detection/object_dt.py”,第 18 行,在
from utils import label_map_util
文件“/home/saikishor/Tensorflow_Models/models/research/object_detection/utils/label_map_util.py”,第22行,在
from object_detection.protos import string_int_label_map_pb2
导入错误:没有名为 object_detection.protos 的模块
How to solve this issue?
如何解决这个问题?
采纳答案by warped
It could be that your object_detection folder is not on your path, so python does not know where to look for the files.
可能是你的 object_detection 文件夹不在你的路径上,所以 python 不知道在哪里查找文件。
you can check this from within python with
你可以从 python 中检查这个
import sys
sys.path
if this is the problem, you can solve it by
如果这是问题,您可以通过以下方式解决
sys.path.insert(0, 'path/to/your/object_detection')
回答by david_liu
I have seen the same problem. that's because string_int_label_map_pb2.py
file doesn't exist.
我见过同样的问题。那是因为string_int_label_map_pb2.py
文件不存在。
1.you need to install protobuf
.
1.你需要安装protobuf
.
https://github.com/google/protobuf/releases
cd
your path toobject_detection
protoc object_detection/protos/string_int_label_map.proto --python_out=.
cd
你的道路object_detection
protoc object_detection/protos/string_int_label_map.proto --python_out=。
you will find string_int_label_map_pb2.py
file in 'object_detection\protos'
你会string_int_label_map_pb2.py
在'object_detection\protos'
- that will be ok, if there is still a problem, you can add your object_detection folder to
PYTHONPATH
.
- 没关系,如果仍然有问题,您可以将 object_detection 文件夹添加到
PYTHONPATH
.
回答by saikishor
You need to download protoc version 3.3 (already compiled). Used protoc inside bin directory to run this command like this:
您需要下载 protoc 3.3 版(已编译)。在 bin 目录中使用 protoc 来运行这个命令,如下所示:
tensorflow$ mkdir protoc_3.3
tensorflow$ cd protoc_3.3
tensorflow/protoc_3.3$ wget wget https://github.com/google/protobuf/releases/download/v3.3.0/protoc-3.3.0-linux-x86_64.zip
tensorflow/protoc_3.3$ chmod 775 protoc-3.3.0-linux-x86_64.zip
tensorflow/protoc_3.3$ unzip protoc-3.3.0-linux-x86_64.zip
tensorflow/protoc_3.3$ cd ../models/research/
tensorflow/protoc_3.3$ /home/saikishor/tensorflow/protoc_3.3/bin/protoc object_detection/protos/*.proto --python_out=.
This will hopefully work!!
这有望奏效!!
回答by Lakshmi_narayana
in python*./site-packages folder , you can see the utils folder . by default , when we run "from utils import label_map_util" it will try search label_map_util in python.*/site-packages/utils folder.
在蟒蛇*中。/site-packages 文件夹,可以看到 utils 文件夹。默认情况下,当我们运行“from utils import label_map_util”时,它会尝试在 python.*/site-packages/utils 文件夹中搜索 label_map_util。
this error can solve by changing the directory or copying a file from tensorflow/models/utils to python*.*/site-packages/utils
此错误可以通过更改目录或将文件从 tensorflow/models/utils 复制到 python*.*/site-packages/utils 来解决