LoginSignup
6

More than 3 years have passed since last update.

TensorflowのモデルをLiteへ変換する方法

Last updated at Posted at 2020-02-02

TensorflowLiteについて

スマートフォンや、埋め込みデバイス用の機械学習ツールセットです!
Tensorflowよりも軽量です。

変換方法について

PCに、PythonとTensorflow(pip)がインストールされていることを前提とします。
まず、変換するモデルを用意します。

python上で変換

サンプル

import tensorflow as tf

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

使い方

import tensorflow as tf

converter = tf.lite.TFLiteConverter.from_saved_model("モデルへの相対パス")
tflite_model = converter.convert()
open("モデルの保存先", "wb").write(tflite_model)

コマンドライン上で変換

コマンドライン上で変換する方法もあります。

サンプル

tflite_convert \
  --saved_model_dir=test_model.pb \
  --output_file=test_model.tflite

使い方

tflite_convert \
  --saved_model_dir=モデルへの相対パス \
  --output_file=モデルの保存先

最後に

TensorflowLiteをAndroidに組み込む方法を解説していますので、良ければぜひ。
記事はこちら

また、公式の情報も参考にしてください。
公式記事

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
What you can do with signing up
6