ImportError: No module named 'nets'

Question:

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

*****************************problem****************************************************************************

$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.

Asked By: Ishara Abeykoon

||

Answers:

I did get the same error, because I had missed out to actually put the slim package into the tensorflow/models folder. The slim package is on
https://github.com/tensorflow/models

Answered By: andreas

Take a look at Protobuf Compilation at
https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/installation.md
and set PYTHONPATH correctly, this is how I solved this for Windows

For Windows:

From tensorflow/models/research/

Step1: protoc object_detection/protos/*.proto --python_out=.

Step2:

set PYTHONPATH= <Path to 'research' Directory> ; <Path to 'slim' Directory>

For Eg:

set PYTHONPATH=C:UsersGuyDesktopmodelsresearch;C:UsersGuyDesktopmodelsresearchslim
Answered By: Pawan Mishra

This is fixed on newer versions of tensorflow, if you get it just update your tensorflow version.

Answered By: Ishara Abeykoon

For MacOS:

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

Solves the problem.

Answered By: ceekay

This is a PYTHONPATH issue.

I would like to add to the existing answers, that if it’s still not working for you and you use an Anaconda environment, use the Anaconda Prompt (in Admin mode) that comes with the distribution and not the system prompt of your OS. Set the PYTHONPATH within the Anaconda Prompt and run your commands from there.

Also the PYTHONPATH is reseted at each deactivation of the anaconda environment, including here a machine restart. So remember to set it again.

Answered By: Gabriel P.

TF-Slim is available as tf.contrib.slim via TensorFlow 1.0, so you don’t need to install it additionally if you used pip install tensorflow. You still need to do these 3 things:

  1. Install the models library

    $ cd
    $ git clone https://github.com/tensorflow/models/
    
  2. Add the PYTHONPATH to .bashrc

    $ cd
    $ vi .bashrc
    
    export PYTHONPATH="$PYTHONPATH:/home/${YOUR_USERNAME}/models/research/slim"
    
  3. Add the models path to your script

    $ vi ${YOUR_SCRIPT}.py
    
    import sys
    sys.path.append('/home/${YOUR_USERNAME}/models/research/slim/')
    

After these 3 steps you’re all set. Now you can import the TF nets like this:

import tensorflow as tf
from tensorflow.contrib import slim
from nets import inception_resnet_v2
Answered By: tsveti_iko

encountered the slim error on windows and this solved my problem

. What I did was, I just copied the entire nets folder from slim directory to C:PythonPythonLibsite-packagesobject_detection-0.1-py3.5.egg (where I installed object_detection API). Then the error is completely gone.

Answered By: Draxy07

Ubuntu 18 physical GPU (device: 0, name: Tesla K80, pci bus id: 0000:00:1e.0, compute capability: 3.7)strong text

cd models/research/slim/;
python setup.py build
python setup.py install

That’s in case you’ve got downloaded or cloned your models directory.

Answered By: Vadim

IF you are using Jupyter Notebook and using Linux sys

download tensorflow-models

and then write this in your Notebook

sys.path.append("/home/Roy/Downloads/models-master/research/slim/")

I solved my problem with this

hope it helps

Answered By: Coder

I solved this by rebuilding protos go and check /models/research/object_detection/protos check for file center_net_pb2.py check all files if protos are generated if not generate manually by code.

Answered By: Prayag Pawar

I solved this by rebuilding protos go and check /models/research/object_detection/protos check for file center_net_pb2.py check all files if protos are generated if not generate manually by code.Make sure you set your PYTHONPATH correctly first

Answered By: Prayag Pawar
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.