-
Notifications
You must be signed in to change notification settings - Fork 162
Open
Description
首先我下载了官方所给的resunet模型的参数和模型文件:inference.pdiparams和inference.pdiparams.info和inference.pdmodel,然后调用了官方的例程,一直在“auto input_names = predictor->GetInputNames();”这一步代码出错,显示内存已被破坏,后来经过调试发现config中根本就没读取到,
代码如下: // 字符串 prog_file 为 Combine 模型文件所在路径
std::string prog_file = "./resunet/inference.pdmodel";
// 字符串 params_file 为 Combine 模型参数文件所在路径
std::string params_file = "./resunet/inference.pdiparams";
// 设置推理模型路径,即为本小节第2步中下载的模型
// 根据模型文件和参数文件构造 Config 对象
paddle_infer::Config config(prog_file, params_file);
// 不启用 GPU 和 MKLDNN 推理
config.DisableGpu();
config.EnableMKLDNN();
// 开启 内存/显存 复用
config.EnableMemoryOptim();
auto predictor = paddle_infer::CreatePredictor(config);
// 获取输入 Tensor
auto input_names = predictor->GetInputNames();
auto input_tensor = predictor->GetInputHandle(input_names[0]);
// 设置输入 Tensor 的维度信息
std::vector<int> INPUT_SHAPE = { 1, 3, 224, 224 };
input_tensor->Reshape(INPUT_SHAPE);
// 准备输入数据
int input_size = 1 * 3 * 224 * 224;
std::vector<float> input_data(input_size, 1);
// 设置输入 Tensor 数据
input_tensor->CopyFromCpu(input_data.data());
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
