PaddlePaddle / PaddlePaddle/FastDeploy

fastdeploy使用openvino推理后端在ppocr-v3模型上的推理速度问题

Open
#2,504 0 comments 0 reactions 1 assignee View on GitHub

@rainyfly is already working on this.

Since Aug 8, 2024.

Dominant language
Python
Stars
3.7k
Forks
756
Avg merge
19h 28m
Merged PRs (30d)
4

Description

按照官方的部署方法搭建了环境,仅cpu运行推理,目前参数设置如下

import fastdeploy as fd
import cv2
import os

det_option = fd.RuntimeOption()
cls_option = fd.RuntimeOption()
rec_option = fd.RuntimeOption()
print(det_option)

det_option.use_openvino_backend()
cls_option.use_openvino_backend()
rec_option.use_openvino_backend()

det_model_file = os.path.join("ch_PP-OCRv3_det_infer", "inference.pdmodel")
det_params_file = os.path.join("ch_PP-OCRv3_det_infer", "inference.pdiparams")

cls_model_file = os.path.join("ch_ppocr_mobile_v2.0_cls_infer", "inference.pdmodel")
cls_params_file = os.path.join("ch_ppocr_mobile_v2.0_cls_infer", "inference.pdiparams")

rec_model_file = os.path.join("ch_PP-OCRv3_rec_infer", "inference.pdmodel")
rec_params_file = os.path.join("ch_PP-OCRv3_rec_infer", "inference.pdiparams")
rec_label_file = "ppocr_keys_v1.txt"


det_model = fd.vision.ocr.DBDetector(
    det_model_file, det_params_file, runtime_option=det_option)

cls_model = fd.vision.ocr.Classifier(
    cls_model_file, cls_params_file, runtime_option=cls_option)

rec_model = fd.vision.ocr.Recognizer(
    rec_model_file, rec_params_file, rec_label_file, runtime_option=rec_option)


#设置输入图像的最大边长。
det_model.preprocessor.max_side_len = 960
#只有置信度高于这个值的文本框才会被认为是有效的文本框
det_model.postprocessor.det_db_thresh = 0.3
#只有置信度高于这个值的文本框才会被保留下来
det_model.postprocessor.det_db_box_thresh = 0.6
#检测到的文本框会按照这个比例进行扩展,以确保完整包含整个文本区域
det_model.postprocessor.det_db_unclip_ratio = 1.5
#设置文本框得分模式
det_model.postprocessor.det_db_score_mode = "slow"
#设置是否在后处理中使用膨胀操作。膨胀操作可以扩大文本区域
det_model.postprocessor.use_dilation = False
#设置文本方向分类的阈值。这个值用于控制分类结果的置信度阈值,只有置信度高于这个值的分类结果才会被认为是有效的
cls_model.postprocessor.cls_thresh = 0.9

print(det_option)
ppocr_v3 = fd.vision.ocr.PPOCRv3(
    det_model=det_model, cls_model=cls_model, rec_model=rec_model)

ppocr_v3.cls_batch_size = 1
ppocr_v3.rec_batch_size = 6
"""
ppocr_v3.predict()返回结果
OCRResult代码定义在fastdeploy/vision/common/result.h中,用于表明图像检测和识别出来的文本框,文本框方向分类,以及文本框内的文本内容.
API:fastdeploy.vision.OCRResult, 该结果返回:
boxes(list of list(int)): 成员变量,表示单张图片检测出来的所有目标框坐标,boxes.size()表示单张图内检测出的框的个数,每个框以8个int数值依次表示框的4个坐标点,顺序为左下,右下,右上,左上.
text(list of string): 成员变量,表示多个文本框内被识别出来的文本内容,其元素个数与boxes.size()一致.
rec_scores(list of float): 成员变量,表示文本框内识别出来的文本的置信度,其元素个数与boxes.size()一致.
cls_scores(list of float): 成员变量,表示文本框的分类结果的置信度,其元素个数与boxes.size()一致.
cls_labels(list of int): 成员变量,表示文本框的方向分类类别,其元素个数与boxes.size()一致.
"""
def fd_ocr_predict(img):
    result = ppocr_v3.predict(img)
    return result.boxes,result.text,result.rec_scores


if __name__ == "__main__":
    im = cv2.imread("picture/1.png")
    print(im)
    text_boxes, recognized_texts,confidence= fd_ocr_predict(im)
    print(text_boxes)
    print(recognized_texts)
    print(confidence)
    print(ppocr_v3.predict(im))
    #vis_im = fd.vision.vis_ppocr(im, result)
    #cv2.imwrite("visualized_result.jpg", vis_im)
    #print("Visualized result save in ./visualized_result.jpg")

请问应该如何设置接口调用参数,或采取某些方法加快推理速度

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.