cannot import name 'string_int_label_map_pb2'

Viewed 14057

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
3 Answers

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

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.

Related