-
Notifications
You must be signed in to change notification settings - Fork 7.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
报告在 CPU 机器上使用 PaddleOCR CPU包, 2小时后遇到内存泄漏问题 #12150
Comments
可以提供一个最小可复现demo吗 |
同款环境下一样的问题,在本机无泄漏情况,同版本在服务器上就不停增加直至崩溃 |
@tisoz 什么样的服务器环境呀,另外可以提供一个最小可复现demo吗 |
我去改写下demo,晚点发过来 |
附带日志
|
我在windows上面内存就会一直累加,使用多进程可以解决。 |
@tisoz,感谢提供代码和描述。 |
这种实际情况下不太适合内嵌和整合代码,单客户端的时候比较麻烦 |
是的,因为要重复创建进程,处理速度也会受到影响。只能临时用一下。 |
用线程池会不会好一点 |
2024-05-22 16:22:20.476 | INFO | main::12 - 200,{"memory_usage_mb":5061.09765625,"ocr_result":[null] 截至目前已经增加到了5G,我推测可能是因为导致的问题,但也不好说,因为线程池没有webapi的功能 |
设置 PaddleOCR/tools/infer/predict_system.py Line 22 in e73eb76
https://www.paddlepaddle.org.cn/documentation/docs/zh/guides/flags/memory_cn.html |
没用 |
@GreatV 当然可以!!! 这段最小可复现demo代码的功能是持续监测 /content/img 目录中的图片,并将结果保存在 /content/log 目录中: import os
import numpy as np
from paddleocr import PaddleOCR, draw_ocr
from PIL import Image
import time
# 设置输入和输出目录
input_dir = '/content/img'
output_dir = '/content/log'
# 初始化 OCR
ocr = PaddleOCR(use_angle_cls=True, lang='en') # 运行一次以下载并加载模型到内存中
# 进入无限循环以持续进行检测
while True:
# 遍历输入目录中的图像文件
for filename in os.listdir(input_dir):
if filename.endswith('.png') or filename.endswith('.jpg') or filename.endswith('.jpeg'):
# 读取图像
img_path = os.path.join(input_dir, filename)
img = Image.open(img_path).convert('RGB')
img_np = np.array(img)
# 进行 OCR
result = ocr.ocr(img_np, cls=True)
# 提取 OCR 结果
res = result[0]
boxes = [line[0] for line in res]
txts = [line[1][0] for line in res]
scores = [line[1][1] for line in res]
# 在图像上绘制 OCR 结果
im_show = draw_ocr(img_np, boxes, txts, scores, font_path='/content/Humor-Sans.ttf')
im_show = Image.fromarray(im_show)
# 将带有 OCR 结果的图像保存到输出目录中
output_path = os.path.join(output_dir, filename)
im_show.save(output_path)
print(f"检测到 {filename} 中的文本,并将结果保存在 {output_path}")
# 在检查新图像之前暂停一段时间
time.sleep(1) |
@Copng-py 我和你的情况一样,内存一直在增加不会释放。 > OS Name: Microsoft Windows 11 Pro
OS Version: 10.0.22621 N/A Build 22621 > Python 3.11.8
paddleocr==2.7.3
paddlepaddle-gpu==2.6.1 注意:无论是paddlepaddle或者paddlepaddle-gpu,两个package在CPU运行下出现同样的异常。 |
我试了一下,把这里修改成下面的,内存应该不会一直增长。 PaddleOCR/tools/infer/predict_system.py Line 22 in e73eb76
os.environ["FLAGS_allocator_strategy"] = "naive_best_fit"
os.environ["FLAGS_eager_delete_tensor_gb"] = "0.0"
os.environ["FLAGS_memory_fraction_of_eager_deletion"] = "1.0" log: run.log
|
另外换一个推理backend,也可以避免这个问题,如onnxruntime、openvino |
|
@GreatV 套用了建议的env,内存没有释放。可以参考一下你的一些环境参数吗? > 这是我这边的信息 OS Name: Microsoft Windows 11 Pro
OS Version: 10.0.22631 N/A Build 22631
Python 3.11.8
paddleocr==2.7.3
paddlepaddle==2.6.1
FLAGS_allocator_strategy=naive_best_fit
FLAGS_eager_delete_tensor_gb=0.0
FLAGS_memory_fraction_of_eager_deletion=1.0 |
|
@jw-redpanda 修改完 |
@GreatV 我是pip安装的,譬如 |
@jw-redpanda 把main分支的最新代码拉下来 |
@GreatV 是的,使用 pip install paddleocr==2.8.0 后,内存的增加速度变慢了。 非常感谢! |
@GreatV 谢谢!我这边重新测试 paddleocr==2.8.0。大约测试了3个小时,看到内存会先上升然后下降,暂时看不到再在上升到之前的高位。 不过,这里出现了另外一个问题。测试开头的时段,OCR效能大约3秒(每张图片),到了3个小时OCR增加到9秒,之后OCR的效能没有回到之前效能。 一些信息给你参考: |
v4 导出onnx模型,然后用paddleOCR加载,use_onnx=True, use_gpu=True, 没有使用gpu推理,请问可能有什么原因吗 |
Facing the same for a long time, tried all the methods but didn't work. |
把main分支的最新代码拉下来git clone https://github.com/PaddlePaddle/PaddleOCR.git,用python setup.py install 或者 pip install -e . 安装就好了。 亲测有效! |
描述:
在使用 PaddleOCR 包2小时后,遇到了内存泄漏问题,这是在 CPU 机器上。尽管在循环中处理图像,但 OCR 的内存使用量持续增加,没有任何内存释放,最终导致内存耗尽。
环境:
PaddleOCR 版本:2.73
Python 版本:3.11.8
操作系统:Window 10
paddlepaddle==2.6.1 -i https://pypi.tuna.tsinghua.edu.cn/simpleol
paddleocr==2.73
hanzidentifier==1.1.0
pillow==10.3.0
fastapi[all]==0.110.3
期望行为:
OCR 处理期间内存使用量应保持稳定或逐渐增加,但应在处理每个图像后释放,以防止内存耗尽。
The text was updated successfully, but these errors were encountered: