前言
实现过程
1.不同模型的调用函数接口稍微有些不同
# Converting a SavedModel to a TensorFlow Lite model. converter = lite.TFLiteConverter.from_saved_model(saved_model_dir) tflite_model = converter.convert() # Converting a tf.Keras model to a TensorFlow Lite model. converter = lite.TFLiteConverter.from_keras_model(model) tflite_model = converter.convert() # Converting ConcreteFunctions to a TensorFlow Lite model. converter = lite.TFLiteConverter.from_concrete_functions([func]) tflite_model = converter.convert()
2. 完整的实现
import tensorflow as tf graph_def_file = ‘./model/detector/‘ input_arrays = [‘serving_default‘] output_arrays = [‘serve‘] converter = tf.lite.TFLiteConverter.from_saved_model(graph_def_file, input_arrays, output_arrays) tflite_model = converter.convert() open(‘model.tflite‘, ‘wb‘).write(tflite_model)
其中,
@classmethod from_saved_model( cls, saved_model_dir, signature_keys=None, tags=None )
另外
For more complex SavedModels, the optional parameters that can be passed into TFLiteConverter.from_saved_model() are input_arrays, input_shapes, output_arrays, tag_set and signature_key. Details of each parameter are available by running help(tf.lite.TFLiteConverter).
对于如何查看模型的操作op,可查看here;
参考
2. stackoverflow_how-to-create-a-tflite-file-from-saved-model-ssd-mobilenet;
3. tfv1-模型文件转换;
完
【tensorflow-v2.0】如何将模型转换成tflite模型
原文:https://www.cnblogs.com/happyamyhope/p/11822111.html