Help us understand the problem. What is going on with this article?

Tensorflowでエラー「tensorflow error KeyError: “The name 'import/Mul' refers to an Operation not in the graph.”」が出た時

More than 1 year has passed since last update.

Tensorflowのエラーが発生した時の解決法

こちらの記事を参考に、画像を認識して判定するものをつくってみました。
TensorFlowで画像認識「〇〇判別機」を作る - Qiita

で、実際にコマンドを実行してみると

python label_image.py --image xxx.jpg --graph retrained_graph.pb --labels retrained_labels.txt

こんなエラーが発生しました。

 /Users/xxx/anaconda3/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
      from ._conv import register_converters as _register_converters
    2018-07-11 00:39:22.028051: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
    Traceback (most recent call last):
      File "label_image.py", line 131, in 
        input_operation = graph.get_operation_by_name(input_name)
      File "/Users/xxx/tensorFlow/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3718, in get_operation_by_name
        return self.as_graph_element(name, allow_tensor=False, allow_operation=True)
      File "/Users/xxx/tensorFlow/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3590, in as_graph_element
        return self._as_graph_element_locked(obj, allow_tensor, allow_operation)
      File "/Users/xxx/tensorFlow/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3650, in _as_graph_element_locked
        "graph." % repr(name))
    KeyError: "The name 'import/Mul' refers to an Operation not in the graph."

ここがエラーになっているようです。

KeyError: "The name 'import/Mul' refers to an Operation not in the graph."

ちなみに「label_image.py」の中身は

      input_height = 299
      input_width = 299
      input_mean = 0
      input_std = 255
      input_layer = "Mul"
      output_layer = "final_result"

こんなかんじ。

色々調べた結果、最後に「--input_layer=Placeholder」をつけると解決。
問題なく動作するようになりました。

python label_image.py --image cat3.jpg --graph retrained_graph.pb --labels retrained_labels.txt --input_layer=Placeholder 
umeee
プログラミングはエンタテイメントだ! 楽しむことがたいせつ。 興味のおもむくままにやりましょう。 最近のロールはプロジェクトマネージャ、ITコンサルタントです。
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away