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

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

新規登録して質問してみよう
ただいま回答率
85.46%
Keras

Kerasは、TheanoやTensorFlow/CNTK対応のラッパーライブラリです。DeepLearningの数学的部分を短いコードでネットワークとして表現することが可能。DeepLearningの最新手法を迅速に試すことができます。

Python 3.x

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

Q&A

解決済

1回答

1958閲覧

ckptファイル復元(Tensor name "xxx" not found in checkpoint files)ができません

Kawasaki02021

総合スコア1

Keras

Kerasは、TheanoやTensorFlow/CNTK対応のラッパーライブラリです。DeepLearningの数学的部分を短いコードでネットワークとして表現することが可能。DeepLearningの最新手法を迅速に試すことができます。

Python 3.x

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

0グッド

0クリップ

投稿2021/10/21 07:51

編集2021/10/21 08:52

前提・実現したいこと

ckptファイルを用いた画像認識プログラムを実行した際に以下のようなエラーが出ました。
以下がそのプログラムのリンクです。
https://github.com/totti0223/deepstomata
モデルが上手く復元できてないようです。
実行したモデルはVGG16を用いて学習させました。
このエラー自体の解決方法などご助言などいただければ幸いです。
よろしくお願いします。
[追記]
画像分類のコードが以下のリンクにあるutils.pyで動いています。その中の466行目から486行目でckptファイルの読み込みを行っています。
https://github.com/totti0223/deepstomata/blob/master/deepstomata/utils.py
ここのサイトhttps://louis-needless.hatenablog.com/entry/notfounderror-bully-meを参考にarg_scopeをutils.pyの467行目に入れて行いましたが、上手くいきませんでした。

発生している問題・エラーメッセージ

>>> from deepstomata import * >>> deepstomata("C:/Users/Rx-80/OneDrive/デスクトップ/研究室/stomata/201216/WT mock") Reading config file using user defined config.ini from: C:\Users\Rx-80\OneDrive\deepstomata-master\deepstomata/config.ini config file path: C:\Users\Rx-80\OneDrive\deepstomata-master\deepstomata/config.ini Reading config file. Validating detector path Detector located Validating classifier path Classifier located config file imported properly listing image files in: C:/Users/Rx-80/OneDrive/デスクトップ/研究室/stomata/201216/WT mock directory detected. reading files inside directory. Will be analyzing the listed files... ['seq22124_result.jpg', 'seq22125_result.jpg', 'seq22126_result.jpg', 'seq22128_result.jpg', 'seq22129_result.jpg', 'seq22130_result.jpg', 'seq22131_result.jpg', 'seq22132_result.jpg', 'seq22133_result.jpg', 'seq22134_result.jpg', 'seq22135_result.jpg', 'seq22136_result.jpg', 'seq22137_result.jpg', 'seq22138_result.jpg', 'seq22139_result.jpg', 'seq22140_result.jpg', 'seq22141_result.jpg', 'seq22142_result.jpg', 'seq22143_result.jpg', 'seq22144_result.jpg', 'seq22145_result.jpg', 'seq22146_result.jpg', 'seq22147_result.jpg', 'seq22148_result.jpg', 'seq22149_result.jpg', 'seq22150_result.jpg', 'seq22151_result.jpg', 'seq22152_result.jpg', 'seq22153_result.jpg', 'seq22154_result.jpg', 'seq22155_result.jpg', 'seq22156_result.jpg', 'seq22157_result.jpg', 'seq22158_result.jpg', 'seq22159_result.jpg', 'seq22160_result.jpg', 'seq22161_result.jpg', 'seq22162_result.jpg', 'seq22163_result.jpg'] analysis start seq22124_result.jpg 2 stomata detected Traceback (most recent call last): File "C:\Users\Rx-80\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\client\session.py", line 1021, in _do_call return fn(*args) File "C:\Users\Rx-80\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\client\session.py", line 1003, in _run_fn status, run_metadata) File "C:\Users\Rx-80\AppData\Local\Programs\Python\Python35\lib\contextlib.py", line 66, in __exit__ next(self.gen) File "C:\Users\Rx-80\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\framework\errors_impl.py", line 469, in raise_exception_on_not_ok_status pywrap_tensorflow.TF_GetCode(status)) tensorflow.python.framework.errors_impl.NotFoundError: Tensor name "fc7/weights" not found in checkpoint files C:/test/stomata_classify_test001.ckpt [[Node: save/RestoreV2_13 = RestoreV2[dtypes=[DT_FLOAT], _device="/job:localhost/replica:0/task:0/cpu:0"](_recv_save/Const_0, save/RestoreV2_13/tensor_names, save/RestoreV2_13/shape_and_slices)]] During handling of the above exception, another exception occurred: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Users\Rx-80\OneDrive\deepstomata-master\deepstomata\__init__.py", line 39, in deepstomata utils.analyze(item) # core module File "C:\Users\Rx-80\OneDrive\deepstomata-master\deepstomata\utils.py", line 556, in analyze results = stomata_stat_batch_classify(stomata_all, len(original_dets), ini['path']['classifier_path']) File "C:\Users\Rx-80\OneDrive\deepstomata-master\deepstomata\utils.py", line 486, in stomata_stat_batch_classify saver.restore(sess, ckpt_path) File "C:\Users\Rx-80\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\training\saver.py", line 1388, in restore {self.saver_def.filename_tensor_name: save_path}) File "C:\Users\Rx-80\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\client\session.py", line 766, in run run_metadata_ptr) File "C:\Users\Rx-80\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\client\session.py", line 964, in _run feed_dict_string, options, run_metadata) File "C:\Users\Rx-80\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\client\session.py", line 1014, in _do_run target_list, options, run_metadata) File "C:\Users\Rx-80\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\client\session.py", line 1034, in _do_call raise type(e)(node_def, op, message) tensorflow.python.framework.errors_impl.NotFoundError: Tensor name "fc7/weights" not found in checkpoint files C:/test/stomata_classify_test001.ckpt [[Node: save/RestoreV2_13 = RestoreV2[dtypes=[DT_FLOAT], _device="/job:localhost/replica:0/task:0/cpu:0"](_recv_save/Const_0, save/RestoreV2_13/tensor_names, save/RestoreV2_13/shape_and_slices)]] NotFoundError (see above for traceback): Tensor name "fc7/weights" not found in checkpoint files C:/test/stomata_classify_test001.ckpt 2_13/t [[Node: save/RestoreV2_13 = RestoreV2[dtypes=[DT_FLOAT], _device="/job:localhost/replica:0/task:0/cpu:0"](_recv_save/Const_0, save/RestoreV2_13/tensor_names, save/RestoreV2_13/shape_and_slices)]]

