tensorflow / models

Models and examples built with TensorFlow
Other
77.02k stars 45.78k forks source link

No module named 'object_detection' #2031

Closed DanMossa closed 7 years ago

DanMossa commented 7 years ago

System information

b'unknown' 1.2.0

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

reedwm commented 7 years ago

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

MaxBareiss commented 7 years ago

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.

DanMossa commented 7 years ago

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 commented 7 years ago

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'
derekjchow commented 7 years ago

Could you print the output of echo $PYTHONPATH?

DanMossa commented 7 years ago

(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"

bombrake commented 7 years ago

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!

DanMossa commented 7 years ago

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

bombrake commented 7 years ago

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

DanMossa commented 7 years ago

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'

roblee357 commented 7 years ago

DanMossa, what did you find out?

DanMossa commented 7 years ago

@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

mschinzvende commented 7 years ago

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

jmiloser commented 7 years ago

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

ybsave commented 7 years ago

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

karkinissan commented 6 years ago

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'

KimmoOjala commented 6 years ago

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

iamtodor commented 6 years ago

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.

crizzy9 commented 6 years ago

I fixed it Go to slim and run this

sudo pip install -e .

this will install slim which allows you to use import nets

cyberphantom commented 6 years ago

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

isaacdchan commented 6 years ago

@cyberphantom there's one in site packages and the other is in models/research. Choose the second one.

deaspo commented 6 years ago

I also had to go through all this using win10 x64 and summary for the steps that worked from this thread:

  1. in models\research directory run the following:
    python setup.py build
    python setup.py install
  2. go to model/research/slim and run the following: pip install -e .

Am using Anaconda virtual environment (Tensorflow-GPU)

SophieApple commented 6 years ago

I am so happy to modified the problem as the method of @hari0920 and @deaspo . I solved the problem through the steps: 1 add the path of slim and the path of research into the environment variable list 2 in models\research directory run the following: python setup.py build python setup.py install 3 change nets to slim.nets in the models folder in the faster_rcnn_inception_resnet_v2_feature_extractor.py and faster_rcnn_resnet_v1_feature_extractor.py 4 restart Anaconda and test “model_builder_test.py”

EricTheAI commented 6 years ago

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')

ghost commented 6 years ago

@deaspo 's answer perfectly clear and worked, it should be published. If you use python 3 just use pip3 instead pip

mmmotta commented 6 years ago

This is what worked for me in windows 10. All the issue is the pythonpath, so besides pointing it to you pythonxx folder also add from the command prompt the following:

set PythonPath=%pythonpath%;c:\ml\models;c:\ml\models\research;c:\ml\models\research\slim

LightSun commented 6 years ago

@jamiii works for me .thanks

anzy0621 commented 6 years ago

works for me!!! Thanks!

akkalbist55 commented 6 years ago

import os import cv2 import time import argparse import multiprocessing import numpy as np import tensorflow as tf from matplotlib import pyplot as plt %matplotlib inline from object_detection.utils import label_map_util from object_detection.utils import visualization_utils as vis_util

I am using anaconda jupyter on ubuntu 16.04lts

This is my error


ModuleNotFoundError Traceback (most recent call last)

in () ----> 1 from object_detection.utils import label_map_util 2 from object_detection.utils import visualization_utils as vis_util

ModuleNotFoundError: No module named 'object_detection'

sanket19189 commented 6 years ago

I am getting the same error . When running from python shell

akkalbist55 commented 6 years ago

yes i also get this error

On Mon, Jul 30, 2018 at 3:59 PM sanket19189 notifications@github.com wrote:

I am getting the same error . When running from python shell

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/tensorflow/models/issues/2031#issuecomment-408815462, or mute the thread https://github.com/notifications/unsubscribe-auth/AMyCUtIpEc_SKpQEEUkUWiV57yCVOJhQks5uLtyjgaJpZM4Oh9HQ .

andremendessousa commented 6 years ago

Hi, I did the following:

After instructions from deaspo and @SophieApple I moved the complete Archive "nets" and "slim" my home directory in virtualenv.

image

I´m using Anaconda, with Tensorflow 1.10 and windows10. It seems that in TF10 they changed the directores completaly..

raj-sivakumar-zz commented 5 years ago

faster_rcnn_inception_resnet_v2_feature_extractor.py and faster_rcnn_resnet_v1_feature_extractor.py

4 restart Anaconda and test “model_builder_test.py”

can you clarify what you mean by restarting Anaconda? Do you mean the Anaconda application that is downloaded with the install?

ashkan-abbasi66 commented 5 years ago

If you are using Anaconda, here is my updated answer. It works for both Linux and Windows.

AISangam commented 5 years ago

Hello @DanMossa , I was able to figure out the problem as object_detection library is not installed so please run below command inside the directory models/research

sudo python setup.py install

I hope, this will solve the problem. If such solution does not work, then please execute the below command one by one inside the directory models/research

export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim
sudo python setup.py install

I still get that error This will resolve the error. I too faced such error while creating model from export_inference_graph.py. I followed the above procedure, error was gone. I hope this solution may be a help to you.

With Regards AI Sangam

shivamzxzx commented 5 years ago

For Linux: --> cd inside models/research Run following commands --> export PYTHONPATH=$PYTHONPATH:pwd:pwd/slim -->protoc object_detection/protos/*.proto --python_out=.
-->python setup.py build -->python setup.py install

freddy24 commented 5 years ago

I just did as you guys say:

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

then I run python object_detection/builders/model_builder_test.py I got this error:

Traceback (most recent call last):
  File "object_detection/builders/model_builder_test.py", line 23, in <module>
    from object_detection.builders import model_builder
  File "C:\Users\wujinpeng\venv\lib\site-packages\object_detection-0.1-py3.6.egg\object_detection\builders\model_builder.py", line 28, in <module>
    from object_detection.builders import region_similarity_calculator_builder as sim_calc
  File "C:\Users\wujinpeng\venv\lib\site-packages\object_detection-0.1-py3.6.egg\object_detection\builders\region_similarity_calculator_builder.py", line 19, in <module>
    from object_detection.protos import region_similarity_calculator_pb2
ImportError: cannot import name 'region_similarity_calculator_pb2'
hussamsayeed commented 5 years ago

$ python setup.py build running build running build_py creating build/lib error: could not create 'build/lib': Permission denied

getting this error while executing the setup.py build

hussamsayeed commented 5 years ago

$ python setup.py install running install running bdist_egg running egg_info error: [Errno 13] Permission denied

getting this error while executing the setup.py install

AISangam commented 5 years ago

$ python setup.py build running build running build_py creating build/lib error: could not create 'build/lib': Permission denied

getting this error while executing the setup.py build

Please run the file with sudo permission

dexception commented 5 years ago

This is ridiculous and confusing.

The wiki section is completely empty. There is zero documentation.

rajkundu commented 5 years ago

I also had to go through all this using win10 x64 and summary for the steps that worked from this thread:

  1. in models\research directory run the following: python setup.py build python setup.py install

  2. go to model/research/slim and run the following: pip install -e .

Am using Anaconda virtual environment (Tensorflow-GPU)

Just in case this helps anyone, I wanted to confirm that these exact steps worked for me. I'm on macOS 10.15 Beta (Build 19A471t) using Tensorflow CPU.

shivampip commented 5 years ago
systems-apatrick commented 4 years ago

### pip install tensorflow-object-detection-api

nadeemsk4347 commented 4 years ago

### pip install tensorflow-object-detection-api

This one worked for me.

SundarML commented 4 years ago

python setup.py build python setup.py install

it worked for me, thanks.

mattiazingaretti commented 4 years ago

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.

Also for macos Catalina fixed the problem. Thanks a lot

Jayanth1812 commented 3 years ago

Hi, I am getting the following errors.. when I run the main training program.. (tensorflow) C:\tensorflow\models\research\object_detection>python train.py --logtostderr --train_dir=training/ --pipeline_config_path=training/faster_rcnn_inception_v2_pets.config Traceback (most recent call last): File "train.py", line 54, in from object_detection.builders import model_builder File "C:\tensorflow\models\research\object_detection\builders\model_builder.py", line 20, in from object_detection.builders import anchor_generator_builder File "C:\tensorflow\models\research\object_detection\builders\anchor_generator_builder.py", line 23, in from object_detection.anchor_generators import flexible_grid_anchor_generator ModuleNotFoundError: No module named 'object_detection.anchor_generators'