Skip to content

ImportError: cannot import name 'string_int_label_map_pb2' #1595

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bsrinivas84 opened this issue Jun 17, 2017 · 40 comments
Closed

ImportError: cannot import name 'string_int_label_map_pb2' #1595

bsrinivas84 opened this issue Jun 17, 2017 · 40 comments

Comments

@bsrinivas84
Copy link

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

@matmoody
Copy link

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

@bsrinivas84
Copy link
Author

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
tensorflow/tensorflow#5953
tensorflow/tensorflow#5953

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

@derekjchow
Copy link
Contributor

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

@bsrinivas84
Copy link
Author

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

@maheshmadhusudanan
Copy link

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)

@bsrinivas84
Copy link
Author

bsrinivas84 commented Jun 26, 2017

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

@4saad
Copy link

4saad commented Jul 12, 2017

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'

@sainttelant
Copy link

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

@songwg188
Copy link

songwg188 commented Aug 8, 2017

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.

@sujanchy
Copy link

sujanchy commented Sep 2, 2017

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

@yuye1992
Copy link

yuye1992 commented Sep 9, 2017

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.

@tj27-vkr
Copy link

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.

@sujanchy
Copy link

sujanchy commented Sep 11, 2017 via email

@jarvis-owl
Copy link

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.

@fera0013
Copy link

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?

@jarvis-owl
Copy link

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

@macro-dadt
Copy link

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

@devilsnare007
Copy link

@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 ##

@tawaki
Copy link

tawaki commented Dec 20, 2017

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?

@gedeon1310
Copy link

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

@yash486gadhavi
Copy link

In my case, the proto folder contains no file named 'string_int_label_map_pb2' instead there is a file named string_int_label_map.proto but still i am not able to import that file please help me

@jcRisch
Copy link

jcRisch commented Mar 8, 2018

My problems was :

  • protos correctly build pb2 files
  • "from object_detection import anchor_generator_pb2" returns no error using the python2.7 console but returned an error with "python2.7 object_detection/builders/model_builder_test.py" command

On Ubuntu17 and with tensorflow 1.6 @gedeon1310 's solution worked for me too.

Thanks

@Flyzzz
Copy link

Flyzzz commented Sep 1, 2018

same problom on windows7, download protoc-3.6.1-win32.zip,place protoc.exe to environment path ,then copy protoc.exe to C:\Windows\systerm32,then run complie protoc object_detection/protos/*.proto --python_out=.,done

@aruna09
Copy link

aruna09 commented Oct 31, 2018

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

I am getting the same error, and the link provided here seems to be broken. Any workaround for this? I am working on ubuntu 16.04

@pranka02
Copy link

pranka02 commented Dec 9, 2018

The new protoc version does not allow you to do protoc object_detection/protos/*.proto --python_out=. I hope you understand that *.proto executes the above command for all files with extension .proto in the object_detection/protos/ folder. In the new version, you will need to compile each file in protos folder individually as, for example, protoc object_detection/protos/anchor_generator.proto --python_out=.

@BlaneG
Copy link

BlaneG commented Jan 4, 2019

I am working on a Windows 10 machine. '...bin\protoc.exe' was added to my path, but for some reason the .proto files were not being converted to .py files with the command protoc object_detection/protos/*.proto --python_out=. from the tensorflow/models/research directory. I was trying this command on both cmd and MINGW64 since I was not clear where to be calling the command from previous comments.

The solution that worked for me was to include the root of protoc.exe in the command using MINGW64:
“C:\Program Files\protoc-3.4.0-win32\bin\protoc.exe” object_detection/protos/*.proto --python_out=.

@richesh09
Copy link

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

protoc object_detection/protos/*.proto --python_out=.
object_detection/protos/calibration.proto:34:3: Expected "required", "optional", or "repeated".
object_detection/protos/calibration.proto:34:6: Expected field name.
object_detection/protos/calibration.proto:48:3: Expected "required", "optional", or "repeated".
object_detection/protos/calibration.proto:48:6: Expected field name.

getting following response on running command.

@avaish1
Copy link

avaish1 commented Jun 19, 2019

The new protoc version does not allow you to do protoc object_detection/protos/*.proto --python_out=. I hope you understand that *.proto executes the above command for all files with extension .proto in the object_detection/protos/ folder. In the new version, you will need to compile each file in protos folder individually as, for example, protoc object_detection/protos/anchor_generator.proto --python_out=.

this,restarting the kernel and "from protos import string_int_label_map_pb" worked for me ..

@srivatsan18
Copy link

srivatsan18 commented Jul 21, 2019

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

This is not running in my pc is there any there solution i can do

@aish-where-ya
Copy link

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

I am getting the same error, and the link provided here seems to be broken. Any workaround for this? I am working on ubuntu 16.04

Here is the new link
https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/installation.md

@Spidy20
Copy link

Spidy20 commented Sep 8, 2019

I got a very easy solution
put this python file in object detection/protos folder:- https://github.com/datitran/object_detector_app/blob/master/object_detection/protos/string_int_label_map_pb2.py

It will solve your error

@davidnugent2425
Copy link

I got a very easy solution
put this python file in object detection/protos folder:- https://github.com/datitran/object_detector_app/blob/master/object_detection/protos/string_int_label_map_pb2.py

It will solve your error

Doing this and switching the import from 'object_detection.protos' to just 'protos' fixed it for me

@Smellegg
Copy link

Smellegg commented Apr 3, 2020

I got a very easy solution
put this python file in object detection/protos folder:- https://github.com/datitran/object_detector_app/blob/master/object_detection/protos/string_int_label_map_pb2.py
It will solve your error

Doing this and switching the import from 'object_detection.protos' to just 'protos' fixed it for me

I tried all of this but still no luck. Instead I had to also change the importobject_detection.utlis to

from object_detection.utils import ops as utils_ops
from utils import label_map_util
from object_detection.utils import visualization_utils as vis_util
from protos import string_int_label_map_pb2

@bozcani
Copy link

bozcani commented May 1, 2020

I downloaded and installed protoc from source, and it worked for me:

# You should be in folder tensorflow/models/research/
$ wget -O protobuf.zip https://github.com/google/protobuf/releases/download/v3.0.0/protoc-3.0.0-linux-x86_64.zip
$ unzip protobuf.zip
$ ./bin/protoc object_detection/protos/*.proto --python_out=.

$ cp object_detection/packages/tf2/setup.py .
$ python -m pip install --use-feature=2020-resolver .

Then, test the installation:

python object_detection/builders/model_builder_test.py

@jix1710
Copy link

jix1710 commented Jun 1, 2020

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

how to slove this error?

@jix1710
Copy link

jix1710 commented Jun 1, 2020

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

@shreyanshu09
Copy link

This error can be solved 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

@dataxsaiyan3
Copy link

dataxsaiyan3 commented May 12, 2021

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

I am having the same problem and it's been a couple of days
Thank you for the suggestion but the link doesn't work, can you guide me to another solution. I appreciate it

@FBeraZulaloglu
Copy link

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)

I am getting error like this in jupyter have you solved it ?

@SuvarnaDalin
Copy link

Error: cannot import name 'string_int_label_map_pb2' from 'object_detection.protos'

I solved this error simply by moving the .ipynb file to 'research' folder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests