models icon indicating copy to clipboard operation
models copied to clipboard

ImportError: cannot import name 'string_int_label_map_pb2'

Open Futi7 opened this issue 7 years ago • 14 comments

C:\tensorflow\models\research>python object_detection\model_main.py --pipeline_config_path=object_detection\training\ssd_mobilenet_v1_pets.config --model_dir=object_detection\images --num_train_steps=50000 --sample_1_of_n_eval_examples=1 --alsologtostderr Traceback (most recent call last): File "object_detection\model_main.py", line 26, in from object_detection import model_lib File "C:\Users\Fuat\AppData\Local\Programs\Python\Python35\lib\site-packages\object_detection\model_lib.py", line 27, in from object_detection import eval_util File "C:\Users\Fuat\AppData\Local\Programs\Python\Python35\lib\site-packages\object_detection\eval_util.py", line 27, in from object_detection.metrics import coco_evaluation File "C:\Users\Fuat\AppData\Local\Programs\Python\Python35\lib\site-packages\object_detection\metrics\coco_evaluation.py", line 22, in from object_detection.utils import object_detection_evaluation File "C:\Users\Fuat\AppData\Local\Programs\Python\Python35\lib\site-packages\object_detection\utils\object_detection_evaluation.py", line 39, in from object_detection.utils import label_map_util File "C:\Users\Fuat\AppData\Local\Programs\Python\Python35\lib\site-packages\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'

I got this error.How can i fix it.I installed protobuf, compiled it, added to path.There are no files such as 'string_int_label_map.prot'.

Top-level directory:c:/tensorflow/models OS:Windows 10 CPU:AMD A9 7th Gen. GPU:AMD Radeon R5 M420 2GB Python version:3.6 Protobuf version:3.4.0 Tensorflow installed from:pip Tensorflow Version:1.12.0 Bazel version:N/A CUDA/cuDNN version:N/A Exact command:#from tensorflow/models/research/object_detection python model_main.py --logtostderr --train_dir=training/ --pipeline_config_path=training/ssd_mobilenet_v1_coco.config

Futi7 avatar Feb 04 '19 03:02 Futi7

Thank you for your post. We noticed you have not filled out the following field in the issue template. Could you update them if they are relevant in your case, or leave them as N/A? Thanks. What is the top-level directory of the model you are using Have I written custom code OS Platform and Distribution TensorFlow installed from TensorFlow version Bazel version CUDA/cuDNN version GPU model and memory Exact command to reproduce

tensorflowbutler avatar Feb 05 '19 00:02 tensorflowbutler

Did you do protobuf compilation as in: https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/installation.md#protobuf-compilation

yu-jingrui avatar Feb 05 '19 14:02 yu-jingrui

@fisheess yes i tried it with all protobuf-3.x.x versions last time i did there was string_int_label_map_pb2.py file but still getting this error

Futi7 avatar Feb 05 '19 15:02 Futi7

Can someone help me with this problem please im stuck at this error can't move forward.

Futi7 avatar Feb 07 '19 01:02 Futi7

I just had this problem on a 2nd machine of mine that had a snapshot of the repository on February 14th, 2019. I looked at my 1st machine with a snapshot pulled some time around September 2nd, 2018 and the import works. So some change between these dates is causing the problem.

When I updated my 2nd machine with the protos and utils folders from my 1st machine, the error went away...

chaosbuster avatar Feb 20 '19 17:02 chaosbuster

I guess i figured it out.I switched to Ubuntu OS from Windows 10 OS.Uninstalled python2.x.x then installed python 3.6 used pip3 for all libraries and executed with python3.Problem might be because of conflicts between python2 libs and python3 libs and the PYTHONPATH you setted.Be sure to install libs for the python version you used(pip for python2,pip3 for python3).Thank you for your answers.

Futi7 avatar Feb 28 '19 12:02 Futi7

I'am still having the same error, looking into "object_detection.protos" there is no 'string_int_label_map_pb2'. I have already compiled and run protobuf as it reefers in https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/installation.md#protobuf-compilation. It seems that the archive is missing.

lukinsb avatar Jun 25 '19 16:06 lukinsb

I am having the same problem.

gireeshkbogu avatar Jul 22 '19 18:07 gireeshkbogu


ImportError Traceback (most recent call last) in 2 sys.path.append("/Users/jivira/Tensorflow-License-Plate-Detection-master/object_detection") 3 ----> 4 from utils import label_map_util 5 from utils import visualization_utils as vis_util 6

~/Tensorflow-License-Plate-Detection-master/object_detection/utils/label_map_util.py in 24 import tensorflow as tf 25 from google.protobuf import text_format ---> 26 from object_detection.protos import string_int_label_map_pb2 27 28

ImportError: cannot import name 'string_int_label_map_pb2'

Similar problem is faced by me where the above mentioned cmds are not helping

jigarvira avatar Aug 20 '19 07:08 jigarvira

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

Spidy20 avatar Sep 08 '19 05:09 Spidy20

also you what you can do is run protoc command, it will create .py files for each .proto files. But make sure that this command run successfully and created .py files for each .proto files in the path object_detection\protos.

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

this short command don't run on windows. so instead of *.proto in the command, mention all .proto files in it and run.

Even if it is not working depend on TF/Objection Detection API version try below: from utils import label_map_util replace above line with from object_detection.utils import label_map_util

or may be issue with this. so just replace it. from object_detection.protos import string_int_label_map_pb2 replace with from protos import string_int_label_map_pb2

Mahesh-Bandi avatar Feb 14 '20 07:02 Mahesh-Bandi

Simply, go to protos dirctory in object detection folder in your pc and put this python file into the it: https://github.com/datitran/object_detector_app/blob/master/object_detection/protos/string_int_label_map_pb2.py

Mehran970 avatar May 16 '20 05:05 Mehran970

After putting this file now also same issue is coming . What is permanent solution??

py3-coder avatar Feb 27 '22 19:02 py3-coder

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

this was very helpful

rivondave avatar Mar 02 '22 11:03 rivondave