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

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

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

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

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

0回答

2949閲覧

kerasのh5ファイルからtensorflowのpbファイル変換のエラー

mi.dai.tomo

総合スコア40

Keras

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

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2020/06/06 10:40

編集2020/06/07 05:45

前提・実現したいこと

kerasで作成した学習データをandroidで動かしてみたいと思っています。
kerasのh5ファイルからtensorflowのpbファイル変換しようと思ったですが

AssertionError: dense_2/Sigmoid is not in graph

が出ていて解決ができません。

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

Traceback (most recent call last): File "C:\Users\xxx\Desktop\python\tinn\keras_to_tensorflow.py", line 29, in <module> main() File "C:\Users\xxx\Desktop\python\tinn\keras_to_tensorflow.py", line 26, in main freeze_graph(session, [out.op.name for out in model.outputs], save_pb_dir=save_pb_dir) File "C:\Users\xxx\Desktop\python\tinn\keras_to_tensorflow.py", line 12, in freeze_graph graphdef_frozen = tf.compat.v1.graph_util.convert_variables_to_constants(session, graphdef_inf, output) File "C:\Users\xxx\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\util\deprecation.py", line 324, in new_func return func(*args, **kwargs) File "C:\Users\xxx\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\framework\graph_util_impl.py", line 359, in convert_variables_to_constants inference_graph = extract_sub_graph(input_graph_def, output_node_names) File "C:\Users\xxx\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\util\deprecation.py", line 324, in new_func return func(*args, **kwargs) File "C:\Users\xxx\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\framework\graph_util_impl.py", line 205, in extract_sub_graph _assert_nodes_are_present(name_to_node, dest_nodes) File "C:\Users\xxx\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\framework\graph_util_impl.py", line 160, in _assert_nodes_are_present assert d in name_to_node, "%s is not in graph" % d AssertionError: dense_2/Sigmoid is not in graph

該当のソースコード

import tensorflow as tf from keras.models import load_model from keras import backend as K from tensorflow.python.framework import graph_io from tensorflow.python.framework import graph_util def freeze_graph(session, output, save_pb_dir='.', save_pb_name='frozen_model.pb', save_pb_as_text=False): graph = session.graph with graph.as_default(): graphdef_inf = tf.compat.v1.graph_util.remove_training_nodes(graph.as_graph_def()) graphdef_frozen = tf.compat.v1.graph_util.convert_variables_to_constants(session, graphdef_inf, output) graph_io.write_graph(graphdef_frozen, save_pb_dir, save_pb_name, as_text=save_pb_as_text) return graphdef_frozen def main(): save_pb_dir = 'dddd.pb' keras_model = 'best.h5' K.clear_session() # This line must be executed before loading Keras model. K.set_learning_phase(0) model = load_model(keras_model) session = tf.compat.v1.keras.backend.get_session() freeze_graph(session, [out.op.name for out in model.outputs], save_pb_dir=save_pb_dir) if __name__ == '__main__': main()

###自分で調べたことや試したこと
kerasのモデル構築部分を

model.add(layers.Dense(7,activation="dense_2/sigmoid"))

したりしてみました

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

tensorflow 2.2.0
Keras 2.3.1
windows 10

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

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

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

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

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

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

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

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

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

ただいまの回答率
85.46%

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

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

質問する

関連した質問