3
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

TensorFlow2 からTensorFlow Liteへのモデル変換

Last updated at Posted at 2020-01-26

TensorFlow2で作ったモデルファイルをTensorFlow Lite形式に変換するメモ

TensorFlow Lite converterに従う

  • SavedModelディレクトリやtf.kerasのmodelをtfliteに変換できるらしい
  • pythonのAPIで変換する方法が推奨されてる
  • CLIもある

python APIでコンバーター書く

Converter Python API guide

SavedModelの変換

converter = tf.lite.TFLiteConverter.from_saved_model("my_savedmodel")
tflite_model = converter.convert()
open("converted_model.tflite", "wb").write(tflite_model)

Keras modelの変換


# 事前にmy_modelオブジェクトを用意しておく

converter = tf.lite.TFLiteConverter.from_keras_model(my_model)
tflite_model = converter.convert()
open("converted_model.tflite", "wb").write(tflite_model)

CLI


$ tflite_convert --saved_model_dir=my_savedmodel --output_file=my_model.tflite

Kerasのmodelの場合は --saved_model_dir--keras_model_file に置き換える

Quantizationやその他色々弄りたいならpython API使ってね、とのこと

toco?

tfliteへの変換についてWeb検索しているとtocoというcliツールが時々出てくるが、今はdeprecatedらしい

3
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?