运行时出现脚本错误https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/image_retraining/label_image.py

时间:2017-09-01 01:56:01

标签: python python-3.x tensorflow

我尝试通过参考以下doc

重新启动Inception的新类别的最终图层
  • 我的操作系统:Windows 10 X64企业版

  • Anaconda 4.4的Python 3.6.2

  • Tensorflow:1.3.0(仅CPU版本)

当我使用由我收集并完成培训的新图像时,我使用以下推荐测试,但失败了!

(tensorflow13) C:\Users\James\Tensorflow\model-retrain\tensorflow-for-poets-2\scripts>python .\label_image.py --image c:\Users\James\Tensorflow\sample_img\Panda001.jpg --graph c:\Users\James\Tensorflow\model-retrain\tensorflow-for-poets-2\scripts\retrained_graph.pb --labels C:\Users\James\Tensorflow\model-retrain\tensorflow-for-poets-2\scripts\retrained_labels.txt

错误讯息:

2017-09-01 09:27:46.902115: I C:\tf_jenkins\home\workspace\nightly-win\M\windows\PY\36\tensorflow\core\platform\cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
Traceback (most recent call last):
  File ".\label_image.py", line 120, in <module>
    input_operation = graph.get_operation_by_name(input_name);
  File "C:\Users\James\AppData\Local\conda\conda\envs\tensorflow13\lib\site-packages\tensorflow\python\framework\ops.py", line 3225, in get_operation_by_name
    return self.as_graph_element(name, allow_tensor=False, allow_operation=True)
  File "C:\Users\James\AppData\Local\conda\conda\envs\tensorflow13\lib\site-packages\tensorflow\python\framework\ops.py", line 3097, in as_graph_element
    return self._as_graph_element_locked(obj, allow_tensor, allow_operation)
  File "C:\Users\James\AppData\Local\conda\conda\envs\tensorflow13\lib\site-packages\tensorflow\python\framework\ops.py", line 3157, in _as_graph_element_locked
    "graph." % repr(name))
KeyError: "The name 'import/input' refers to an Operation not in the graph."

有没有人有同样的问题?

2 个答案:

答案 0 :(得分:0)

由于某些原因,retrained_graph.pb没有脚本期望的输入。可能它的构建方式与教程的预期略有不同(特别是关于如何导入元图)。

答案 1 :(得分:0)

Updated link to script

这里的问题是您的输入/输出可能是错误的,脚本正在使用此输入/输出:

  input_name = "file_reader"
  output_name = "normalized"

如果您训练了该模型,则可能需要查找输入/输出,因为它们可能会有所不同。

我不知道找出答案的最佳方法,但是这段代码对我有所帮助:

import tensorflow as tf
frozen='/tensorflow/mobilenets/mobilenet_v1_1.0_224.pb'
gf = tf.GraphDef()
gf.ParseFromString(open(frozen,'rb').read())
[n.name + '=>' +  n.op for n in gf.node if n.op in ( 'Softmax','Placeholder')]
[n.name + '=>' +  n.op for n in gf.node if n.op in ( 'Softmax','Mul')]