質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

Q&A

0回答

2334閲覧

TensorFlowのチュートリアルのサンプルlabel_image.pyがうまく動かない。

Aki1000

総合スコア78

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

0グッド

0クリップ

投稿2019/01/21 09:58

下記のような幾つかのサイトを参考にしつつ、うどん、そば、スパゲッティの識別機を作ろうとしました。TensorFlowのバージョンは1.5.0です。

https://qiita.com/too-ai/items/4fad0239b8b3c465fe6d
https://blog.ch3cooh.jp/entry/20180930/1538287200

写真を集め、種類別にフォルダ毎に分け、retrain.pyを実行して学習ファイルとラベルファイル、retrained_graph.pbとretrained_labels.txtを生成するところまでは成功しました。

しかし、test.jpgを識別するため

python label_image.py --image test.jpg --graph retrained_graph.pb --labels retrained_labels.txt --input_layer Placeholder --output
final_result

と実行すると、下記のようなエラーメッセージが出て動きません。

Error

1Traceback (most recent call last): 2 File "C:\Python\Python35\lib\site-packages\tensorflow\python\client\session.py", line 1350, in _do_call 3 return fn(*args) 4 File "C:\Python\Python35\lib\site-packages\tensorflow\python\client\session.py", line 1329, in _run_fn 5 status, run_metadata) 6 File "C:\Python\Python35\lib\site-packages\tensorflow\python\framework\errors_impl.py", line 473, in __exit__ 7 c_api.TF_GetCode(self.status.status)) 8tensorflow.python.framework.errors_impl.NotFoundError: Error while reading resource variable module/InceptionV3/Mixed_7c/Branch_0/Conv2d_0a_1x1/weights from Container: local 9host. This could mean that the variable was uninitialized. Not found: Container localhost does not exist. (Could not find resource: localhost/module/InceptionV3/Mixed_7c/Bra 10nch_0/Conv2d_0a_1x1/weights) 11 [[Node: import/module_apply_default/InceptionV3/InceptionV3/Mixed_7c/Branch_0/Conv2d_0a_1x1/Conv2D/ReadVariableOp = ReadVariableOp[dtype=DT_FLOAT, _device="/job:loc 12alhost/replica:0/task:0/device:CPU:0"](import/module/InceptionV3/Mixed_7c/Branch_0/Conv2d_0a_1x1/weights)]] 13 14During handling of the above exception, another exception occurred: 15 16Traceback (most recent call last): 17 File "label_image.py", line 139, in <module> 18 input_operation.outputs[0]: t 19 File "C:\Python\Python35\lib\site-packages\tensorflow\python\client\session.py", line 895, in run 20 run_metadata_ptr) 21 File "C:\Python\Python35\lib\site-packages\tensorflow\python\client\session.py", line 1128, in _run 22 feed_dict_tensor, options, run_metadata) 23 File "C:\Python\Python35\lib\site-packages\tensorflow\python\client\session.py", line 1344, in _do_run 24 options, run_metadata) 25 File "C:\Python\Python35\lib\site-packages\tensorflow\python\client\session.py", line 1363, in _do_call 26 raise type(e)(node_def, op, message) 27tensorflow.python.framework.errors_impl.NotFoundError: Error while reading resource variable module/InceptionV3/Mixed_7c/Branch_0/Conv2d_0a_1x1/weights from Container: local 28host. This could mean that the variable was uninitialized. Not found: Container localhost does not exist. (Could not find resource: localhost/module/InceptionV3/Mixed_7c/Bra 29nch_0/Conv2d_0a_1x1/weights) 30 [[Node: import/module_apply_default/InceptionV3/InceptionV3/Mixed_7c/Branch_0/Conv2d_0a_1x1/Conv2D/ReadVariableOp = ReadVariableOp[dtype=DT_FLOAT, _device="/job:loc 31alhost/replica:0/task:0/device:CPU:0"](import/module/InceptionV3/Mixed_7c/Branch_0/Conv2d_0a_1x1/weights)]] 32 33Caused by op 'import/module_apply_default/InceptionV3/InceptionV3/Mixed_7c/Branch_0/Conv2d_0a_1x1/Conv2D/ReadVariableOp', defined at: 34 File "label_image.py", line 124, in <module> 35 graph = load_graph(model_file) 36 File "label_image.py", line 33, in load_graph 37 tf.import_graph_def(graph_def) 38 File "C:\Python\Python35\lib\site-packages\tensorflow\python\util\deprecation.py", line 316, in new_func 39 return func(*args, **kwargs) 40 File "C:\Python\Python35\lib\site-packages\tensorflow\python\framework\importer.py", line 554, in import_graph_def 41 op_def=op_def) 42 File "C:\Python\Python35\lib\site-packages\tensorflow\python\framework\ops.py", line 3160, in create_op 43 op_def=op_def) 44 File "C:\Python\Python35\lib\site-packages\tensorflow\python\framework\ops.py", line 1625, in __init__ 45 self._traceback = self._graph._extract_stack() # pylint: disable=protected-access 46 47NotFoundError (see above for traceback): Error while reading resource variable module/InceptionV3/Mixed_7c/Branch_0/Conv2d_0a_1x1/weights from Container: localhost. This cou 48ld mean that the variable was uninitialized. Not found: Container localhost does not exist. (Could not find resource: localhost/module/InceptionV3/Mixed_7c/Branch_0/Conv2d_0 49a_1x1/weights) 50 [[Node: import/module_apply_default/InceptionV3/InceptionV3/Mixed_7c/Branch_0/Conv2d_0a_1x1/Conv2D/ReadVariableOp = ReadVariableOp[dtype=DT_FLOAT, _device="/job:loc 51alhost/replica:0/task:0/device:CPU:0"](import/module/InceptionV3/Mixed_7c/Branch_0/Conv2d_0a_1x1/weights)]] 52

label_image.pyの中の、
input_layer = "input"
output_layer = "InceptionV3/Predictions/Reshape_1"
はこのままで実行すると、KeyErrorが出ますので
参考のしてたホームページが書いていた通り、

 input_layer = "Mul"
output_layer = "final_result"

input_layer = "Placeholder"
output_layer = "final_result"
にしました。どちらでも動きません。
どうやったら動くでしょうか?

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問