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

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

Open
uniqlo1 opened this issue Aug 8, 2024 · 0 comments
Assignees

Comments

@uniqlo1
Copy link

uniqlo1 commented Aug 8, 2024

按照官方的部署方法搭建了环境,仅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")

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

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

2 participants