Models: ImportError: No module named 'nets'

Created on 4 Sep 2017  路  12Comments  路  Source: tensorflow/models

I am trying to convert trained_checkpoint to final frozen model from the export_inference_graph.py script provided in tensorflow/models,but the following error results.
And yes,I have already setup $PYTHONPATH to "models/slim" but still I get this error,can someone help me out?

$ echo $PYTHONPATH
:/home/ishara/tensorflow_models/models:/home/ishara/tensorflow_models/models/slim

$sudo python3 object_detection/export_inference_graph.py  --input_type image_tensor  --pipeline_config_path = "ssd_inception_v2_pets.config"  --trained_checkpoint_prefix="output/model.ckpt-78543"  --output_directory="birds_inference_graph.pb"

Traceback (most recent call last):
  File "object_detection/export_inference_graph.py", line 74, in <module>
    from object_detection import exporter
  File "/usr/local/lib/python3.5/dist-packages/object_detection-0.1-py3.5.egg/object_detection/exporter.py", line 28, in <module>

  File "/usr/local/lib/python3.5/dist-packages/object_detection-0.1-py3.5.egg/object_detection/builders/model_builder.py", line 30, in <module>
  File "/usr/local/lib/python3.5/dist-packages/object_detection-0.1-py3.5.egg/object_detection/models/faster_rcnn_inception_resnet_v2_feature_extractor.py", line 28, in <module>
ImportError: No module named 'nets'

I have been struggling with this for days now,tried many solutions nothing work
I am using Ubuntu 16.04 with tensorflow gpu version.

awaiting model gardener bug

Most helpful comment

slim has moved into the research directory in the repo. To get it to work I had to do:

export PYTHONPATH=/home/username/models/research/slim:$PYTHONPATH

All 12 comments

@jch1 Check out faster_rcnn_inception_resnet_v2_feature_extractor.py which says from rofl3.third_party.tensorflow_models.slim.nets import inception_resnet_v2 internally but from nets import inception_resnet_v2 on GitHub. Odd.

@amith01994 Add the slim path to your bashrc.
ex: add export PYTHONPATH=/home/username/models/slim:$PYTHONPATH line.

Please refer to #729 for further detail and the solution.

Its already there.

$ echo $PYTHONPATH
:/home/ishara/tensorflow_models/models:/home/ishara/tensorflow_models/models/slim

@amith01994 Make sure the following format is correct in the bashrc:
export PYTHONPATH=/home/username/models/slim:$PYTHONPATH

add following codes to the top of `` will be help.

import os, sys
sys.path.append(os.path.join(os.path.dirname(__file__), "../../"))
sys.path.append(os.path.join(os.path.dirname(__file__), "../../slim"))

slim has moved into the research directory in the repo. To get it to work I had to do:

export PYTHONPATH=/home/username/models/research/slim:$PYTHONPATH

@icoxfog417 this is working. many thanks.

doesnt worked for me

i m trying to run train.py but getting same error no module name nets
so i changed the' from nets ' to 'research.slim.nets' in individual fiels where nets is imported and run each file and didnt get error
but when i try to run train.py its showing same error and when i locate to that file it the file remains the same as befre changing from nets to from research.slim.nets'
does anyone how to solve it
i tried to set the PYTHONPATH but the error occurs

I have the same issue and I have tried many solution it does not work.

Please any help in this issue will be appreciated.

One thing to notice (if you haven't noticed before) is that slim is in the larger package in the repo: https://github.com/tensorflow/models/tree/master/research. You need to copy this to the directory you are working on. I copied the slim folder to the same level as object_detection and it worked (I didn't notice this before).

It still is not closed..

1.open bashrc
nano ~/.bashrc
2.add this line to bashrc
export PYTHONPATH=/home/username/models/research/slim:$PYTHONPATH
3.refresh ( I guess you got error, cuz you didn't make it apply right away. )
source ~/.bashrc

Yes, since the "slim" was moved to the research folder, the README.md seems updated. gosick237's response works!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Mostafaghelich picture Mostafaghelich  路  3Comments

kamal4493 picture kamal4493  路  3Comments

mbenami picture mbenami  路  3Comments

trungdn picture trungdn  路  3Comments

rakashi picture rakashi  路  3Comments