Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: No module named nets #1842

Closed
10183308 opened this issue Jul 3, 2017 · 52 comments
Closed

ImportError: No module named nets #1842

10183308 opened this issue Jul 3, 2017 · 52 comments

Comments

@10183308
Copy link

10183308 commented Jul 3, 2017

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

@heroinlin
Copy link

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
Copy link

heroinlin commented Jul 4, 2017 via email

@aweichina
Copy link

aweichina commented Jul 31, 2017

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"

@heroinlin
Copy link

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.

@FlashSnail
Copy link

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. 哇,喷火龙唉!

@aweichina
Copy link

Thanks a lot!

@wationgo
Copy link

Thanks a lot. It worked for me

@aweichina
Copy link

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

@arpitsharmagit
Copy link

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

@qiaoguan
Copy link

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!

@kil0watt
Copy link

kil0watt commented Apr 2, 2018

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.

@JustinAsdz
Copy link

JustinAsdz commented Aug 14, 2018

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

@kochsnow
Copy link

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

@jeremiahharbach
Copy link

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"

@aweichina
Copy link

aweichina commented Sep 6, 2018 via email

@LyonOconner
Copy link

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 :/

@mymultiverse
Copy link

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'

@LyonOconner
Copy link

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
Copy link

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

@mymultiverse
Copy link

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
Copy link

mymultiverse commented Nov 11, 2018

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

I did that but still same import error. In case of google colab I did with following command, let me know if path is not correct.
cp -R slim/ /usr/local/lib/python3.6/dist-packages/object_detection-0.1-py3.6.egg/

Problem solved when I copy nets and deployment.

@MohammadDabbas
Copy link

Hi guys I'm having an error when I'm trying to run the training using this command:

python train.py --logtostderr --train_dir=training/ --pipeline_config_path=training/ssd_mobilenet_v1_coco.config

Traceback (most recent call last): File "train.py", line 51, in <module> from object_detection.builders import model_builder File "C:\tensorflow1\models\research\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 "C:\tensorflow1\models\research\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

note:
the slim folder is already added to PYTHONPATH !!!

@arascan35
Copy link

arascan35 commented Apr 16, 2019

under slim folder use command 'python setup.py install' research/slim/setup.py

@cj-clifton
Copy link

cj-clifton commented Apr 19, 2019

under slim folder use command 'python setup.py install' research/slim/setup.py

This did it for me after nothing else worked, thanks!

@Tourenathan-G5organisation

For google colab. Inside research folder.

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

thanks you very much. This solution just came al the right time. you save my day

@hoangnt2601
Copy link

hoangnt2601 commented May 13, 2019

I add this code sys.path.append("../../models/research/slim/") into /models/research/object_detection/models/faster_rcnn_inception_resnet_v2_feature_extrac
tor.py
It's worked for me

@devimonica
Copy link

@hoangnt2601 where exactly did you add the code ?

@wander1985
Copy link

For windows, create a text file in your\Anaconda\environment\path\Lib\site-packages, rename it to tensorflow_model.pth, add the following two lines:
your\Anaconda\environment\path\Lib\site-packages\tensorflow\models\research
your\Anaconda\environment\path\Lib\site-packages\tensorflow\models\research\slim
Then save and close.
Do the test again. It works for me.

@libichong
Copy link

under slim folder use command 'python setup.py install' research/slim/setup.py
https://github.com/tensorflow/models/issues/5795#issuecomment-440562409

(python35) D:\Code\GitHub\models\research\slim>python setup.py build
running build
running build_py
creating build
error: could not create 'build': \u5f53\u6587\u4ef6\u5df2\u5b58\u5728\u65f6\uff0c\u65e0\u6cd5\u521b\u5efa\u8be5\u6587\u4ef6\u3002

delete BUILD file under the folder will solve it.

@anmol4210
Copy link

Hi,
I tried all the solutions but the one that worked for me was

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

I ran the above command in the models folder...

Hope that helps someone......

@rikenshah2002
Copy link

rikenshah2002 commented Sep 10, 2019

For google colab. Inside research folder.

import os
os.environ['PYTHONPATH'] += ':/content/models/research/:/content/models/research/slim/'
It worked by a small tweak:
os.environ['PYTHONPATH'] += ':/:slim/'

Thanks a Lot!
It finally worked!

@luiscorujo
Copy link

luiscorujo commented Oct 4, 2019

