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
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/:
export PYTHONPATH=$PYTHONPATH:pwd
:pwd
/slim
nets and deployment modules belong to slim
'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 notifications@github.com:
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/slimhc@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
.
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"
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:
.
so I just add this slim to the path.on the linux, you can try it similarly.
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. 哇,喷火龙唉!
Thanks a lot!
Thanks a lot. It worked for me
Thank you for all! I have solved this problem by run setup.py. Thank you!
Thanks!!! running setup.py build
and setup.py install
worked
sudo gedit ~/.bashrc #open bashrc file
export
PYTHONPATH=$PYTHONPATH=/home/hri/tensorflow/models/research:/home/hri/tensorflow/models/research/slim
source ~/.bashrc
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.
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
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
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"
Thank you! It works!
发件人:Jeremiah Harbach notifications@github.com
发送时间:2018年8月31日(星期五) 02:15
收件人:tensorflow/models models@noreply.github.com
抄 送:aweichina aweichina@aliyun.com; Comment comment@noreply.github.com
主 题: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.
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 :/
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'
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
or copy & paste Slim folder content in
C:\ProgramData\Anaconda3\envstensorflow_cpu\Lib\site-packages\object_detection-0.1-py3.5.egg\ {here}
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
or copy & paste Slim folder content in
C:\ProgramData\Anaconda3\envstensorflow_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.
For google colab. Inside research folder.
import os
os.environ['PYTHONPATH'] += ':/content/models/research/:/content/models/research/slim/'
To overcome this error:
ImportError: No module named 'tensorflow.contrib.slim'
All I did was:
pip install tensorflow-gpu==1.8.0
cd "path to the models folder"
$ protoc object_detection/protos/*.proto --python_out=.
$ export PYTHONPATH=$PYTHONPATH:pwd
:pwd
/slim
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"
The path you add yourself after exiting the Python environment will automatically disappear
@aweichina solution worked for me. :)
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 !!!
under slim folder use command 'python setup.py install' research/slim/setup.py
under slim folder use command 'python setup.py install' research/slim/setup.py
This did it for me after nothing else worked, thanks!
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
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
@hoangnt2601 where exactly did you add the code ?
For windows, create a text file in _your\Anaconda\environmentpath_\Lib\site-packages, rename it to tensorflow_model.pth, add the following two lines:
_your\Anaconda\environmentpath_\Lib\site-packagestensorflow\models\research
_your\Anaconda\environmentpath_\Lib\site-packagestensorflow\models\research\slim
Then save and close.
Do the test again. It works for me.
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.
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......
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!
copy the absolute path of your slim folder (we'll call it XYZ), which is inside models/research.
then type export PYTHONPATH=$PYTHONPATH:XYZ
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\u3002delete BUILD file under the folder will solve it.
It really work for me. Thank you!
do i need to run this everytime ? because when i run train.py the error pops up again
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
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
I slove this problem !!!!!!!!
open slim folder copy net folder and past in object _detection folder
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.
Go to research/slim/ and fire this command
python setup.py build
sudo python setup.py install
cd tensorflow/models/research
.
Check slim exists by ls | grep 'slim'
Then run - export PYTHONPATH=$PYTHONPATH:$(pwd):$(pwd)/slim
Go to research/slim/ and fire this command
python setup.py build
sudo python setup.py install
It worked for me on Google Colab!
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
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 https://github.com/google-research/tf-slim/issues/6
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\envstensorflow1\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\envstensorflow1\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\envstensorflow1\lib\site-packages\object_detection-0.1-py3.8.egg\object_detection\protos__init__.py)
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
Most helpful comment
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.