models icon indicating copy to clipboard operation
models copied to clipboard

No module named 'object_detection'

Open DanMossa opened this issue 9 years ago • 48 comments

System information

  • What is the top-level directory of the model you are using: Nothing yet
  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow): Nope
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows 10 64bit
  • TensorFlow installed from (source or binary): pip install tensorflow-gpu
  • TensorFlow version (use command below):

b'unknown' 1.2.0

  • Bazel version (if compiling from source):
  • CUDA/cuDNN version: 8.0 and 5
  • GPU model and memory: Geforce GTX 1050ti 4gb ddr5
  • Exact command to reproduce: python object_detection/builders/model_builder_test.py

Describe the problem

I followed the README.MD up until the point of having to execute the above command. And when I do I get an error saying that there is no module named object_detection I believe this has something to do with the

export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim

command. Because when I look at my system environment variables, I don't see anything titled PYTHONPATH.

I'm using Anaconda with a Virtual Environment

DanMossa avatar Jul 25 '17 01:07 DanMossa

@jch1 can you look at this, or should it be forwarded to someone who works on Windows support?

reedwm avatar Jul 25 '17 01:07 reedwm

Try running pwd on its own; pwd doesn't come with Windows by default, so you may not have it. If you don't have pwd, I recommend defining the environment variable manually. This is what I do; you'll have to adapt the paths to your computer:

set PYTHONPATH=<PATH_TO_MODELS>;<PATH_TO_MODELS>\slim

Also, this should be posted to Stack Overflow.

MaxBareiss avatar Jul 25 '17 16:07 MaxBareiss

Well @MaxBareiss I was able to setup pwd correctly using Git Bash on windows I originally typed source activate py35cv3

I don't have a PYTHONPATH but I do have a PYTHON_HOME So what I did is

echo $PYTHON_HOME
C:\Users\DanMo\Anaconda3
export PYTHON_HOME=$PYTHON_HOME:`pwd`:`pwd`/slim
echo $PYTHON_HOME
C:\Users\DanMo\Anaconda3:/c/Users/DanMo/Anaconda3/envs/py35cv3/lib/site-packages/tensorflow/models:/c/Users/DanMo/Anaconda3/envs/py35cv3/lib/site-packages/tensorflow/models/slim
DanMo@DESKTOP-V1R6HEC MINGW64 ~/Anaconda3/envs/py35cv3/lib/site-packages/tensorflow/models (master)
$ python object_detection/builders/model_builder_test.py
Traceback (most recent call last):
  File "object_detection/builders/model_builder_test.py", line 21, in <module>
    from object_detection.builders import model_builder
ImportError: No module named 'object_detection'

I still get that error

DanMossa avatar Jul 26 '17 09:07 DanMossa

So I didn't realize I also needed to also run

$ python setup.py build
$ python setup.py install

Is there a reason this isn't mentioned in the README?

But now I get the error

$ python object_detection/builders/model_builder_test.py
Traceback (most recent call last):
  File "object_detection/builders/model_builder_test.py", line 21, in <module>
    from object_detection.builders import model_builder
  File "C:\Users\DanMo\Anaconda3\envs\py35cv3\lib\site-packages\object_detection-0.1-py3.5.egg\object_detection\builders\model_builder.py", line 30, in <module>
    from object_detection.models import faster_rcnn_inception_resnet_v2_feature_extractor as frcnn_inc_res
  File "C:\Users\DanMo\Anaconda3\envs\py35cv3\lib\site-packages\object_detection-0.1-py3.5.egg\object_detection\models\faster_rcnn_inception_resnet_v2_feature_extractor.py", line 29, in <module>
ImportError: No module named 'nets'

DanMossa avatar Jul 26 '17 09:07 DanMossa

Could you print the output of echo $PYTHONPATH?

derekjchow avatar Jul 28 '17 22:07 derekjchow

(py35cv3) C:\Users\DanMo\Anaconda3\envs\py35cv3\Lib\site-packages\tensorflow\models>echo %PYTHONPATH% "C:\Users\DanMo\Anaconda3\envs\py35cv3\Lib\site-packages\tensorflow\models\slim";"C:\Users\DanMo\Anaconda3\envs\py35cv3\Lib\site-packages\tensorflow\models"

