简体   繁体   English

导入错误:没有名为 .nets 的模块

[英]ImportError: No module named 'nets'

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.我正在尝试从 tensorflow/models 中提供的 export_inference_graph.py 脚本将 trained_checkpoint 转换为最终冻结的 model,但出现以下错误结果。 And yes,I have already setup $PYTHONPATH to "models/slim" but still I get this error,can someone help me out?是的,我已经将 $PYTHONPATH 设置为“models/slim”,但我仍然收到此错误,有人可以帮助我吗?

$ 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.我已经为此苦苦挣扎了好几天,尝试了很多解决方案都没有用我正在使用 Ubuntu 16.04 和 tensorflow-gpu 版本。

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 Windowshttps://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/installation.md 上查看 Protobuf Compilation 并正确设置 PYTHONPATH,这就是我为 Windows 解决此问题的方法

For Windows:对于 Windows:

From tensorflow/models/research/来自张量流/模型/研究/

Step1: protoc object_detection/protos/*.proto --python_out=.第一步: 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 Ubuntu 18 物理 GPU(设备:0,名称:Tesla K80,pci 总线 ID:0000:00:1e.0,计算能力:3.7)强文本

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.以防万一您已经下载或克隆了您的模型目录。

I did get the same error, because I had missed out to actually put the slim package into the tensorflow/models folder.我确实遇到了同样的错误,因为我错过了将超薄包实际放入 tensorflow/models 文件夹的机会。 The slim package is on https://github.com/tensorflow/models超薄包位于https://github.com/tensorflow/models

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 . TF-超薄可作为通过TensorFlow 1.0 tf.contrib.slim,所以你并不需要,如果你使用的额外安装pip install tensorflow You still need to do these 3 things:你仍然需要做这3件事:

  1. Install the models library安装模型库

    $ cd $ git clone https://github.com/tensorflow/models/
  2. Add the PYTHONPATH to .bashrcPYTHONPATH添加到.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.完成这 3 个步骤后,您就大功告成了。 Now you can import the TF nets like this:现在您可以像这样导入 TF 网络:

import tensorflow as tf
from tensorflow.contrib import slim
from nets import inception_resnet_v2

这在较新版本的 tensorflow 上是固定的,如果你得到它,只需更新你的 tensorflow 版本。

For MacOS:对于 MacOS:

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

Solves the problem.解决问题。

encountered the slim error on windows and this solved my problem在 Windows 上遇到了小错误,这解决了我的问题

. . What I did was, I just copied the entire nets folder from slim directory to C:\\Python\\Python\\Lib\\site-packages\\object_detection-0.1-py3.5.egg (where I installed object_detection API).我所做的是,我只是将整个 nets 文件夹从 slim 目录复制到 C:\\Python\\Python\\Lib\\site-packages\\object_detection-0.1-py3.5.egg(我在其中安装了 object_detection API)。 Then the error is completely gone.然后错误就完全消失了。

This is a PYTHONPATH issue.这是一个 PYTHONPATH 问题。

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.我想补充现有的答案,如果它仍然不适合您并且您使用的是 Anaconda 环境,请使用发行版附带的 Anaconda Prompt(在管理员模式下),而不是您的操作系统的系统提示。 Set the PYTHONPATH within the Anaconda Prompt and run your commands from there.在 Anaconda Prompt 中设置 PYTHONPATH 并从那里运行您的命令。

Also the PYTHONPATH is reseted at each deactivation of the anaconda environment, including here a machine restart.此外,每次停用 anaconda 环境时都会重置 PYTHONPATH,包括此处的机器重启。 So remember to set it again.所以记得重新设置。

IF you are using Jupyter Notebook and using Linux sys如果您正在使用 Jupyter Notebook 并使用 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希望它有帮助

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.我通过重建 protos go 解决了这个问题,并检查 /models/research/object_detection/protos 检查文件 center.net_pb2.py 检查所有文件是否生成了 protos 如果不是通过代码手动生成。

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我通过重建 protos go 并检查 /models/research/object_detection/protos 检查文件 center.net_pb2.py 来解决这个问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM