No module named 'object_detection'
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
@jch1 can you look at this, or should it be forwarded to someone who works on Windows support?
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.
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
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'
Could you print the output of echo $PYTHONPATH?
(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"
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!
@hari0920 Where did you change nets to slim.nets?
under the models folder in the faster_rcnn_inception_resnet_v2_feature_extractor.py and faster_rcnn_resnet_v1_feature_extractor.py
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, what did you find out?
@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 which solution did you use to fix that error message?
Using windows the following worked for me: Set PYTHONPATH to both \models and \models\slim and then add PYTHONPATH to your Path variable
@jamiii Your solution works for me in Windows 10. But I do not add PYTHONPATH to PATH, it still works.
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'
Hi @karkinissan. I changed nets to research.slim.nets and it works for me now.
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.
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 Can you please tell which slim? I found 2 in models