首页 > 其他 > 详细

【tensorflow-v2.0】如何将模型转换成tflite模型

时间:2019-11-08 20:04:05      阅读:1078      评论:0      收藏:0      [点我收藏+]

前言

 

实现过程

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;

参考

1. tf.lite.TFLiteConverter

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!