环境
- Win10 x86 64
- TensorFlow 2.3.1
- Python3.6
目录
安装tflite
pip3 install https://dl.google.com/coral/python/tflite_runtime-2.1.0.post1-cp36-cp36m-win_amd64.whl
本机是intel的cpu但安装amd64也可以正常运行,毕竟windows里就没有x86的选项。
模型转换
将基于 TensorFlow 2.3.1训练得到的模型直接转换为 TensorFlow Lite 模型,官方指南,我的TensorFlow 模型是PB格式,转换代码如下:
import tensorflow as tf
if __name__ == '__main__':
int_path = "TensorFlow_model_path_pb"
out_path = ""
# Converting a SavedModel to a TensorFlow Lite model.
converter = tf.lite.TFLiteConverter.from_saved_model(int_path )
#Normalization or quantization
converter.post_training_quantize = True
tflite_model = converter.convert()
print(tflite_model)
open(out_path, "wb").write(tflite_model)