[英]from utils import label_map_util Import Error: No module named utils
I am trying to run the object_detection.ipynb
type program but it is a normal python program(.py). 我试图运行object_detection.ipynb
类型程序,但它是一个普通的python程序(.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: 它运行得很好,但是当在..models/research/object_detection
文件夹中运行时,但主要问题是当我尝试在另一个目录中使用正确的sys.append
运行此代码时,我最终得到以下错误:
Traceback (most recent call last): Traceback(最近一次调用最后一次):
File "obj_detect.py", line 20, in 文件“obj_detect.py”,第20行,in
from utils import label_map_util
ImportError: No module named utils ImportError:没有名为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): Traceback(最近一次调用最后一次):
File "classify_image.py", line 10, in 文件“classify_image.py”,第10行,in
import object_dt
File "/home/saikishor/Tensorflow_Models/models/research/object_detection/object_dt.py", line 18, in 文件“/home/saikishor/Tensorflow_Models/models/research/object_detection/object_dt.py”,第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 文件“/home/saikishor/Tensorflow_Models/models/research/object_detection/utils/label_map_util.py”,第22行,in
from object_detection.protos import string_int_label_map_pb2
ImportError: No module named object_detection.protos ImportError:没有名为object_detection.protos的模块
How to solve this issue? 如何解决这个问题?
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')
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 to object_detection
cd
你的object_detection
路径
protoc object_detection/protos/string_int_label_map.proto --python_out=. 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'
你会在'object_detection\\protos'
找到string_int_label_map_pb2.py
文件
PYTHONPATH
. 没问题,如果还有问题,可以将object_detection文件夹添加到PYTHONPATH
。 in python*. 在python *中。 /site-packages folder , you can see the utils folder . / site-packages文件夹,你可以看到utils文件夹。 by default , when we run "from utils import label_map_util" it will try search label_map_util in python .*/site-packages/utils folder. 默认情况下,当我们运行“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可以解决此错误
You need to download protoc version 3.3 (already compiled). 您需要下载protoc版本3.3(已编译)。 Used protoc inside bin directory to run this command like this: 在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!! 这将有希望工作!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.