models icon indicating copy to clipboard operation
models copied to clipboard

ImportError: No module named nets

Open 10183308 opened this issue 9 years ago • 52 comments

when I enter : python object_detection/builders/model_builder_test.py

it shows the wrong : ImportError: No module named nets

could you help me?

thank you very much

10183308 avatar Jul 03 '17 07:07 10183308

Look at Installation!!! When running locally, the tensorflow/models/ and slim directories should be appended to PYTHONPATH. This can be done by running the following from tensorflow/models/:

From tensorflow/models/

export PYTHONPATH=$PYTHONPATH:pwd:pwd/slim nets and deployment modules belong to slim

heroinlin avatar Jul 04 '17 01:07 heroinlin

'pwd' is the path of models folder. Try to set "pwd:pwd/slim" with "/media/media_share/linkfile/models: /media/media_share/linkfile/models/slim".

2017-07-04 9:32 GMT+08:00 10183308 [email protected]:

thank you .

I have added the PYTHONPATH ,

but it does not work.

hc@hc-PC:/media/media_share/linkfile/models$ echo $PYTHONPATH /usr/local/lib/python2.7/dist-packages:/usr/lib/python2.7/ dist-packages:/home/hc/project/caffe2/caffe2/build/ caffe2:/home/hc/project/caffe2/caffe2/build/caffe2/ python:/home/hc/project/caffe_sorce/caffe/python:/usr/local: /home/hc/project/caffe_sorce/caffe/python:/usr/local:/home/ hc/project/caffe2/caffe2/build::/home/hc:/home/hc/slim: /home/hc:/home/hc/slim:pwd:pwd/slim

hc@hc-PC:/media/media_share/linkfile/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 "/media/media_share/linkfile/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 "/media/media_share/linkfile/models/object_detection/ models/faster_rcnn_inception_resnet_v2_feature_extractor.py", line 29, in from nets import inception_resnet_v2 ImportError: No module named nets

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

heroinlin avatar Jul 04 '17 02:07 heroinlin

Ah, it is the problem of "path"! I have trying for several days. When I added in the program code: "import sys print(sys.path) sys.path.append("/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/slim") print(sys.path)" It works! For the nets.py in directory"/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/slim"

aweichina avatar Jul 31 '17 13:07 aweichina

Congratulate to work it well.You can find the slim folder in models folder, and nets folder in the slim folder.I work it on windows, like this: image . so I just add this slim to the path.on the linux, you can try it similarly.

heroinlin avatar Aug 02 '17 02:08 heroinlin

I think it's a trick.... in the document, it said

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

pwd is your local path, however, you should keep mark like this : 'local path':'localpath'/slim it works on my computer. 哇,喷火龙唉!

FlashSnail avatar Aug 21 '17 09:08 FlashSnail

Thanks a lot!

aweichina avatar Oct 17 '17 00:10 aweichina

Thanks a lot. It worked for me

wationgo avatar Nov 20 '17 22:11 wationgo

Thank you for all! I have solved this problem by run setup.py. Thank you!

aweichina avatar Nov 29 '17 14:11 aweichina

Thanks!!! running setup.py build and setup.py install worked

arpitsharmagit avatar Jan 27 '18 15:01 arpitsharmagit

sudo gedit ~/.bashrc #open bashrc file #then add this new line to the end of your bashrc file export PYTHONPATH=$PYTHONPATH=/home/hri/tensorflow/models/research:/home/hri/tensorflow/models/research/slim #then restart then bashrc to make it work source ~/.bashrc #you can change the path to your own!

qiaoguan avatar Mar 23 '18 06:03 qiaoguan

I encountered the same problem on windows. What I did was, I just copied the entire nets folder from slim directory to C:\Python\Python35\Lib\site-packages\object_detection-0.1-py3.5.egg (where I installed object_detection API). Then the error is completely gone.

kil0watt avatar Apr 02 '18 13:04 kil0watt

I have the same problem and I go to the tensorflow's github for information You can never figure it out that I solve this by simply copy the code below from the net page export PYTHONPATH=$PYTHONPATH:pwd:pwd/slim

Note that it's ` instead of ' around the key pwd That's my problem, hope it's helpful to you

JustinAsdz avatar Aug 14 '18 05:08 JustinAsdz

I add export PYTHONPATH="$PYTHONPATH:tensorflow/models/research:/tensorflow/models/research/slim" in my .bashrc file, then source ~/.bashrc file, but I still has this problem. someone can tell me whiy

