workflow icon indicating copy to clipboard operation
workflow copied to clipboard

图像识别任务内存占用率一直在上升

Open WanwanLinLin opened this issue 2 years ago • 7 comments

我在使用计算任务运行ocr图像识别,程序会从命令行读取图片路径然后运行算法识别图像上的文字,每次我输入新的路径,程序的内存使用量就会一直上升,这是我的代码

int main() {
    std::string input;
    Executor executor;
    executor.init(3);    // 10个线程
    ExecQueue queue;
    queue.init();

    std::cout << "请输入图片绝对路径(输入 'exit' 以结束):\n";

    while (true) {
        // 提示用户输入
        std::cout << "> ";
        std::getline(std::cin, input); // 从标准输入读取一行

        // 处理输入
        if (input == "exit") {
            std::cout << "接收到退出指令,程序结束。" << std::endl;
            break; // 退出循环
        } else {
            WFGoTask *task = WFTaskFactory::create_go_task(&queue, &executor, ocr_task, input);
            task->start();
        }

        // 打印当前输入
        std::cout << "读取到图片: " << input << std::endl;

        // 在这里可以添加其他处理逻辑
    }

    executor.deinit();
    queue.deinit();

    return 0;
}

WanwanLinLin avatar Oct 23 '24 08:10 WanwanLinLin

加载模型的代码

PaddleOCR::Inference ocr_inter("./models/ch_PP-OCRv3_det_infer", "./models/ch_PP-OCRv3_rec_infer", "./models/ch_ppocr_mobile_v2.0_cls_infer");

void ocr_task(std::string input_image) {
    ocr_inter.ocr(input_image, output_image);
    std::cout << "图片文字提取成功!" << std::endl;
}

WanwanLinLin avatar Oct 23 '24 08:10 WanwanLinLin

你好。这个代码,除非是提交任务的速度超过了任务处理速度,否则不会出现内存持续上涨的问题。你能否用valgrind让程序正常结束之后,看一下哪里的内存没有释放呢?

Barenboim avatar Oct 23 '24 09:10 Barenboim

你好。这个代码,除非是提交任务的速度超过了任务处理速度,否则不会出现内存持续上涨的问题。你能否用valgrind让程序正常结束之后,看一下哪里的内存没有释放呢?

好我先看看

WanwanLinLin avatar Oct 23 '24 09:10 WanwanLinLin

输入的路径数量远超过Executor配置的线程数的时候,内存也会继续涨吗?都使用同一个路径,每次执行以后内存上涨的具体数值是多少,会越长越慢吗?

kedixa avatar Oct 23 '24 11:10 kedixa

输入的路径数量远超过Executor配置的线程数的时候,内存也会继续涨吗?都使用同一个路径,每次执行以后内存上涨的具体数值是多少,会越长越慢吗?

Executor配置的线程数为3时,连续输入10次相同的图片路径,每次执行后内存都有上涨(由上至下为1到10次) image

WanwanLinLin avatar Oct 23 '24 12:10 WanwanLinLin

https://github.com/PaddlePaddle/PaddleOCR/discussions/12398 看起来好像是paddleocr本身的问题,我再看一下吧

WanwanLinLin avatar Oct 23 '24 13:10 WanwanLinLin

@WanwanLinLin 你好问一下后续排查出是paddleocr是如何解决的呢? 我看在wfrest issues说当通过接口调用内存会增长,如果调用接口后在while循环里面就不会增长,如果是paddleocr内存复用的问题,调用一次新的接口会产生么什么影响导致内存复用失效么

YoooDT avatar Mar 25 '25 07:03 YoooDT