13

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?

Community
  • 1
  • 1
saikishor
  • 768
  • 2
  • 9
  • 20
  • what do you mean by "normal type of program"? Did you create a virtual environment for your project? Where did you get these scripts? Your script simply cannot see the modules you are trying to use, in other words these modules are not in Python path. You can read about it here: https://stackoverflow.com/questions/19917492/how-to-use-pythonpath – Leo Skhrnkv Sep 29 '17 at 17:47
  • No i mean to say that I edited the code present in object_detection.ipynb to a new python file as per my requirement. – saikishor Sep 30 '17 at 19:44

4 Answers4

11

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')
warped
  • 6,239
  • 3
  • 16
  • 35
  • The problem is you can't do that way, as the depending files inside the folder are imported in a different manner like from object_detection.ptoso import .... – saikishor Sep 30 '17 at 19:45
  • 3
    what is this "path/to/your/object_detection"? i don't understand... can you explain? – Sudip Das Feb 07 '18 at 13:55
  • The location of the object detection folder. For example "c:/projects/object_detection" or "/home/projects/object_detection" – warped Feb 07 '18 at 16:07
3

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.
8-Bit Borges
  • 8,099
  • 15
  • 64
  • 132
david_liu
  • 59
  • 2
0

in python*./site-packages folder , you can see the utils folder . by default , when we run "from utils import label_map_util" it will try search label_map_util in python.*/site-packages/utils folder.

this error can solve by changing the directory or copying a file from tensorflow/models/utils to python*.*/site-packages/utils

0

You need to download protoc version 3.3 (already compiled). Used protoc inside bin directory to run this command like this:

tensorflow$ mkdir protoc_3.3
tensorflow$ cd protoc_3.3
tensorflow/protoc_3.3$ wget wget https://github.com/google/protobuf/releases/download/v3.3.0/protoc-3.3.0-linux-x86_64.zip
tensorflow/protoc_3.3$ chmod 775 protoc-3.3.0-linux-x86_64.zip
tensorflow/protoc_3.3$ unzip protoc-3.3.0-linux-x86_64.zip
tensorflow/protoc_3.3$ cd ../models/research/
tensorflow/protoc_3.3$ /home/saikishor/tensorflow/protoc_3.3/bin/protoc object_detection/protos/*.proto --python_out=.

This will hopefully work!!

saikishor
  • 768
  • 2
  • 9
  • 20