前提・実現したいこと
https://github.com/totti0223/deepstomata
はckptファイルを読み込むように書かれていますが、h5ファイルを読み込むように変えたいので、
https://github.com/totti0223/deepstomata/blob/master/deepstomata/utils.py
の「def stomata_stat_batch_classify(...」(466行目〜)を質問に記載のコードの内容に変更して実行したら、以下のエラーが出ました。学習モデル(.h5)はkerasを使って学習させたので、復元したモデルがtensorflow形式に合っていないことから起こっていると考えています。該当のコードはエラーの原因と思われるコードの一部を抜粋して下記に置きます。元のコードが長いので以下のリンクに元コードを貼っておきます。
該当コード
[追記]
元々のプログラム(https://github.com/totti0223/deepstomata)ではckptファイル単体で実行するのですが、私の場合3つのファイル(.meta, .index, data-000)が保存され一つのckptファイルとして保存できません。これが本来の仕様であることは理解していますが、何か方法などがあればご教授いただければ幸いです。
よろしくお願いします。
発生している問題・エラーメッセージ
>>> deepstomata("C:/Users/Rx-80/OneDrive/デスクトップ/研究室/stomata/201216/WT mock") Reading config file using user defined config.ini from: C:\Users\Rx-80\AppData\Local\Programs\Python\Python35\lib\site-packages\deepstomata/config.ini config file path: C:\Users\Rx-80\AppData\Local\Programs\Python\Python35\lib\site-packages\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 Exception ignored in: <bound method BaseSession.__del__ of <tensorflow.python.client.session.Session object at 0x0000020C04EBCC50>> Traceback (most recent call last): File "C:\Users\Rx-80\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\client\session.py", line 576, in __del__ if self._session is not None: AttributeError: 'Session' object has no attribute '_session' Traceback (most recent call last): File "C:\Users\Rx-80\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\client\session.py", line 267, in __init__ fetch, allow_tensor=True, allow_operation=True)) File "C:\Users\Rx-80\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\framework\ops.py", line 2318, in as_graph_element return self._as_graph_element_locked(obj, allow_tensor, allow_operation) File "C:\Users\Rx-80\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\framework\ops.py", line 2402, in _as_graph_element_locked raise ValueError("Operation %s is not an element of this graph." % obj) ValueError: Operation name: "init" op: "NoOp" input: "^conv1/weights/Assign" input: "^conv1/biases/Assign" input: "^conv2/weights/Assign" input: "^conv2/biases/Assign" input: "^conv3/weights/Assign" input: "^conv3/biases/Assign" input: "^conv4/weights/Assign" input: "^conv4/biases/Assign" input: "^fc5/weights/Assign" input: "^fc5/biases/Assign" input: "^fc6/weights/Assign" input: "^fc6/biases/Assign" input: "^fc7/weights/Assign" input: "^fc7/biases/Assign" is not an element of this graph. 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\AppData\Local\Programs\Python\Python35\lib\site-packages\deepstomata\__init__.py", line 39, in deepstomata utils.analyze(item) # core module File "C:\Users\Rx-80\AppData\Local\Programs\Python\Python35\lib\site-packages\deepstomata\utils.py", line 569, in analyze results = stomata_stat_batch_classify(stomata_all, len(original_dets), ini['path']['classifier_path']) File "C:\Users\Rx-80\AppData\Local\Programs\Python\Python35\lib\site-packages\deepstomata\utils.py", line 495, in stomata_stat_batch_classify with tf.Session(graph=K.get_session()) as sess: File "C:\Users\Rx-80\AppData\Local\Programs\Python\Python35\lib\site-packages\keras\backend\tensorflow_backend.py", line 125, in get_session _initialize_variables() File "C:\Users\Rx-80\AppData\Local\Programs\Python\Python35\lib\site-packages\keras\backend\tensorflow_backend.py", line 282, in _initialize_variables sess.run(tf.variables_initializer(uninitialized_variables)) 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 951, in _run fetch_handler = _FetchHandler(self._graph, fetches, feed_dict_string) File "C:\Users\Rx-80\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\client\session.py", line 407, in __init__ self._fetch_mapper = _FetchMapper.for_fetch(fetches) File "C:\Users\Rx-80\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\client\session.py", line 238, in for_fetch return _ElementFetchMapper(fetches, contraction_fn) File "C:\Users\Rx-80\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\client\session.py", line 274, in __init__ 'Tensor. (%s)' % (fetch, str(e))) ValueError: Fetch argument <tensorflow.python.framework.ops.Operation object at 0x0000020C052A2A20> cannot be interpreted as a Tensor. (Operation name: "init" op: "NoOp" input: "^conv1/weights/Assign" input: "^conv1/biases/Assign" input: "^conv2/weights/Assign" input: "^conv2/biases/Assign" input: "^conv3/weights/Assign" input: "^conv3/biases/Assign" input: "^conv4/weights/Assign" input: "^conv4/biases/Assign" input: "^fc5/weights/Assign" input: "^fc5/biases/Assign" input: "^fc6/weights/Assign" input: "^fc6/biases/Assign" input: "^fc7/weights/Assign" input: "^fc7/biases/Assign" is not an element of this graph.)
該当のソースコード
python
1def stomata_stat_batch_classify(image, region_number, ckpt_path): 2 3 ''' 4 input 5 image : image read by scipy. imread if by opencv, bgr to rgb must be performed 6 ckpt_path : checkpoint absolute path 7 output 8 most likely stat of stomata, confidential level of most likely stat of stomata 9 ''' 10 DST_INPUT_SIZE = 56 11 NUM_CLASS = 4 12 tf.reset_default_graph() 13 14 image = tf.reshape(image, [-1, DST_INPUT_SIZE, DST_INPUT_SIZE, 3]) 15 logits = stomata_model.tf_inference(image, region_number, DST_INPUT_SIZE, NUM_CLASS) 16 17 with tf.Graph().as_default(): 18 with tf.session(graph=K.get_session()) as sess: 19 import keras.backend.tensorflow_backend as KTF 20 sess.run(tf.global_variables_initializer()) 21 model = load_model() 22 K.set_image_dim_ordering('tf') 23 if ckpt_path: 24 model 25 K.set_image_dim_ordering('tf') 26 softmax = tf.nn.softmax(logits).eval() 27 results = [[None for _ in range(2)] for _ in range(region_number)] 28 q = 0 29 for logit in softmax: 30 logit = [round(n * 100, 1) for n in logit] 31 logit = np.asarray(logit) 32 result = [["open", logit[0]], ["closed", logit[1]], ["partially_open", logit[2]], ["false_positive", logit[3]]] 33 result = sorted(result, key =lambda x: int(x[1]), reverse = True) 34 results[q][0] = result[0][0] 35 results[q][1] = result[0][1] 36 q += 1 37 #print ("\t",results) 38 return results
試したこと
インターネットで検索したところ、"image_dim_ordering": "tf"をkerasの.jsonファイルに入れると解決するらしいのですが、該当のファイルがpython内にあるkerasフォルダ内にないのですが、この場合の解決策などもあれば教えて頂きたいです。
参考サイト
https://stackoverflow.com/questions/46497869/valueerror-fetch-argument-tf-operation-init-8-type-noop-cannot-be-interpret
補足情報(FW/ツールのバージョンなど)
現在の環境
python 3.5.6
tensorflow 0.12.0rc0
keras 1.2.2
matplotlib 2.0.0
pandas 0.25.3
numpy 1.15.2
回答1件
あなたの回答
tips
プレビュー