Skip to content
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

OCR把预测结果取出来很慢 #2412

Open
AnthonyF333 opened this issue Nov 7, 2024 · 3 comments
Open

OCR把预测结果取出来很慢 #2412

AnthonyF333 opened this issue Nov 7, 2024 · 3 comments
Assignees

Comments

@AnthonyF333
Copy link

描述问题

pipeline = create_pipeline(pipeline="./OCR.yaml")
image = cv2.imread('./ocr_imgs/page_1.jpg')
b = image[:, :, 0]
g = image[:, :, 1]
r = image[:, :, 2]

output = pipeline.predict(cv2.merge([r, r, r]))

start = time.perf_counter()
res = next(output)
end = time.perf_counter()
print(f"执行时间:{end - start} 秒")

运行上面的代码,predict的速度还行,挺快的,但是下面把OCR预测的结果取出来的代码res = next(output)却要20秒左右,有什么方法可以优化一下呢,还是我的使用方法有误?

环境

  1. PaddlePaddle为3.0.0-beta1、PaddleX版本号为3.0.0.beta1、Python版本号为3.10
  2. 操作系统为Linux
@TingquanGao
Copy link
Collaborator

使用方法没问题。因为predict()函数是一个generator,所以推理逻辑是在res = next(output)时执行的,造成了predict()调用很快,但是next()调用较慢。推理很慢的原因是模型在第一次推理时涉及到内存/显存分配等,后续再推理时就比较快了,所以建议先做warm up,再统计耗时。

@AnthonyF333
Copy link
Author

@TingquanGao 但是我跑了很多轮,每轮都是耗时20s左右

@TingquanGao
Copy link
Collaborator

TingquanGao commented Nov 13, 2024

很多轮是什么意思?可以贴一下代码吗?我的意思是:

pipeline = create_pipeline(pipeline="./OCR.yaml")
image = cv2.imread('./ocr_imgs/page_1.jpg')
b = image[:, :, 0]
g = image[:, :, 1]
r = image[:, :, 2]

inputs = [cv2.merge([r, r, r])] * 10
output = pipeline.predict(inputs)
res = next(output)
elapse = []
for _ in range(9):
    start = time.perf_counter()
    res = next(output)
    end = time.perf_counter()
    elapse.append(end-start)
avg_elapse = np.mean(elapse)
print(f"执行时间:{avg_elapse} 秒")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants