Created by: Shixiaowei02
Paddle-Lite
支持使用 Flatbuffers
格式存取预测模型。预测模型分为计算图和权重两部分,我们使用 paddle::lite::fbs::ProgramDescView
和 paddle::lite::fbs::CombinedParamsDescView
作为二者的只读视图。
Flatbuffers
无需编解码,只用一个扁平缓冲区即可存放所有内容。所以我们使用 std::vector<char>&&
作为参数加载缓冲区。这里使用右值以避免深拷贝。
此外,我们对齐了 fbs::ProgramDescView
与 cpp::ProgramDesc
的读接口以支持多态,隐藏模型加载中的 NaiveBuffer
及相关格式转换。
使用示例:
#include "lite/model_parser/flatbuffers/io.h"
int main() {
using paddle::lite::fbs;
// 分别读取计算图和权重,这里用分立文件作为输入格式举例
ProgramDescView program(LoadFile(std::string("model.fbs")));
CombinedParamsDescView params(LoadFile(std::string("params.fbs")));
// 读取权重变量到作用域
lite::Scope scope;
SetScopeWithCombinedParams(&scope, params);
return 0;
}
本提交添加单元测试,并确定了 Flatbuffers 在框架内的使用形式。