We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
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秒左右,有什么方法可以优化一下呢,还是我的使用方法有误?
The text was updated successfully, but these errors were encountered:
使用方法没问题。因为predict()函数是一个generator,所以推理逻辑是在res = next(output)时执行的,造成了predict()调用很快,但是next()调用较慢。推理很慢的原因是模型在第一次推理时涉及到内存/显存分配等,后续再推理时就比较快了,所以建议先做warm up,再统计耗时。
Sorry, something went wrong.
@TingquanGao 但是我跑了很多轮,每轮都是耗时20s左右
很多轮是什么意思?可以贴一下代码吗?我的意思是:
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} 秒")
TingquanGao
No branches or pull requests
描述问题
运行上面的代码,predict的速度还行,挺快的,但是下面把OCR预测的结果取出来的代码res = next(output)却要20秒左右,有什么方法可以优化一下呢,还是我的使用方法有误?
环境
The text was updated successfully, but these errors were encountered: