models icon indicating copy to clipboard operation
models copied to clipboard

object_detection ImportError: No module named 'object_detection'

Open lucasjinreal opened this issue 9 years ago • 25 comments

in research directory, Simply run:

python object_detection/builders/model_builder_test.py

as readme install suggested. Got the error:

ImportError: No module named 'object_detection'

I know this is a low-level error, but the tutorial in readme is really misleading, follow that command just got this error message. in object_detection many files are using from object_detection import ..., So how to solve this problem???

lucasjinreal avatar Oct 24 '17 03:10 lucasjinreal

go to the research directory and type:

export PYTHONPATH=$PYTHONPATH:pwd:pwd/slim

jjahanip avatar Oct 24 '17 19:10 jjahanip

'export' is not recognized as an internal or external command, operable program or batch file.

T0MTOM1 avatar Oct 26 '17 01:10 T0MTOM1

if you are in WINDOES you can use the following command (from the research directory): SET PYTHONPATH=%cd%:%cd%\slim

if working with editors (like PyCharm) you can add path to PYTHONPATH variable from the software.

jjahanip avatar Oct 26 '17 03:10 jjahanip

@jjahanip So many thanks, I'll check it again.

lucasjinreal avatar Oct 26 '17 03:10 lucasjinreal

i am working in anaconda and i get a similar error accept it says: File "object_detection/builders/model_builder_test.py", line 21, in from object_detection.builders import model_builder ModuleNotFoundError: No module named 'object_detection'

wsuppiger avatar Oct 31 '17 05:10 wsuppiger

@williamsuppiger Maybe this is not supporte anymore? This is an obvious mistake.

lucasjinreal avatar Oct 31 '17 05:10 lucasjinreal

@jinfagang @williamsuppiger this error usually occurs if you fail to set the PYTHONPATH as mentioned by @jjahanip . Have you tried setting it ?

tombstone avatar Nov 02 '17 22:11 tombstone

if you use windows add in model_builder_test.py after import tensorflow as tf.

 import sys
   sys.path.append("{YOU_PATH}\\models-master\\research\\")
      sys.path.append("{YOU_PATH}\\models-master\\research\\object_detection\\utils")

temiklis avatar Nov 03 '17 12:11 temiklis

I will close this for now since things seems to work as expected. If you are still having problems please feel free to reopen this issue.

tombstone avatar Nov 18 '17 07:11 tombstone

After I entered 'export PYTHONPATH=$PYTHONPATH:pwd:pwd/slim' to get around the Import error for object detection, I got another import error

ImportError: No module named nets

imrandatascientist avatar Dec 29 '17 14:12 imrandatascientist

to correct @jjahanip, on windows is SET PYTHONPATH=%cd%;%cd%\slim. It's ';' not ':'

klauszeng avatar Jan 30 '18 07:01 klauszeng

One possible reason for this might be that you are not running the Jupyter Notebook in the same terminal where you set the $PYTHONPATH value.

Or you can try to add $PYTHONPATH value into your ~/.bashrc file (or ~/.zshrc file if you are using 'oh my zsh')

EricTheAI avatar Feb 14 '18 02:02 EricTheAI

on windows the line is :

SET PYTHONPATH=%cd%;%cd%\slim

NOT SET PYTHONPATH=%cd%:%cd%\slim

You can test with : echo %PYTHONPATH%

it should give you somethine like \models\research;\models\research\slim

jpdoiron avatar Jun 20 '18 15:06 jpdoiron

Has anyone tried the same thing on floydhub? I am getting the modulenotfound error there. Can anyone help me?

uthiraa avatar Jul 19 '18 22:07 uthiraa

When i am running the ipython in object detection i am getting an error in line 17 saying that i do not have tensor flow how to avoid this error

I tried add these two lines and it works for me. import sys sys.path.append("..")

gfjiyue avatar Sep 13 '18 07:09 gfjiyue

If anyone has the same issue in a Kaggle kernel, here is one fix:

import os
os.environ['PYTHONPATH'] += ':/kaggle/working/models/research/:/kaggle/working/models/research/slim/'

rbarman avatar Mar 10 '19 17:03 rbarman

from imageai.Detection import ObjectDetection error at this line while running as windows service. please help me.

ghost avatar May 07 '19 12:05 ghost

If anyone has the same issue in a Kaggle kernel, here is one fix:

import os
os.environ['PYTHONPATH'] += ':/kaggle/working/models/research/:/kaggle/working/models/research/slim/'

Great working on colab too!

ravi3222 avatar Oct 19 '19 11:10 ravi3222

Thank you very much..... for windows user......

import sys sys.path.append("{YOU_PATH}\models-master\research\") sys.path.append("{YOU_PATH}\models-master\research\object_detection\utils")

PATH_TO_LABELS = 'data/mscoco_label_map.pbtxt'

Sakifneoworld avatar Nov 19 '19 05:11 Sakifneoworld