繁体   English   中英

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

[英]Script Error when run https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/image_retraining/label_image.py

我尝试通过参考以下文档来为新类别重新训练Inception的最终层

  • 我的操作系统:Windows 10 X64 Enterprise

  • 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."

有人有同样的问题吗?

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

更新了脚本链接

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

  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')]

暂无
暂无

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

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