TensorFlow Lite学习笔记(参考Module: tf.lite | TensorFlow Lite (google.cn))
总共分为六块:
Interpreter
: 推理
model_content:
num_threads:tflite的卷积推理支持多线程,这里可以指定线程数
tf.lite.Interpreter(
model_path=None, model_content=None, experimental_delegates=None,
num_threads=None
)
OpsSet
: 参数类型
EXPERIMENTAL_TFLITE_BUILTINS_ACTIVATIONS_INT16_WEIGHTS_INT8
SELECT_TF_OPS
TFLITE_BUILTINS
TFLITE_BUILTINS_INT8
TFLITE_BUILTINS,SELECT_TF_OPS, EXPERIMENTAL_TFLITE_BUILTINS_ACTIVATIONS_INT16_WEIGHTS_INT8 都是在实验阶段,不建议使用
TFLITE_BUILTINS_INT8要用的化需要自定义数据集
Optimize
: 生成TFlite图的时候优化方法
RepresentativeDataset
: 重定义数据集
TFLiteConverter
: tflite转换器
支持
# Converting a SavedModel to a TensorFlow Lite model.
converter = tf.lite.TFLiteConverter.from_saved_model(saved_model_dir)
tflite_model = converter.convert()
#keras model xxx.h5
# Converting a tf.Keras model to a TensorFlow Lite model.
converter = tf.lite.TFLiteConverter.from_keras_model(model)
tflite_model = converter.convert()
# Converting ConcreteFunctions to a TensorFlow Lite model.
converter = tf.lite.TFLiteConverter.from_concrete_functions([func])
tflite_model = converter.convert()
TargetSpec
: 对于特定设备的特殊要求指定
supported_ops:比如二进制,正在实验阶段
supported_types:设备上支持的类型
tf.lite.TargetSpec(
supported_ops=None, supported_types=None
)