TensorFlowHubの学習済みモデルをTensorFlowLiteに変換したい

実現したいこと

表題の通り、TensorFlowの学習済みモデルを保存し、TensorFlowLiteに変換したいです

前提

Google Colaboratory上で実行しています。

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

現在発生しているエラーは以下の通りです。

ValueError Traceback (most recent call last) <ipython-input-33-7c46c3e13015> in <cell line: 3>() 1 import tensorflow as tf 2 ----> 3 converter = tf.lite.TFLiteConverter.from_saved_model("/saved_model_directory") 4 tflite_model = converter.convert() 5 open("test_model.tflite", "wb").write(tflite_model) /usr/local/lib/python3.10/dist-packages/tensorflow/lite/python/lite.py in from_saved_model(cls, saved_model_dir, signature_keys, tags) 1826 1827 if not signature_keys: -> 1828 raise ValueError("Only support at least one signature key.") 1829 1830 funcs = [] ValueError: Only support at least one signature key.

該当のソースコード

python

1import tensorflow as tf 2import tensorflow_hub as hub 3 4# モデルを選択、ロード5module_handle = "https://tfhub.dev/google/faster_rcnn/openimages_v4/inception_resnet_v2/1"6detector = hub.load(module_handle)7 8# モデルの保存(saved_model_directoryが作成され、その中にモデルが保存される)9saved_model_path = "/saved_model_directory"10tf.saved_model.save(detector, saved_model_path)11 12# この部分でエラーが発生13converter = tf.lite.TFLiteConverter.from_saved_model(saved_model_path)14 15tflite_model = converter.convert()16open("test_model.tflite", "wb").write(tflite_model)

試したこと

右の質問を参考にシグネチャーを確認してみた所、以下のように表示されました。参考にした質問

python

1imported = tf.saved_model.load(path)2print(imported.signatures)

出力結果:_SignatureMap({})
結果を見るにシグネチャーは何も表示されず、このあたりが原因だと思うんですが、完全に詰まっています。
宜しくお願い致します。

コメントを投稿

0 コメント