ImportError: No module named 'nets'

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:\Users\Guy\Desktop\models\research;C:\Users\Guy\Desktop\models\research\slim

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.


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