Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix native inference #3395

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,17 @@ void RunAnalysis(int batch_size, std::string model_dirname) {

// 2. 根据config 创建predictor,并准备输入数据,此处以全0数据为例
auto predictor = CreatePaddlePredictor(config);
int channels = 3;
int height = 224;
int width = 224;
float input[batch_size * channels * height * width] = {0};
const int channels = 3;
const int height = 224;
const int width = 224;
std::vector<float> input(batch_size * channels * height * width, 0.f);

// 3. 创建输入
// 使用了ZeroCopy接口,可以避免预测中多余的CPU copy,提升预测性能
auto input_names = predictor->GetInputNames();
auto input_t = predictor->GetInputTensor(input_names[0]);
input_t->Reshape({batch_size, channels, height, width});
input_t->copy_from_cpu(input);
input_t->copy_from_cpu(input.data());

// 4. 运行预测引擎
CHECK(predictor->ZeroCopyRun());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,17 @@ void RunAnalysis(int batch_size, std::string model_dirname) {

// 2. 根据config 创建predictor,并准备输入数据,此处以全0数据为例
auto predictor = CreatePredictor(config);
int channels = 3;
int height = 224;
int width = 224;
float input[batch_size * channels * height * width] = {0};
const int channels = 3;
const int height = 224;
const int width = 224;
std::vector<float> input(batch_size * channels * height * width, 0.f);

// 3. 创建输入
// 使用了ZeroCopy接口,可以避免预测中多余的CPU copy,提升预测性能
auto input_names = predictor->GetInputNames();
auto input_t = predictor->GetInputHandle(input_names[0]);
input_t->Reshape({batch_size, channels, height, width});
input_t->CopyFromCpu(input);
input_t->CopyFromCpu(input.data());

// 4. 运行预测引擎
CHECK(predictor->Run());
Expand Down