kochsnow avatar Aug 30 '18 12:08 kochsnow

It looks like your paths are wrong (unless you have a directory called "tensorflow" at the root of your filesystem, in which case you are missing a '/' at the beginning of your first path)

try to include the absolute path. e.g.: export PYTHONPATH="$PYTHONPATH:/home/kochsnow/tensorflow/models/research:/home/kochsnow/tensorflow/models/research/slim"

jeremiahharbach avatar Aug 30 '18 18:08 jeremiahharbach

Thank you! It works!


发件人:Jeremiah Harbach [email protected] 发送时间:2018年8月31日(星期五) 02:15 收件人:tensorflow/models [email protected] 抄 送:aweichina [email protected]; Comment [email protected] 主 题:Re: [tensorflow/models] ImportError: No module named nets (#1842)

It looks like your paths are wrong (unless you have a directory called "tensorflow" at the root of your filesystem, in which case you are missing a '/' at the beginning of your first path) try to include the absolute path. e.g.: export PYTHONPATH="$PYTHONPATH:/home/kochsnow/tensorflow/models/research:/home/kochsnow/tensorflow/models/research/slim" — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

aweichina avatar Sep 06 '18 08:09 aweichina

I encountered the same problem on windows. What I did was, I just copied the entire nets folder from slim directory to C:\Python\Python35\Lib\site-packages\object_detection-0.1-py3.5.egg (where I installed object_detection API). Then the error is completely gone.

No working for me :/

LyonOconner avatar Oct 26 '18 20:10 LyonOconner

I am able to run on a local machine by adding the right slim path to PYTHONPATH. But when I am trying to run on google colab I am getting error even though I added the slim path with:

# From tensorflow/models/research/
export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim

Here is my error messages:

Traceback (most recent call last):
  File "legacy/train.py", line 51, in <module>
    from object_detection.builders import model_builder
  File "/usr/local/lib/python3.6/dist-packages/object_detection-0.1-py3.6.egg/object_detection/builders/model_builder.py", line 35, in <module>
    from object_detection.models import faster_rcnn_inception_resnet_v2_feature_extractor as frcnn_inc_res
  File "/usr/local/lib/python3.6/dist-packages/object_detection-0.1-py3.6.egg/object_detection/models/faster_rcnn_inception_resnet_v2_feature_extractor.py", line 28, in <module>
    from nets import inception_resnet_v2
ModuleNotFoundError: No module named 'nets'

mymultiverse avatar Nov 06 '18 09:11 mymultiverse

I am able to run on a local machine by adding the right slim path to PYTHONPATH. But when I am trying to run on google colab I am getting error even though I added the slim path with:

# From tensorflow/models/research/
export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim

Here is my error messages:

Traceback (most recent call last):
  File "legacy/train.py", line 51, in <module>
    from object_detection.builders import model_builder
  File "/usr/local/lib/python3.6/dist-packages/object_detection-0.1-py3.6.egg/object_detection/builders/model_builder.py", line 35, in <module>
    from object_detection.models import faster_rcnn_inception_resnet_v2_feature_extractor as frcnn_inc_res
  File "/usr/local/lib/python3.6/dist-packages/object_detection-0.1-py3.6.egg/object_detection/models/faster_rcnn_inception_resnet_v2_feature_extractor.py", line 28, in <module>
    from nets import inception_resnet_v2
ModuleNotFoundError: No module named 'nets'

set PYTHONPATH=C:\Tensorflow\models;C:\Tensorflow\models\research;C:\Tensorflow\models\research\slim set PATH=%PATH%;%PYTHONPATH% Set environment EVERYTIME when activate tensorflow gpu

LyonOconner avatar Nov 06 '18 13:11 LyonOconner

or copy & paste Slim folder content in C:\ProgramData\Anaconda3\envs\tensorflow_cpu\Lib\site-packages\object_detection-0.1-py3.5.egg\ {here}

LyonOconner avatar Nov 06 '18 13:11 LyonOconner

set PYTHONPATH=C:\Tensorflow\models;C:\Tensorflow\models\research;C:\Tensorflow\models\research\slim set PATH=%PATH%;%PYTHONPATH%

I think there no C in google colab. Results from above command

/bin/bash: C:Tensorflowmodelsresearch: command not found
/bin/bash: C:Tensorflowmodelsresearchslim: command not found
/bin/bash: line 0: fg: no job control

mymultiverse avatar Nov 11 '18 07:11 mymultiverse