models icon indicating copy to clipboard operation
models copied to clipboard

ImportError: No module named 'nets'

Open arcslash opened this issue 9 years ago • 13 comments

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.

arcslash avatar Sep 04 '17 04:09 arcslash

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

jart avatar Sep 04 '17 05:09 jart

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

astorfi avatar Sep 05 '17 16:09 astorfi

Its already there.

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

arcslash avatar Sep 05 '17 16:09 arcslash

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

astorfi avatar Sep 05 '17 18:09 astorfi

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"))

icoxfog417 avatar Sep 30 '17 03:09 icoxfog417

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

codybushnell avatar Nov 06 '17 16:11 codybushnell

@icoxfog417 this is working. many thanks.

AllanZuo avatar Jun 29 '18 12:06 AllanZuo

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

moinkhan3012 avatar Sep 25 '18 09:09 moinkhan3012

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

Please any help in this issue will be appreciated.

Moohialdin99 avatar Dec 15 '18 10:12 Moohialdin99

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

george1459 avatar Jan 15 '19 04:01 george1459

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

gosick237 avatar Jun 09 '19 00:06 gosick237

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

erolrecep avatar Oct 31 '19 13:10 erolrecep

Are you satisfied with the resolution of your issue? Yes No

google-ml-butler[bot] avatar Jan 09 '21 04:01 google-ml-butler[bot]