該当のソースコード

python

1with vgg.arg_scope(arg_scope): 2 net, end_points = vgg.vgg_16.vgg_16_50(input=input) 3def stomata_stat_batch_classify(image, region_number, ckpt_path): 4 5 ''' 6 input 7 image : image read by scipy. imread if by opencv, bgr to rgb must be performed 8 ckpt_path : checkpoint absolute path 9 output 10 most likely stat of stomata, confidential level of most likely stat of stomata 11 ''' 12 DST_INPUT_SIZE = 56 13 NUM_CLASS = 4 14 tf.reset_default_graph() 15 16 image = tf.reshape(image, [-1, DST_INPUT_SIZE, DST_INPUT_SIZE, 3]) 17 logits = stomata_model.tf_inference(image, region_number, DST_INPUT_SIZE, NUM_CLASS) 18 19 sess = tf.InteractiveSession() 20 saver = tf.train.Saver() 21 sess.run(tf.global_variables_initializer()) 22 if ckpt_path: 23 saver.restore(sess, ckpt_path) 24 softmax = tf.nn.softmax(logits).eval() 25 results = [[None for _ in range(2)] for _ in range(region_number)] 26 q = 0 27 for logit in softmax: 28 logit = [round(n * 100, 1) for n in logit] 29 logit = np.asarray(logit) 30 result = [["open", logit[0]], ["closed", logit[1]], ["partially_open", logit[2]], ["false_positive", logit[3]]] 31 result = sorted(result, key =lambda x: int(x[1]), reverse = True) 32 results[q][0] = result[0][0] 33 results[q][1] = result[0][1] 34 q += 1 35 #print ("\t",results) 36 return results

試したこと

以下のサイトを参考にモデルを組んで学習させましたが、結果は似たようなエラーが出ました。
Kerasは使わない方がいいのでしょうか?
参考サイト
https://qiita.com/haru1977/items/17833e508fe07c004119

補足情報(FW/ツールのバージョンなど)

現在の環境
Windows 10
python 3.5.6
tensorflow 0.12.0rc0
keras 1.2.2
matplotlib 2.0.0
pandas 0.25.3
numpy 1.15.2
原因は恐らくここのコードとモデルの構造が一致していないことが原因と考えているのですが、学習モデルをこれにどう対応させていいのかが分からないです。

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

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

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

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

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

guest

回答1

0

自己解決

ここで質問した内容でjbpb0さんに教えていただいたリンクに答えがありました。単純にckptの復元方法が間違えていることが分かりました。utilsの486行目の復元コードを```
with tf.Session() as sess:
saver = tf.train.import_meta_graph('/xxx/model.ckpt.meta')
saver.restore(sess, ckpt_pass)

に変えれば解決しました。 単純にページの内容をよく読んでいませんでした。 反省です。

投稿2021/10/22 06:33

編集2021/10/22 06:38
Kawasaki02021

総合スコア1

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.46%

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

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

質問する

関連した質問