目录
April 4, 2023 · View on GitHub
快速上手用Bolt部署Tflite模型
目录
方法1:直接用bolt部署tflite模型 方法2:通过转换成onnx模型部署 附:tflite部署 常见问题 bolt转换和推理添加新算子
方法1:直接用bolt部署tflite模型
对于常见的CNN模型可以采用直接部署的方式,对于含有复杂reshape/transpose等算子的网络,建议通过转换成onnx模型部署。
-
下载和编译bolt项目
请参考INSTALL.md。
-
使用X2bolt转换tflite格式模型到bolt格式模型
详细请参考USER_HANDBOOK.md或者 --help。
- 示例:转换./example.tflite到./example_f32.bolt
./X2bolt -d ./ -m example -i FP32 -
通用benchmark测试
详细请参考USER_HANDBOOK.md或者 --help。
- 示例:CPU推理./example_f32.bolt,查看模型输入输出信息和推理时间。
./benchmark -m ./example_f32.bolt -
C/C++/Java API开发
详细请参考DEVELOPER.md。
方法2:通过转换成onnx模型部署
-
tflite转onnx
tensorflow-onnx提供了工具转换tflite模型到onnx模型。
-
用bolt部署onnx模型
附:tflite部署
-
使用tflite python推理
bolt提供了一个简单的示例运行脚本inference/engine/tools/tflite_tools/benchmark.py,支持单输入/多输入,支持指定输入文件或输入文件夹,支持添加新输出tensor(中间tensor)。
- 示例:全1输入测试
python inference/engine/tools/tflite_tools/benchmark.py ./example.tflite- 示例:当前目录./下单txt文件输入,模型有1个输入,名字为input,input.txt是输入input的数据内容,用空格分割。
python inference/engine/tools/tflite_tools/benchmark.py ./example.tflite ./input.txt- 示例:当前目录./下多txt文件输入,模型有2个输入,名字分别为input0和input1,input0.txt是输入input0的数据内容,用空格分割,input0.txt是输入input1的数据内容。
python inference/engine/tools/tflite_tools/benchmark.py ./example.tflite ./- 示例:当前目录./下多txt文件输入,输入维度是动态的,模型有2个输入,名字分别为input0和input1,shape.txt记录实际推理输入维度,input0.txt是输入input0的数据内容,用空格分割,input0.txt是输入input1的数据内容。
shape.txt内容:维度用空格分割
input0 1 3 224 224 input1 1 1 224 224python inference/engine/tools/tflite_tools/benchmark.py ./example.tflite ./- 示例:全1输入测试,添加新输出,新添加的2个输出名字tensor0和tensor1存放在output.txt
output.txt内容:
tensor0 tensor1python inference/engine/tools/tflite_tools/benchmark.py ./example.tflite None ./output.txt
常见问题
-
bolt转换和推理添加新算子
详细请参考DEVELOPER.md。