DanMossa avatar Jul 31 '17 14:07 DanMossa

Hi there, I am facing the same issue. I solved it by changing nets to slim.nets. This removed the errors for me. I am using Pycharm and didn't set any environment variables. I added the models and the slim directory as sources root in the project structure. Give it a try and see if it works!

bombrake avatar Aug 04 '17 02:08 bombrake

@hari0920 Where did you change nets to slim.nets?

DanMossa avatar Aug 05 '17 01:08 DanMossa

under the models folder in the faster_rcnn_inception_resnet_v2_feature_extractor.py and faster_rcnn_resnet_v1_feature_extractor.py

bombrake avatar Aug 06 '17 13:08 bombrake

Still get the same error

(py35cv3) C:\Users\DanMo\Anaconda3\envs\py35cv3\Lib\site-packages\tensorflow\models>python object_detection/builders/model_builder_test.py Traceback (most recent call last): File "object_detection/builders/model_builder_test.py", line 21, in from object_detection.builders import model_builder File "C:\Users\DanMo\Anaconda3\envs\py35cv3\Lib\site-packages\tensorflow\models\object_detection\builders\model_builder.py", line 30, in from object_detection.models import faster_rcnn_inception_resnet_v2_feature_extractor as frcnn_inc_res File "C:\Users\DanMo\Anaconda3\envs\py35cv3\Lib\site-packages\tensorflow\models\object_detection\models\faster_rcnn_inception_resnet_v2_feature_extractor.py", line 30, in slim = tf.contrib.slim.nets AttributeError: module 'tensorflow.contrib.slim' has no attribute 'nets'

DanMossa avatar Aug 07 '17 15:08 DanMossa

DanMossa, what did you find out?

roblee357 avatar Aug 09 '17 19:08 roblee357

@roblee357 I honestly have no idea. I didn't try it for a few days, and then I just randomly tried it and it all worked lol

DanMossa avatar Aug 12 '17 02:08 DanMossa

@DanMossa which solution did you use to fix that error message?

mschinzvende avatar Aug 28 '17 14:08 mschinzvende

Using windows the following worked for me: Set PYTHONPATH to both \models and \models\slim and then add PYTHONPATH to your Path variable

jmiloser avatar Sep 11 '17 13:09 jmiloser

@jamiii Your solution works for me in Windows 10. But I do not add PYTHONPATH to PATH, it still works.

ybsave avatar Oct 18 '17 20:10 ybsave

Nothing in this thread has worked for me. I still get the "ImportError: No module named 'nets'" error. I went inside "slim" and ran python setup.py install (because thats where he 'nets' folder is). Then ran "python object_detection/builders/model_builder_test.py" again. Now I get the error ImportError: No module named 'nets.nasnet'

py object_detection/builders/model_builder_test.py Traceback (most recent call last): File "object_detection/builders/model_builder_test.py", line 21, in from object_detection.builders import model_builder File "C:\Users\Nissan\AppData\Local\Programs\Python\Python35\lib\site-packages\object_detection-0.1-py3.5.egg\object_detection\builders\model_builder.py", line 32, in from object_detection.models import faster_rcnn_nas_feature_extractor as frcnn_nas File "C:\Users\Nissan\AppData\Local\Programs\Python\Python35\lib\site-packages\object_detection-0.1-py3.5.egg\object_detection\models\faster_rcnn_nas_feature_extractor.py", line 26, in ImportError: No module named 'nets.nasnet'

karkinissan avatar Nov 03 '17 09:11 karkinissan

Hi @karkinissan. I changed nets to research.slim.nets and it works for me now.

KimmoOjala avatar Nov 10 '17 06:11 KimmoOjala

For mac os sierra steps to install. Run from models/research:

sudo chown -R $USER /Library/Frameworks/Python.framework/Versions/3.6/
python setup.py build
python setup.py install

If you use jupyter notebook you need to restart it.

iamtodor avatar Nov 12 '17 18:11 iamtodor

I fixed it Go to slim and run this

sudo pip install -e .

this will install slim which allows you to use import nets

crizzy9 avatar Nov 13 '17 00:11 crizzy9

@crizzy9 Can you please tell which slim? I found 2 in models

cyberphantom avatar Nov 30 '17 19:11 cyberphantom