Navigation

    全志在线开发者论坛

    • Register
    • Login
    • Search
    • Categories
    • Tags
    • 在线文档
    • 社区主页

    NPU资源释放问题

    V Series
    3
    5
    2312
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S
      sunxi LV 5 last edited by

      需要高频次通过NPU进行YOLO检测目标,请教如何能避免多次读入模型和多次申请内存?——就是要快速连续多次调用NPU,要将初始化的部分、预测部分和资源释放部分分开,希望高手指教,感谢!

      1 Reply Last reply Reply Quote Share 0
      • S
        sunxi LV 5 last edited by

        请教:我需要连续高频次调用目标检测,我的思路是先进行一个初始化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;
        }

        L 1 Reply Last reply Reply Quote Share 0
        • L
          llkkzz LV 2 last edited by

          问题得到解决了吗

          1 Reply Last reply Reply Quote Share 0
          • L
            llkkzz LV 2 @sunxi last edited by

            vnn_PreProcessNeuralNetwork(network_items,frame) 会申请内存吧,要么释放,要么就调用一次,然后改变输入指针指向的数据

            1 Reply Last reply Reply Quote Share 0
            • Z
              zheng1 LV 3 last edited by zheng1

              This post is deleted!
              1 Reply Last reply Reply Quote Share 0
              • 1 / 1
              • First post
                Last post

              Copyright © 2024 深圳全志在线有限公司 粤ICP备2021084185号 粤公网安备44030502007680号

              行为准则 | 用户协议 | 隐私权政策