LoginSignup
0
0

More than 3 years have passed since last update.

Kerasで作ったモデルをKendryte K210環境で動かす(仮)

Posted at

Kerasで学習させたモデルをK210環境(M5StickV)で動作するか試してみます。

モデルの変換は以下の2手順でできるようです。
①Kerasで学習して保存したモデルをTensorflowLiteのモデルに変換する。
②TensorflowLiteのモデルをK210モデルに変換する

TensorflowLiteのモデルに変換する。

Kerasがインストールされてる(tensorflowがインストールされてる)環境なら以下のような感じでconverterを使って簡単に変換できる。

import tensorflow as tf

converter = tf.lite.TFLiteConverter.from_keras_model_file("keras_clf_iris_dp.h5")
tflite_model = converter.convert()
open("keras_clf_iris_dp.tflite", "wb").write(tflite_model)

TensorflowLiteのモデルで推論を実行してみる。

以下のような感じでInterpreterのオブジェクトを作ってデータをセットしてinvoke()実行で推論を実行できるようです。
TensorflowLiteはKerasのモデルの1/3以下位のサイズになるようなので、TensorflowLiteの環境を作れる場合にはマイコンの環境等には向いていると思います

interpreter = tf.lite.Interpreter(model_path="keras_clf_iris_dp.tflite")
interpreter.set_tensor(input_details[0]['index'],np.reshape(X_test[0], (1,4)).astype(np.float32))
interpreter.invoke()
output_data = interpreter.get_tensor(output_details[0]['index'])
print(output_data)

K210モデルに変換してみる。

結論としては、使用しているレイヤーが未対応と思われるためうまくいきませんでした。
現在時点(2019/10/29)で他のサイトも同じ結論のようなのでバージョンアップを待つしかなさそうです。

0
0
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
0
0