raspberry pi 1でtensorflow lite その2
概要
raspberry pi 1でtensorflow liteやってみた。
tfliteファイルの作り方を調査してみた。
4つの方法がある。
環境
tensorflow 1.12
tf.Sessionから作る。
import tensorflow as tf
import tensorflow.contrib.lite as lite
img = tf.placeholder(name = "img", dtype = tf.float32, shape = (1, 64, 64, 3))
var = tf.get_variable("weights", dtype = tf.float32, shape = (1, 64, 64, 3))
val = img + var
out = tf.identity(val, name = "out")
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
converter = lite.TFLiteConverter.from_session(sess, [img], [out])
tflite_model = converter.convert()
open("converted_model.tflite", "wb").write(tflite_model)
freeze_graphなpbファイルから作る。
import tensorflow as tf
import tensorflow.contrib.lite as lite
graph_def_file = "/path/to/Downloads/mobilenet_v1_1.0_224/frozen_graph.pb"
input_arrays = ["input"]
output_arrays = ["MobilenetV1/Predictions/Softmax"]
converter = lite.TFLiteConverter.from_frozen_graph(graph_def_file, input_arrays, output_arrays)
tflite_model = converter.convert()
open("converted_model.tflite", "wb").write(tflite_model)
高級APIのSavedModelから作る。
import tensorflow as tf
import tensorflow.contrib.lite as lite
converter = lite.TFLiteConverter.from_saved_model(saved_model_dir)
tflite_model = converter.convert()
open("converted_model.tflite", "wb").write(tflite_model)
kerasモデルから作る。
import tensorflow as tf
import tensorflow.contrib.lite as lite
converter = lite.TFLiteConverter.from_keras_model_file("keras_model.h5")
tflite_model = converter.convert()
open("converted_model.tflite", "wb").write(tflite_model)
import tensorflow as tf
import tensorflow.contrib.lite as lite
img = tf.placeholder(name = "img", dtype = tf.float32, shape = (1, 64, 64, 3))
var = tf.get_variable("weights", dtype = tf.float32, shape = (1, 64, 64, 3))
val = img + var
out = tf.identity(val, name = "out")
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
converter = lite.TFLiteConverter.from_session(sess, [img], [out])
tflite_model = converter.convert()
open("converted_model.tflite", "wb").write(tflite_model)
import tensorflow as tf
import tensorflow.contrib.lite as lite
graph_def_file = "/path/to/Downloads/mobilenet_v1_1.0_224/frozen_graph.pb"
input_arrays = ["input"]
output_arrays = ["MobilenetV1/Predictions/Softmax"]
converter = lite.TFLiteConverter.from_frozen_graph(graph_def_file, input_arrays, output_arrays)
tflite_model = converter.convert()
open("converted_model.tflite", "wb").write(tflite_model)
高級APIのSavedModelから作る。
import tensorflow as tf
import tensorflow.contrib.lite as lite
converter = lite.TFLiteConverter.from_saved_model(saved_model_dir)
tflite_model = converter.convert()
open("converted_model.tflite", "wb").write(tflite_model)
kerasモデルから作る。
import tensorflow as tf
import tensorflow.contrib.lite as lite
converter = lite.TFLiteConverter.from_keras_model_file("keras_model.h5")
tflite_model = converter.convert()
open("converted_model.tflite", "wb").write(tflite_model)
import tensorflow as tf
import tensorflow.contrib.lite as lite
converter = lite.TFLiteConverter.from_saved_model(saved_model_dir)
tflite_model = converter.convert()
open("converted_model.tflite", "wb").write(tflite_model)
import tensorflow as tf
import tensorflow.contrib.lite as lite
converter = lite.TFLiteConverter.from_keras_model_file("keras_model.h5")
tflite_model = converter.convert()
open("converted_model.tflite", "wb").write(tflite_model)
以上。
Author And Source
この問題について(raspberry pi 1でtensorflow lite その2), 我々は、より多くの情報をここで見つけました https://qiita.com/ohisama@github/items/6dd9e0317aabd776beb0著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .