models icon indicating copy to clipboard operation
models copied to clipboard

ImportError: cannot import name 'string_int_label_map_pb2'

Open bsrinivas84 opened this issue 9 years ago • 40 comments

In step "Object detection imports" I am getting the following error

ImportError Traceback (most recent call last) in () ----> 1 from utils import label_map_util 2 3 from utils import visualization_utils as vis_util D:\Personal\learn\ML\DL\Tensorflow\Official-Tutorial\models-master\object_detection\utils\label_map_util.py in () 20 import tensorflow as tf 21 from google.protobuf import text_format ---> 22 from object_detection.protos import string_int_label_map_pb2 23 24 ImportError: cannot import name 'string_int_label_map_pb2'

To workaround/proceed I commented the following line in "label_map_util.py" from object_detection.protos import string_int_label_map_pb2

But I am now getting error at step "Loading label map" NameError: name 'string_int_label_map_pb2' is not defined

So need your help to solve the error in step "Object detection imports" Appreciate the help to proceed further

bsrinivas84 avatar Jun 17 '17 17:06 bsrinivas84

Make sure you run protoc object_detection/protos/*.proto --python_out=. as mentioned in installation instructions: https://github.com/tensorflow/models/blob/master/object_detection/g3doc/installation.md

matmoody avatar Jun 17 '17 19:06 matmoody

Thanks mat for the quick response. I am unable to locate the tensorflow/models directory.

Couple of hits got me to these links, but It did not help me find the directory https://github.com/tensorflow/tensorflow/issues/5953 https://github.com/tensorflow/tensorflow/issues/5953

For windows OS, the steps need to be better? Please help

bsrinivas84 avatar Jun 17 '17 19:06 bsrinivas84

@bsrinivas84 tensorflow/models refers to the root of the git checkout.

derekjchow avatar Jun 17 '17 20:06 derekjchow

Thanks Derek, realized first I had to install protoc-3.2.0-windows-x86_64.exe from https://github.com/google/protobuf/releases (pointed environment variables to include the path to installation) and then go to root and run the command. It worked, Many Thanks

bsrinivas84 avatar Jun 18 '17 07:06 bsrinivas84

Anybody who is getting an import error in Jupyter notebook even after updating the PYTHONPATH make sure you restart the notebook. (i wasted couple of hours trying to chase down this problem)

maheshmadhusudanan avatar Jun 25 '17 21:06 maheshmadhusudanan

Mahesh which error are you getting? If its the protof please follow the instructions here to install as pointed above https://github.com/tensorflow/models/blob/master/object_detection/g3doc/installation.md

Also make sure you re-download the latest version of code

bsrinivas84 avatar Jun 26 '17 07:06 bsrinivas84

i am still beginner i am trying to install tensorflow object detection API on windows i followed the instruction like that :

  1. I installed protoc
  2. protoc object_detection/protos/*.proto --python_out=.
  3. set PYTHONPATH=$PYTHONPATH:pwd:pwd/slim
  4. but i am getting this error: C:\Users\DigitalNet\AppData\Local\Programs\Python\Python35\Lib\site-packages\ten sorflow\models>python object_detection/builders/model_builder_test.py Traceback (most recent call last): File "object_detection/builders/model_builder_test.py", line 21, in from object_detection.builders import model_builder File "C:\Users\DigitalNet\AppData\Local\Programs\Python\Python35\lib\site-pack ages\object_detection-0.1-py3.5.egg\object_detection\builders\model_builder.py", line 17, in from object_detection.builders import anchor_generator_builder File "C:\Users\DigitalNet\AppData\Local\Programs\Python\Python35\lib\site-pack ages\object_detection-0.1-py3.5.egg\object_detection\builders\anchor_generator_b uilder.py", line 20, in from object_detection.protos import anchor_generator_pb2 ImportError: cannot import name 'anchor_generator_pb2'

4saad avatar Jul 12 '17 10:07 4saad

yes, i got the same error as 4saad mentioned, i checked the builder folder, where i found the anchor_generator-pb2.py which it has already been there, i still got the error like this

sainttelant avatar Aug 04 '17 02:08 sainttelant

I also got the same error as 4saad mentioned that cannot import name 'anchor_generator_pb2' even if i found the file of ' anchor_generator-pb2.py'. However,when i come into python environment in cmd, from object_detection.protos import anchor_generator_pb2 is correct.

C:\Users\swg\Anaconda3\Lib\site-packages\tensorflow\models>python Python 3.5.2 |Anaconda 4.2.0 (64-bit)| (default, Jul 5 2016, 11:41:13) [MSC v.1900 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> from object_detection.protos import anchor_generator_pb2 >>> In this case, It can work.

songwg188 avatar Aug 08 '17 15:08 songwg188

Hi songwg188, do you found any solution for the issue? I have also faced same problem as you mentioned. import is working from python environment, but I couldn't run the following command: python object_detection/builders/model_builder_test.py from command prompt. Any help will be appreciable

sujanchy avatar Sep 02 '17 23:09 sujanchy

i had the same error,but i solved it. make sure your protoc version >=2.6,download tensorflow/model to a new folder ,and re-install it.

yuye1992 avatar Sep 09 '17 03:09 yuye1992

The application is looking for anchor_generator_pb2 in /usr/local/python3. Include the path in the python environment as mentioned in the installation guide. Or install the object_detection API with models/setup.py. All the libraries will be then installed.

tj27-vkr avatar Sep 10 '17 14:09 tj27-vkr

Thanks. I have solved the issue. Actually I have to delete the log before running next time. That creates problem. 

Sujan Chowdhury

From: tj27 [email protected] To: tensorflow/models [email protected] Cc: Sujan Chowdhury [email protected]; Comment [email protected] Sent: Monday, September 11, 2017 12:09 AM Subject: Re: [tensorflow/models] ImportError: cannot import name 'string_int_label_map_pb2' (#1595)

The application is looking for anchor_generator_pb2 in /usr/local/python3. Include the path in the python environment as mentioned in the installation guide. Or install the object_detection API with models/setup.py. All the libraries will be then installed.— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

sujanchy avatar Sep 11 '17 00:09 sujanchy

hej okay i fixed it by editing object_detection/utils/label_map_util.py line 22 #from object_detection.protos import string_int_label_map_pb2 from protos import string_int_label_map_pb2

I guess it's because the jupyter notebook already is in the object_detection directory.

@sujanchy what log to clear? @tj27-vkr used models/setup.py build followed by models/setup.py install - could not cure it.

jarvis-owl avatar Sep 27 '17 20:09 jarvis-owl

I get

object_detection/protos/*.proto: Invalid argument

when I run

C:\Users\Me\Documents\GitHub\tensorflow\models\research> protoc o
bject_detection/protos/*.proto --python_out=.

On my windows 10 machine. What could be the problem?

fera0013 avatar Sep 30 '17 10:09 fera0013

Okay, I can reproduce that output. It works, when I specify the exact path to 'protoc.exe'

jarvis-owl avatar Sep 30 '17 10:09 jarvis-owl

Make sure you run:

From tensorflow/models/research/

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

From tensorflow/models/research/

export PYTHONPATH=$PYTHONPATH:pwd:pwd/slim

macro-dadt avatar Nov 17 '17 02:11 macro-dadt

@fera0013 , if you're on windows and running that command it won't work, for some reason it doesn't recognize /* as iterating thru all .proto files, you will have to manually (or create a batch file) do all .proto files one by one: D:\Tensorflow_Object_Detection_API\protoc-3.5\bin\protoc object_detection/protos/"filename.proto" --python_out=.
##Running this from the folder containing protoc.exe ##

devilsnare007 avatar Dec 03 '17 00:12 devilsnare007

I am using windows 10 with python 3.6.3 instead of using protoc object_detection/protos/*.proto --python_out=. I use for %i in (object_detection\protos\*.proto) DO protoc %i --python_out=. set PYTHONPATH=$PYTHONPATH:pwd:pwd/slim it create .py file for each .proto file in that folder.

However, I also have the same problem when run from object_detection.protos import string_int_label_map_pb2 still have error ImportError: cannot import name 'string_int_label_map_pb2 If I run from protos import string_int_label_map_pb2 another error shows up ModuleNotFoundError: No module named 'protos'

Is there other way to solve this problem?

tawaki avatar Dec 20 '17 21:12 tawaki

On windows 10, assuming that you fixed protoc issues as indicated above, I also ran commands: python setup.py build then python setup.py install for in research folder and slim folder (you may also have encountered some import issues with commands like ''from nets import ... )

I then copied copied related egg files into my libray path (related to my tensorflow environment):

C:\Users\test\Anaconda3\envs\tensorflow\Lib\site-packages

I finally have in this folder following files:

  • slim-0.1-py3.5.egg
  • object_detection-0.1-py3.5.egg

and folders:

  • slim.egg-info
  • object_detection.egg-info

this allowed to run from Anaconda prompt (in_..\models\research_) the test command indicated in installation guidelines: python object_detection/builders/model_builder_test.py

gedeon1310 avatar Jan 10 '18 16:01 gedeon1310