Skip to content

paddle multi threads error #75318

@HuuY

Description

@HuuY

bug描述 Describe the Bug

paddle cpu版本运行多线程时发生报错。

`import os
from time import sleep
import concurrent.futures
import traceback
from paddleocr import PaddleOCR

ocr = PaddleOCR(
ocr_version='PP-OCRv4',
text_detection_model_name="PP-OCRv4_mobile_det",
text_detection_model_dir="./PP-OCRv4_mobile_det",
text_recognition_model_name="PP-OCRv4_mobile_rec",
text_recognition_model_dir="./PP-OCRv4_mobile_rec",
use_doc_orientation_classify=False,
use_doc_unwarping=False,
use_textline_orientation=False,
device="cpu"
)

def predect_test(filepath):
result = ocr.predict(filepath)
print(f"{filepath} 预测结束")
for res in result:
res.print()

try:
thread_pool = concurrent.futures.ThreadPoolExecutor(max_workers=5)
for root, sub_dirs, files in os.walk("/data/hugo/paddle_test/images"):
for filename in files:
fixname = filename.split(".")[1]
if fixname=="jpg" or fixname=="jpeg" or fixname=="JPEG" or fixname=="JPG" or fixname=="wav" or fixname=="WAV" or fixname=="mp4" or fixname=="png":
bsname = os.path.join(root, filename)
print("提交文件预测任务:", bsname)
thread_pool.submit(predect_test,bsname)
thread_pool.shutdown(wait=True)
except Exception as e:
traceback.print_exc()`

测试情况:
在3.1.0 paddle cpu上运行报错。
在3.1.0 paddle gpu上运行报错。
在3.0.0 paddle gpu上运行正常。

paddlex 3.2.0
paddleocr 3.2.0

其他补充信息 Additional Supplementary Information

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions