NPU资源释放问题
-
需要高频次通过NPU进行YOLO检测目标,请教如何能避免多次读入模型和多次申请内存?——就是要快速连续多次调用NPU,要将初始化的部分、预测部分和资源释放部分分开,希望高手指教,感谢!
-
请教:我需要连续高频次调用目标检测,我的思路是先进行一个初始化NPU_Yolo_init和一个预处理Detect_pr,然后调用Detect(),会造成内存不停疯长,一会就撑满了。不知道问题在哪里。劳烦大神指教。
//初始化,执行一次
int NPU_Yolo::NPU_Yolo_init(string moduleFile)
{
/* Initialize vip lite /
status = vip_init(80 * 1024 * 1024);
_CHECK_STATUS(status, final);
printf("Initialize vip lite success\n");
/ Initialize network items /
status = vnn_InitNetworkItem(&network_items,moduleFile);
_CHECK_STATUS(status, final);
printf("Initialize network items success\n");
/ Create the neural network */
status = vnn_CreateNeuralNetwork(network_items);
_CHECK_STATUS(status, final);
printf("Create the neural network success\n");
final:
return status;
}//作为预处理,执行一次
void NPU_Yolo::Detect_pre(cv::Mat frame)
{
int sizeInt=640;//v5 640 v3 416
int w=sizeInt;
float h=frame.rowssizeInt/frame.cols;
cv::resize(frame,frame,cv::Size(sizeInt,int(h)));
Mat mat(Size(sizeInt,sizeInt),CV_8UC3,Scalar(0));
Mat roi=mat(Rect(0,0,frame.cols,frame.rows));
Mat mask=Mat(roi.rows,roi.cols,roi.depth(),Scalar(1));
frame.copyTo(roi,mask);
/ Pre process the input/output data /
status = vnn_PreProcessNeuralNetwork(network_items,frame);
_CHECK_STATUS(status, final);
printf("Pre process the input/output data success\n");
/ Run the neural network */
status = vnn_RunNeuralNetwork(network_items);
_CHECK_STATUS(status, final);
printf("Run the neural network success\n");final:
mat.release();}
// 高频次调用进行目标检测
vector<Object> NPU_Yolo::Detect(cv::Mat frame)
{
cout<<" *** 1 "<<endl;
int sizeInt=640;//v5 640 v3 416
int w=sizeInt;
float h=frame.rows*sizeInt/frame.cols;
cv::resize(frame,frame,cv::Size(sizeInt,int(h)));
Mat mat(Size(sizeInt,sizeInt),CV_8UC3,Scalar(0));
Mat roi=mat(Rect(0,0,frame.cols,frame.rows));
cout<<" *** 2 "<<endl;
Mat mask=Mat(roi.rows,roi.cols,roi.depth(),Scalar(1));
frame.copyTo(roi,mask);
std::vector<Object> objects= vnn_PostProcessNeuralNetwork(network_items,mat);
cout<<" *** 3 "<<endl;
_CHECK_STATUS(status, final);
printf("Post process output data success\n");
final:
mat.release();
cout<<" *** 4 "<<endl;
} -
问题得到解决了吗
-
vnn_PreProcessNeuralNetwork(network_items,frame) 会申请内存吧,要么释放,要么就调用一次,然后改变输入指针指向的数据
-
This post is deleted!
Copyright © 2023 深圳全志在线有限公司 粤ICP备2021084185号 粤公网安备44030502007680号