PaddleLite学习<二>模型推理

2023-11-22 11:58:24
标签: paddle

作者: 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>PaddlePredictorpredictor=CreatePaddlePredictor<</span>MobileConfig>(config);

// 获得模型的输入和输出名称

std::vector<</span>std::stringinput_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::stringoutput_names=predictor->GetOutputNames();

for(inti=0i<</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:

 

阅读(0) 收藏(0) 转载(0) 举报/Report
相关阅读

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有