Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

from utils import label_map_util Import Error: No module named utils

I am trying to run the object_detection.ipynb type program but it is a normal python program(.py). It is working very well but when running inside the ..models/research/object_detection folder, but the main issue is when I am trying to run this code in another directory with proper sys.append, I am ending up with the following error:

Traceback (most recent call last):

File "obj_detect.py", line 20, in

from utils import label_map_util

ImportError: No module named utils

If I trying to import the file from ..models/research/object_detection folder into a python program in a different directory, then I end up with more errors as follows:

Traceback (most recent call last):

File "classify_image.py", line 10, in

import object_dt

File "/home/saikishor/Tensorflow_Models/models/research/object_detection/object_dt.py", line 18, in

from utils import label_map_util

File "/home/saikishor/Tensorflow_Models/models/research/object_detection/utils/label_map_util.py", line 22, in

from object_detection.protos import string_int_label_map_pb2

ImportError: No module named object_detection.protos

How to solve this issue?

like image 821
saikishor Avatar asked Sep 29 '17 17:09

saikishor


2 Answers

It could be that your object_detection folder is not on your path, so python does not know where to look for the files.

you can check this from within python with

import sys

sys.path

if this is the problem, you can solve it by

sys.path.insert(0, 'path/to/your/object_detection')
like image 115
warped Avatar answered Sep 17 '22 11:09

warped


I have seen the same problem. that's because string_int_label_map_pb2.py file doesn't exist.

1.you need to install protobuf.

https://github.com/google/protobuf/releases
  1. cd your path to object_detection

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

you will find string_int_label_map_pb2.py file in 'object_detection\protos'

  1. that will be ok, if there is still a problem, you can add your object_detection folder to PYTHONPATH.
like image 22
david_liu Avatar answered Sep 19 '22 11:09

david_liu