PaddleX icon indicating copy to clipboard operation
PaddleX copied to clipboard

关于多张图片同时推理的问题

Open aiwenzhu opened this issue 4 years ago • 5 comments
trafficstars

在用batch_infer部署推理的时候发现调大batch size同时推理多张图片并不会缩短整体推理时间,如何才能像pytorch那样调大batch size使得在单个GPU上同时推理多张图片达到缩短推理时间的目的

aiwenzhu avatar Sep 17 '21 06:09 aiwenzhu

请问是用的C++的batch_infer的demo? 如果是c++推理:

  1. 可以修改 batch_ifner.cpp的第81行 model->Predict(im_vec, &results) , 在里边多传入 一个thread_num参数, 提高前后处理的并行化
  2. 可以使用multi_gpu_model_infer.cpp 的demo。 单卡情况下gpu_id参数可以传入 0,0 这样会启动2个线程处理batch的数据(注意不能设置太多线程, 太多会导致显存爆掉+显存利用率不高, 看模型大小和batch大小设置在2~8最佳)

heliqi avatar Sep 17 '21 06:09 heliqi

你好,谢谢回复,我用的是c++的batch infer 的demo,按官方教程转成dll调用的,你提到的第一种方式算是cpu的并行吗,第二种方式是对gpu的并行,我的理解对吗😅

---原始邮件--- 发件人: @.> 发送时间: 2021年9月17日(周五) 下午2:55 收件人: @.>; 抄送: @.@.>; 主题: Re: [PaddlePaddle/PaddleX] 关于多张图片同时推理的问题 (#1149)

请问是用的C++的batch_infer的demo? 如果是c++推理:

可以修改 batch_ifner.cpp的第81行 model->Predict(im_vec, &results) , 在里边多传入 一个thread_num参数, 提高前后处理的并行化

可以使用multi_gpu_model_infer.cpp 的demo。 单卡情况下gpu_id参数可以传入 0,0 这样会启动2个线程处理batch的数据(注意不能设置太多线程, 太多会导致显存爆掉+显存利用率不高, 看模型大小和batch大小设置在2~8最佳)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.

aiwenzhu avatar Sep 17 '21 07:09 aiwenzhu

查不多。 第一种是cpu层面对前后处理进行并行加速, gpu层面交给引擎进行batch加速 ; 第二种是 前后处理+引擎推理整个推理逻辑进行并行

heliqi avatar Sep 17 '21 07:09 heliqi

hi 😅你好,经过测试发现,更改batch size和thread num时间几乎没变化

---原始邮件--- 发件人: @.> 发送时间: 2021年9月17日(周五) 下午3:13 收件人: @.>; 抄送: @.@.>; 主题: Re: [PaddlePaddle/PaddleX] 关于多张图片同时推理的问题 (#1149)

查不多。 第一种是cpu层面对前后处理进行并行加速, gpu层面交给引擎进行batch加速 ; 第二种是 前后处理+引擎推理整个推理逻辑进行并行

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.

aiwenzhu avatar Sep 18 '21 08:09 aiwenzhu

你好,多张图像进行批处理时,你遇见过预测结果全部为容器内的第一张图像的预测结果吗;paddlex版本为2.0

kuaiyouxiaozi avatar Jan 11 '22 08:01 kuaiyouxiaozi