copy the absolute path of your slim folder (we'll call it XYZ), which is inside models/research.
then type export PYTHONPATH=$PYTHONPATH:XYZ

@Conghung43
Copy link

under slim folder use command 'python setup.py install' research/slim/setup.py
https://github.com/tensorflow/models/issues/5795#issuecomment-440562409

(python35) D:\Code\GitHub\models\research\slim>python setup.py build
running build
running build_py
creating build
error: could not create 'build': \u5f53\u6587\u4ef6\u5df2\u5b58\u5728\u65f6\uff0c\u65e0\u6cd5\u521b\u5efa\u8be5\u6587\u4ef6\u3002

delete BUILD file under the folder will solve it.

It really work for me. Thank you!

@jsn-bln
Copy link

jsn-bln commented Nov 7, 2019

do i need to run this everytime ? because when i run train.py the error pops up again

@luiscorujo
Copy link

luiscorujo commented Nov 7, 2019

You can run from the models/research directory exactly this:
export PYTHONPATH=$PYTHONPATH:pwd:pwd/slim
Just copy that line, just once, and it should work

@Danielson23
Copy link

Danielson23 commented Nov 8, 2019

The correct way, if you need only object detection module:

  • copy object_detection and slim folder in a same location

  • export the working path to pythonpath using this commande (this will be done in the folder where object_detection and slim folder ar located):

export PYTHONPATH=$PYTHONPATH:pwd:pwd/slim in this folder

@vatsal1301
Copy link

I slove this problem !!!!!!!!

open slim folder copy net folder and past in object _detection folder

@CHAMOD
Copy link

CHAMOD commented May 9, 2020

fo Windows users, you could solve this by setting PYTHONPATH as follows.
set PYTHONPATH=C:\Users...\models\research;C:\Users...\models\research\slim
then after run train.py inside object_detection dir.

@dhanpalrajpurohit
Copy link

Go to research/slim/ and fire this command
python setup.py build
sudo python setup.py install

@i-amgeek
Copy link

cd tensorflow/models/research

Check slim exists by ls | grep 'slim' 

Then run - export PYTHONPATH=$PYTHONPATH:$(pwd):$(pwd)/slim

@rsrrohit
Copy link

rsrrohit commented Jun 7, 2020

Go to research/slim/ and fire this command
python setup.py build
sudo python setup.py install

It worked for me on Google Colab!

@artongdou
Copy link

Go to research/slim/, delete BUILD, and run the following commands fix the 'nets' issue in windows 10 under anaconda virutal env.
python setup.py install

@yegortokmakov
Copy link

yegortokmakov commented Jul 8, 2020

Changing PYTHONPATH manually doesn't seem like the right solution. Is there a reason why this repo is not using tf-slim package as a dependency and instead has a copy of the source code? Just trying to understand.

Update: There is a PR #8626 somehow related to this

Update2: Found the answer here google-research/tf-slim#6

@rethamasae
Copy link

I can't run the Training, maybe someone can help me
(tensorflow1) C:\tensorflow1\models\research\object_detection>python train.py --logtostderr --train_dir=training/ --pipeline_config_path=training/faster_rcnn_inception_v2_pets.config
2020-08-10 22:08:00.754622: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cudart64_101.dll
Traceback (most recent call last):
File "train.py", line 53, in
from object_detection.builders import model_builder
File "C:\Users\ASUS\anaconda3\envs\tensorflow1\lib\site-packages\object_detection-0.1-py3.8.egg\object_detection\builders\model_builder.py", line 39, in
from object_detection.protos import model_pb2
File "C:\Users\ASUS\anaconda3\envs\tensorflow1\lib\site-packages\object_detection-0.1-py3.8.egg\object_detection\protos\model_pb2.py", line 14, in
from object_detection.protos import center_net_pb2 as object__detection_dot_protos_dot_center__net__pb2
ImportError: cannot import name 'center_net_pb2' from 'object_detection.protos' (C:\Users\ASUS\anaconda3\envs\tensorflow1\lib\site-packages\object_detection-0.1-py3.8.egg\object_detection\protos_init_.py)

@khalidw
Copy link

khalidw commented Oct 5, 2020

On Windows 10 with Anaconda I used the following hack

import sys
import os
pwd = %pwd
sys.path.append(os.path.join(pwd,'models', 'research')) # point to your research dir
sys.path.append(os.path.join(pwd,'models', 'research', 'object_detection')) # point to your object_detection dir
sys.path.append(os.path.join(pwd,'models', 'research', 'slim')) # point ot your slim dir

@codeperfectplus
Copy link

In Windows, I just copied the nets folder from research/slim directory to lib/site-package in my python environment.

@Petros626
Copy link

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

hey from which directory i must run this command

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests