FastDeploy yolov5 batch推理
温馨提示:根据社区不完全统计,按照模板提问,可以加快回复和解决问题的速度
环境
- 【FastDeploy版本】: fastdeploy-linux-develop
- 【系统平台】: Linux x64(Ubuntu 22.04)
- 【硬件】: 说明具体硬件型号,如 Nvidia GPU 3060TI, CUDA 11.5 CUDNN 8.3
- 【编译语言】: C++ 10.5
问题日志及出现问题的操作流程
问题:当使用fastdeploy中fastdeploy::vision::detection::YOLOv5 进行batch推理,举例:两个线程调用 每个线程传一个batch的数据 现象:不加锁的话 会导致结果错乱 我在外部调用加锁 那和串行执行没什么区别,YOLOv5Postprocessor::Run在这内部局部加锁会不会更好些
std::vectorcv::Mat img_batch ; std::vectorfastdeploy::vision::DetectionResult results; BatchPredict(img_batch, &results) 我查看源码BatchPredict内部 bool YOLOv5::BatchPredict(const std::vectorcv::Mat& images, std::vector<DetectionResult>* results) { std::vector<std::map<std::string, std::array<float, 2>>> ims_info; std::vector<FDMat> fd_images = WrapMat(images);
if (!preprocessor_.Run(&fd_images, &reused_input_tensors_, &ims_info)) { FDERROR << "Failed to preprocess the input image." << std::endl; return false; }
reused_input_tensors_[0].name = InputInfoOfRuntime(0).name; if (!Infer(reused_input_tensors_, &reused_output_tensors_)) { FDERROR << "Failed to inference by runtime." << std::endl; return false; }
if (!postprocessor_.Run(reused_output_tensors_, results, ims_info)) { FDERROR << "Failed to postprocess the inference results by runtime." << std::endl; return false; }
return true; }
这个接口可能没有考虑多并发的情况,不过一般batch推理应该不需要多并发吧