Closed spiderpigpig closed 2 years ago
cpu模式,使用c++部署实例分割,推理多张图片时,内存涨幅与推理图片数量正相关,输入三五张图片是可以正常推理的,但输入太多图片(如十张)时会因为内存不够而退出
c++部署方式
std::vector<std::string> imgs_path; // 获取文件夹下所有的图片路径 FindFiles(std::string(current_path) + "/images/", imgs_path);
if (!model->PaddleEngineInit(engine_config)) return -2;
std::vector imgs; for (int i = 0; i < imgs_path.size(); i++) { std::cout << imgs_path[i] << std::endl; // prepare data imgs.push_back(std::move(cv::imread(imgs_path[i]))); //imgs.push_back(std::move(cv::imread(FLAGS_image))); // predict
} std::vector results; if (!model->Predict(imgs, &results, 1)) return -3; for (int i = 0; i < imgs_path.size(); i++) { cv::Mat vis_seg; if (!Visualize(imgs[i], *(results[i].seg_result), &vis_seg, 2)) { continue; } std::string output = outputdir + filename(imgs_path[i]) + ".jpg"; cv::imwrite(output, vis_seg); } delete model;
看您提供的模型是Deeplabv3p?该模型本身较大,同时推理的图像数量过大导致内存不足,这个符合预期。建议您在机器允许的条件下,选择合适的批量数量。
Deeplabv3p
Checklist:
描述问题
cpu模式,使用c++部署实例分割,推理多张图片时,内存涨幅与推理图片数量正相关,输入三五张图片是可以正常推理的,但输入太多图片(如十张)时会因为内存不够而退出
复现
c++部署方式
if (!model->PaddleEngineInit(engine_config)) return -2;
std::vector imgs;
for (int i = 0; i < imgs_path.size(); i++)
{
std::cout << imgs_path[i] << std::endl;
// prepare data
imgs.push_back(std::move(cv::imread(imgs_path[i])));
//imgs.push_back(std::move(cv::imread(FLAGS_image))); // predict
} std::vector results;
if (!model->Predict(imgs, &results, 1))
return -3;
for (int i = 0; i < imgs_path.size(); i++)
{
cv::Mat vis_seg;
if (!Visualize(imgs[i], *(results[i].seg_result), &vis_seg, 2))
{
continue;
}
std::string output = outputdir + filename(imgs_path[i]) + ".jpg";
cv::imwrite(output, vis_seg);
}
delete model;
环境