作者: Sam(甄峰) sam_code@hotmail.com
以分类模型和目标检测模型分别演示模型推理。
0. 基础介绍:
0.1:PaddlePredictor:
PaddlePredictor是Paddle
Lite的预测器,由CreatePaddlePredictor()根据MobileConfig 配置创建。
可以使用PaddlePredictor的接口获取输入Tensor,设置输入数据,执行模型预测,获取输出等。
0.1.1:创建PaddlePredictor--预测器,获取模型所有InputName.
// 设置 MobileConfig
MobileConfig config;
config.set_model_dir(FLAGS_model_dir);
// 根据 MobileConfig 创建
PaddlePredictor
std::shared_ptr<</span>PaddlePredictor> predictor=CreatePaddlePredictor<</span>MobileConfig>(config);
// 获得模型的输入和输出名称
std::vector<</span>std::string> input_names = predictor->GetInputNames();
for(inti=0;i<</span>input_names.size();i++)
{
printf("Input name[%d]:
%s\n",i,input_names[i].c_str());
}
std::vector<</span>std::string> output_names=predictor->GetOutputNames();
for(inti=0; i<</span>output_names.size(); i++)
{
printf("Output
name[%d]:
%s\n",i,output_names[i].c_str());
}
当获取Input
Names后,就可以通过predictor->GetInputByName()获取Tensor指针。
0.2:CreatePaddlePredictor():
#include <<span
se-mark="1">paddle_api.h>
template<</span>typename
ConfigT>
std::shared_ptr<</span>PaddlePredictor>
CreatePaddlePredictor(constConfigT&);
CreatePaddlePredictor
用来根据 MobileConfig
构建预测器。
0.3:
PaddleLite学习<二>模型推理
作者: Sam(甄峰) sam_code@hotmail.com
以分类模型和目标检测模型分别演示模型推理。
0. 基础介绍:
0.1:PaddlePredictor:
PaddlePredictor是Paddle Lite的预测器,由CreatePaddlePredictor()根据MobileConfig 配置创建。
可以使用PaddlePredictor的接口获取输入Tensor,设置输入数据,执行模型预测,获取输出等。
0.1.1:创建PaddlePredictor--预测器,获取模型所有InputName.
// 设置 MobileConfig
MobileConfig config;
config.set_model_dir(FLAGS_model_dir);
// 根据 MobileConfig 创建 PaddlePredictor
std::shared_ptr<</span>PaddlePredictor> predictor=CreatePaddlePredictor<</span>MobileConfig>(config);
// 获得模型的输入和输出名称
std::vector<</span>std::string> input_names = predictor->GetInputNames();
for(inti=0;i<</span>input_names.size();i++)
{
printf("Input name[%d]: %s\n",i,input_names[i].c_str());
}
std::vector<</span>std::string> output_names=predictor->GetOutputNames();
for(inti=0; i<</span>output_names.size(); i++)
{
printf("Output name[%d]: %s\n",i,output_names[i].c_str());
}
当获取Input Names后,就可以通过predictor->GetInputByName()获取Tensor指针。
0.2:CreatePaddlePredictor():
#include <<span se-mark="1">paddle_api.h>
template<</span>typename ConfigT>
std::shared_ptr<</span>PaddlePredictor>
CreatePaddlePredictor(constConfigT&);
CreatePaddlePredictor
用来根据MobileConfig
构建预测器。0.3: