cannot import name 'string_int_label_map_pb2'
Question:
My goal is to run tensorflow object detection API and followed the steps in the installation.
I install the tensorflow object detection API and protobuf.
I have also added the path to protobuf.
But the following error shoots up:
ImportError: cannot import name 'string_int_label_map_pb2'
Installed protobuf :
%%bash
cd models/research
protoc object_detection/protos/*.proto --python_out=.
A block of code containing the error import statements:
from object_detection.utils import ops as utils_ops
from object_detection.utils import label_map_util
from object_detection.utils import visualization_utils as vis_util
Answers:
Install protoc-3.11.4 from
https://github.com/google/protobuf/releases
and run protoc object_detection/protos/*.proto --python_out=.
as mentioned in the installation instructions. And put this file in in object detection/protos
it’s a simple path issue from this package so, we need to append the path of protos/string_int_label_map_pb2.py inside utils/label_map_util.py
instead of this
from objection_detection.protos import string_int_label_map_pb2
it should be
import sys
sys.path.append("..")
from protos import string_int_label_map_pb2
Also, if you have done pip installation of object_detection then open these files from site-packages/objection_detection/utils.. else you can replace it in the git files under
model-master/research/objection_detection/utils.
You can try this suggestion in the same order
see models/issues/1962#
Or
git clone https://github.com/tensorflow/models.git
cd models/research
protoc -I=./ --python_out=./ ./object_detection/protos/*.proto
export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim
import sys
sys.path.append('/content/models/research/object_detection') # ~/tensorflow/models/research/object_detection
#try import now..
from utils import label_map_util
The solution that works for me is as follows:
If you are creating a Virtual environment:
Run the command after you create the environment to change the Google file .protp
to .py
:
protoc object_detection/protos/*.proto --python_out=.
However, if you are still facing an error, you can simply run the code on a google colab notebook:
Protos Conversion to Python
%%cd /content/drive/MyDrive/TFOD1.x/models/research
!protoc object_detection/protos/*.proto --python_out=.
get the file in protoc folder, then copy it into the >models>research>protoc
And (import step):
Copy the folder to your environment path:
For example:
C:Usersx04xx18Anaconda3envstfod1.xlibsprotos
This should fix the error for you!
My goal is to run tensorflow object detection API and followed the steps in the installation.
I install the tensorflow object detection API and protobuf.
I have also added the path to protobuf.
But the following error shoots up:
ImportError: cannot import name 'string_int_label_map_pb2'
Installed protobuf :
%%bash
cd models/research
protoc object_detection/protos/*.proto --python_out=.
A block of code containing the error import statements:
from object_detection.utils import ops as utils_ops
from object_detection.utils import label_map_util
from object_detection.utils import visualization_utils as vis_util
Install protoc-3.11.4 from
https://github.com/google/protobuf/releases
and run protoc object_detection/protos/*.proto --python_out=.
as mentioned in the installation instructions. And put this file in in object detection/protos
it’s a simple path issue from this package so, we need to append the path of protos/string_int_label_map_pb2.py inside utils/label_map_util.py
instead of this
from objection_detection.protos import string_int_label_map_pb2
it should be
import sys
sys.path.append("..")
from protos import string_int_label_map_pb2
Also, if you have done pip installation of object_detection then open these files from site-packages/objection_detection/utils.. else you can replace it in the git files under
model-master/research/objection_detection/utils.
You can try this suggestion in the same order
see models/issues/1962#
Or
git clone https://github.com/tensorflow/models.git
cd models/research
protoc -I=./ --python_out=./ ./object_detection/protos/*.proto
export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim
import sys
sys.path.append('/content/models/research/object_detection') # ~/tensorflow/models/research/object_detection
#try import now..
from utils import label_map_util
The solution that works for me is as follows:
If you are creating a Virtual environment:
Run the command after you create the environment to change the Google file .protp
to .py
:
protoc object_detection/protos/*.proto --python_out=.
However, if you are still facing an error, you can simply run the code on a google colab notebook:
Protos Conversion to Python
%%cd /content/drive/MyDrive/TFOD1.x/models/research
!protoc object_detection/protos/*.proto --python_out=.
get the file in protoc folder, then copy it into the >models>research>protoc
And (import step):
Copy the folder to your environment path:
For example:
C:Usersx04xx18Anaconda3envstfod1.xlibsprotos
This should fix the error for you!