tensorflow / models

Models and examples built with TensorFlow
Other
77.04k stars 45.77k forks source link

cannot import name label_map_util #1990

Closed tcexeexe closed 3 years ago

tcexeexe commented 7 years ago

l follow the Installation step to install in python2.7,debian 8 and pass the "model_builder_test.py" but when l run the Object Detection Demo,the error happend:

root@australia_debian1:~/PycharmProjects/objdetection# ipython example.py

ImportError Traceback (most recent call last) /root/PycharmProjects/objdetection/example.py in () 17 # This is needed since the notebook is stored in the object_detection folder. 18 sys.path.append("..") ---> 19 from utils import label_map_util 20 21 from utils import visualization_utils as vis_util

ImportError: cannot import name label_map_util

dose anyone know how to solve this problem?

asimshankar commented 7 years ago

I apologize but I am having a hard time understanding what the problem is, where the problem is, and what version it affects. Please resubmit and pay attention to the issue template (https://github.com/tensorflow/tensorflow/issues/new) . Please provide all the information it asks. Thank you.

In particular, detailed instructions to reproduce the problem will be most helpful. As of now, it is not clear to me whether the notebook file is in the expected directory from where it can access all the libraries. (From your log it seems you're using some file called example.py, where is that coming from? There is no such file in the object_detection directory)

sjwhhhi commented 7 years ago

I have the same question You can change label_map_util.py (in utils folder) line 22 to from protos import string_int_label_map_pb2.

RobinBaumann commented 7 years ago

I have faced the same error: I found out that I only get it when running my commands from another directory than the project root directory.

To see if you installed the API correctly, you can run the following command from the tensorflow/models directory:

python object_detection/protos/label_map_util_test.py

It should print out OK.

Edit: There are indentation errors in the test file from line 79-107

ayushmaan commented 6 years ago

Hi, I solve this just 1) git clone https://github.com/tensorflow/models in tensorflow folder.

From tensorflow/models/research/

2) protoc object_detection/protos/*.proto --python_out=.

3)# From tensorflow/models/research/ export PYTHONPATH=$PYTHONPATH:pwd:pwd/slim

Viveco commented 6 years ago

I have faced the same error: ImportError: cannot import name 'label_map_util' so The file in ‘object_detection/utils’

mordka commented 6 years ago

After cloning tensorflow models, running protoc object_detection/protos/*.proto --python_out=. and exporting PYTHONPATH it still failed but changing the import helped: from object_detection.utils import label_map_util

karthi-keyan commented 6 years ago

I have faced the same error: ImportError: cannot import name 'label_map_util' i just install setup.py in research folder and i copied that object_detection and .egg.info in sitepackages folder

imvinaypatil commented 6 years ago

I tried running these commands as mentioned from a jupyter notebook:

git clone https://github.com/tensorflow/models in tensorflow folder.

From tensorflow/models/research/

protoc object_detection/protos/*.proto --python_out=.

3)# From tensorflow/models/research/ export PYTHONPATH=$PYTHONPATH:pwd:pwd/slim

but it still doesnot work

monomon commented 6 years ago

This seems to be coming up very frequently - make sure object_detection is in your PYTHONPATH!

duancaohui commented 6 years ago

My system is windows 10, python 3.6 and I install protoc-3.4.0-win32 not protoc-3.5.0-win32, protoc-3.5 for windows has bug!!! After running protoc object_detection/protos/*.proto --python_out=. just change from utils import label_map_util
to from object_detection.utils import label_map_util

alaparthishivaji commented 6 years ago

I am facing issue in windows 10 ,python 3.6 in object detection can any one help me out these, i am facing errors as name 'label_map_util' is not defined & No module named 'utils'

AdityaPai2398 commented 6 years ago

I am facing the same problem right now from utils import label_map_util

ModuleNotFoundError: No module named 'utils'

It mostly happens if you've changed the working directory,so you need to add it to the PATH

Viveco commented 6 years ago

I am faceing issue in Mac ,python 3.5.6. I add the path ,but it still doesn't work , I try to do it. like : export PYTHONPATH=$PYTHONPATH:pwd:pwd/slim

so,not working . I ask question for my teacher, so he tell me the Mac operating system is ‘Unix’,unlike linux。 Every time I do this, it doesn't work。

AdityaPai2398 commented 6 years ago

@Viveco what's the protoc version that you're using?

parmarmanoj007 commented 6 years ago

import like this...

from object_detection.utils import label_map_util

frontr-uk commented 5 years ago

@parmarmanoj007 still does not work :(

monomon commented 5 years ago

Note that the object_detection directory needs to be in PYTHONPATH, not its parent.

naivesecret commented 5 years ago

I tried all of the methods from internet and they didn't work. At last, I solve this problem on mac: My pip3 and python3 were not matched. I solve this just:

  1. pip3 uninstall pip
  2. brew uninstall python (whatever, just uninstall your python3. My python3 was installed by 'brew install python')
  3. brew install python and it works!
hemali-14 commented 5 years ago

I'm also getting same error.

from object_detection.utils import label_map_util File "/usr/local/lib/python2.7/dist-packages/object_detection-0.1-py2.7.egg/object_detection/utils/label_map_util.py", line 21, in from object_detection.protos import string_int_label_map_pb2 ImportError: cannot import name string_int_label_map_pb2

gutruaircraft commented 5 years ago

protoc object_detection/protos/*.proto --python_out=.

it is not recognizing fo me, I am using Windows 7

BlakeJin1234 commented 5 years ago

PS D:\TensorFlow_Supporting\models-master\research> python object_detection/builders/model_builder_test.py Traceback (most recent call last): File "object_detection/builders/model_builder_test.py", line 23, in from object_detection.builders import model_builder File "D:\TensorFlow_Supporting\models-master\research\object_detection\builders\model_builder.py", line 37, in from object_detection.models import faster_rcnn_inception_v2_feature_extractor as frcnn_inc_v2 File "D:\TensorFlow_Supporting\models-master\research\object_detection\models\faster_rcnn_inception_v2_feature_extractor.py", line 24, in from nets import inception_v2 ImportError: cannot import name 'inception_v2' I dont know what should i do......

BlakeJin1234 commented 5 years ago

I solved my problem. PYTHONPATH D:\TensorFlow_Supporting\modelsmaster\research\slim;D:\TensorFlow_Supporting\models-maste
here not " \ research " HAHAHA.....

kiad4631 commented 5 years ago

Hi guys.Please help me.

if i run object_detection_toturial code with protobuf=3.0.0 i get this error: serialized_pb=_b('\n,tensorflow/core/framework/tensor_shape.proto\x12\ntensorflow\"z\n\x10TensorShapeProto\x12-\n\x03\x64im\x18\x02 \x03(\x0b\x32 .tensorflow.TensorShapeProto.Dim\x12\x14\n\x0cunknown_rank\x18\x03 \x01(\x08\x1a!\n\x03\x44im\x12\x0c\n\x04size\x18\x01 \x01(\x03\x12\x0c\n\x04name\x18\x02 \x01(\tBq\n\x18org.tensorflow.frameworkB\x11TensorShapeProtosP\x01Z=github.com/tensorflow/tensorflow/tensorflow/go/core/framework\xf8\x01\x01\x62\x06proto3') TypeError: new() got an unexpected keyword argument 'serialized_options'

and if i run code with protobuf=3.6.1 i get this:

ModuleNotFoundError: No module named 'object_detection.utils'; 'object_detection' is not a package

i set export PYTHONPATH=$PYTHONPATH:pwd:pwd/slim too. please help i am very confused

BlakeJin1234 commented 5 years ago

'object_detection' is not a package ;I think that you should to add init.py in the folder,

kiad4631 commented 5 years ago

'object_detection' is not a package ;I think that you should to add init.py in the folder,

i have it

BlakeJin1234 commented 5 years ago

PYTHONPATH = $ PYTHONPATH:pwd:pwd / slim ; another :PYTHONPATH = $ PYTHONPATH:。。。。/(Folder Name of "object_detection's Upper Level)?

kiad4631 commented 5 years ago

PYTHONPATH = $ PYTHONPATH:pwd:pwd / slim ; another :PYTHONPATH = $ PYTHONPATH:。。。。/(Folder Name of "object_detection's Upper Level)?

Folder name of object_detection's Upper Level is research.and i run PYTHONPATH = $ PYTHONPATH:pwd:pwd / slim in this directoy

kiad4631 commented 5 years ago

I tried running these commands as mentioned from a jupyter notebook:

git clone https://github.com/tensorflow/models in tensorflow folder.

From tensorflow/models/research/

protoc object_detection/protos/*.proto --python_out=.

3)# From tensorflow/models/research/ export PYTHONPATH=$PYTHONPATH:pwd:pwd/slim

but it still doesnot work

me too.did you find a solution?

BlakeJin1234 commented 5 years ago

PYTHONPATH = $ PYTHONPATH:。。。。/models ; NOT‘s PYTHONPATH = $ PYTHONPATH:。。。。/models/research ; maybe,i'm not sure。

kiad4631 commented 5 years ago

PYTHONPATH = $ PYTHONPATH:。。。。/models ; NOT‘s PYTHONPATH = $ PYTHONPATH:。。。。/models/research ; maybe,i'm not sure。

but i have slim in research directory.it should not be wrong

BlakeJin1234 commented 5 years ago

I solved my problem. PYTHONPATH D:\TensorFlow_Supporting\modelsmaster\research\slim;D:\TensorFlow_Supporting\models-maste ;

应该有两个路经吧,。。。/slim ;。。。/models ;

pirate-lofy commented 5 years ago

I found the solution here https://stackoverflow.com/questions/51569669/python-from-utils-import-label-map-util-importerror-cannot-import-name-lab/51574399

raedkit commented 4 years ago

Hi, you have to do the following commands to make it work for you : protoc object_detection/protos/*.proto --python_out=. Add the following to your ~/.bashrc : export PYTHONPATH=$PYTHONPATH:<PATH_TO_TF>/TensorFlow/models/research/object_detection:<PATH_TO_TF>/TensorFlow/models/research:<PATH_TO_TF>/TensorFlow/models/research/slim

Mahesh-Bandi commented 4 years ago

I'm also getting same error.

from object_detection.utils import label_map_util File "/usr/local/lib/python2.7/dist-packages/object_detection-0.1-py2.7.egg/object_detection/utils/label_map_util.py", line 21, in from object_detection.protos import string_int_label_map_pb2 ImportError: cannot import name string_int_label_map_pb2

after running protoc object_detection\protos\string_int_label_map.proto make sure string_int_label_map_pb2.py file is created in object_detection\protos directory. I had the same problem.

Mahesh-Bandi commented 4 years ago

protoc object_detection/protos/*.proto --python_out=.

it is not recognizing fo me, I am using Windows 7

this short command is not working in windows. so instead of *.proto in the command include all the .proto files names in the command and run it. after that validate .py file is created for each .proto files. i.e string_int_label_map_pb2.py for string_int_label_map.proto ... etc.

google-ml-butler[bot] commented 3 years ago

Are you satisfied with the resolution of your issue? Yes No

ilkin94 commented 3 years ago

After cloning tensorflow models, running protoc object_detection/protos/*.proto --python_out=. and exporting PYTHONPATH it still failed but changing the import helped: from object_detection.utils import label_map_util

Following code is needed at the end. Otherwise it will still fail: pip install tensorflow-object-detection-api

mcbridemarci commented 3 years ago

Resolved on a Mac, running Python 3.9.5.

sys.path.append('tensorflow/models/research/') sys.path.append('tensorflow/models/research/object_detection/') from utils import label_map_util from utils import visualization_utils as vis_util

busedagidir commented 2 years ago

first I was able to do from object_detection.utils import dataset_util but I couldn't add import label_map_util like this: from object_detection.utils import dataset_util, label_map_util

then I tried this on windows cmd: pip install tensorflow-object-detection-api

I can run it successfully

priyanka-hande commented 2 years ago

I'm getting an error. category_index = label_map_util.create_category_index_from_labelmap(files['LABELMAP']) name error: name 'label_map_util' is not defined