跳转至

参数介绍

config.yaml的生成

rapidocr config

default_rapidocr.yaml常用参数介绍

Global

该部分为全局配置。

Global:
    lang_det: "ch_mobile" # ch_server
    lang_rec: "ch_mobile"
    text_score: 0.5

    use_det: true
    use_cls: true
    use_rec: true

    min_height: 30
    width_height_ratio: 8
    max_side_len: 2000
    min_side_len: 30

    return_word_box: false

    with_onnx: false
    with_openvino: false
    with_paddle: false
    with_torch: false

    font_path: null

lang_det (str): 文本检测使用模型。默认值是ch_mobile,意思是使用中文轻量模型。取值为[ch_mobile, ch_server]

lang_rec (str): 文本识别使用模型。默认值是ch_mobile, 意思是使用中文轻量模型。取值为[ch_mobile, ch_server]

text_score (float): 文本识别结果置信度,值越大,把握越大。取值范围:[0, 1], 默认值是0.5。

use_det (bool): 是否使用文本检测。默认为True

use_cls (bool): 是否使用文本行方向分类。默认为True

use_rec (bool): 是否使用文本行识别。默认为True

min_height (int) : 图像最小高度(单位是像素),低于这个值,会跳过文本检测阶段,直接进行后续识别。默认值为30。min_height是用来过滤只有一行文本的图像(如下图),这类图像不会进入文本检测模块,直接进入后续过程。

width_height_ratio (float): 如果输入图像的宽高比大于width_height_ratio,则会跳过文本检测,直接进行后续识别,取值为-1时:不用这个参数. 默认值为8。

max_side_len (int): 如果输入图像的最大边大于max_side_len,则会按宽高比,将最大边缩放到max_side_len。默认为2000px。

min_side_len (int): 如果输入图像的最小边小于min_side_len,则会按宽高比,将最小边缩放到min_side_len。默认为30px。

return_word_box (bool): 是否返回文字的单字坐标。默认为False。在rapidocr_onnxruntime==1.4.0中,汉字会返回单字坐标,英语返回单词坐标。在rapidocr_onnxruntime>=1.4.1中,汉字返回单字坐标,英语返回单字母坐标。

with_onnx (bool): 是否使用ONNXRuntime推理引擎。默认为False。注意:在所有推理引擎都为False时,会默认采用ONNXRuntime。

with_openvino (bool): 是否使用OpenVINO推理引擎,默认为False

with_paddle (bool): 是否使用PaddlePaddle推理引擎,默认为False

with_torch (bool): 是否使用PyTorch推理引擎,默认为False

font_path (str): 字体文件路径。如不提供,程序会自动下载预置的字体文件模型到本地。默认为null

EngineConfig

该部分为相关推理引擎的配置文件,大家可按需配置。该部分后面可能会增删部分关键字,如果有需求,可以在文档下面评论区指出。

EngineConfig:
    onnxruntime:
        intra_op_num_threads: -1
        inter_op_num_threads: -1
        use_cuda: false
        use_dml: false

    openvino:
        inference_num_threads: -1

    paddle:
        cpu_math_library_num_threads: -1
        use_cuda: false
        gpu_id: 0
        gpu_mem: 500

    torch:
        use_cuda: false
        gpu_id: 0

ONNXRuntime Python API 参见:Python API

OpenVINO Python API 参见:OpenVINO Python API

PaddlePaddle API 参见:API 文档

PyTorch API 参见:PyTorch documentation

Det

Det:
    model_path: null
    model_dir: null

    limit_side_len: 736
    limit_type: min
    std: [ 0.5, 0.5, 0.5 ]
    mean: [ 0.5, 0.5, 0.5 ]

    thresh: 0.3
    box_thresh: 0.5
    max_candidates: 1000
    unclip_ratio: 1.6
    use_dilation: true
    score_mode: fast

model_path (str): 文本检测模型路径,仅限于基于PaddleOCR训练所得DBNet文本检测模型。默认值为null

limit_side_len (float): 限制图像边的长度的像素值。默认值为736。

limit_type (str): 限制图像的最小边长度还是最大边为limit_side_len
示例解释:当limit_type=minlimit_side_len=736时,图像最小边小于736时,
会将图像最小边拉伸到736,另一边则按图像原始比例等比缩放。 取值范围为:[min, max],默认值为min

thresh (float): 图像中文字部分和背景部分分割阈值。值越大,文字部分会越小。取值范围:[0, 1],默认值为0.3。

box_thresh (float): 文本检测所得框是否保留的阈值,值越大,召回率越低。取值范围:[0, 1],默认值为0.5。

max_candidates (int): 最大候选框数目。默认是1000。

unclip_ratio (float): 控制文本检测框的大小,值越大,检测框整体越大。取值范围:[1.6, 2.0],默认值为1.6。

use_dilation (bool): 是否使用膨胀。默认为true。该参数用于将检测到的文本区域做形态学的膨胀处理。

score_mode (str): 计算文本框得分的方式。取值范围为:[slow, fast],默认值为fast

Cls

1
2
3
4
5
6
7
8
Cls:
    model_path: null
    model_dir: null

    cls_image_shape: [3, 48, 192]
    cls_batch_num: 6
    cls_thresh: 0.9
    label_list: ['0', '180']

model_path (str): 文本行方向分类模型路径,仅限于PaddleOCR训练所得二分类分类模型。默认值为None

model_dir (str): 占位参数,暂时无效。

cls_image_shape (List[int]): 输入方向分类模型的图像Shape(CHW)。默认值为[3, 48, 192]`。

cls_batch_num (int): 批次推理的batch大小,一般采用默认值即可,太大并没有明显提速,效果还可能会差。默认值为6。

cls_thresh (float): 方向分类结果的置信度。取值范围:[0, 1],默认值为0.9。

label_list (List[str]): 方向分类的标签,0°或者180°,该参数不能动。默认值为["0", "180"]

Rec

1
2
3
4
5
6
7
Rec:
    model_path: null
    model_dir: null

    rec_keys_path: null
    rec_img_shape: [3, 48, 320]
    rec_batch_num: 6

model_path (str): 文本识别模型路径,仅限于PaddleOCR训练文本识别模型。默认值为None

model_dir (str): 模型存放路径或目录。如果是PaddlePaddle,该参数则对应模型存在目录。其余推理引擎对应模型地址。

rec_keys_path (str): 文本识别模型对应的字典文件,默认为None

rec_img_shape (List[int]): 输入文本识别模型的图像Shape(CHW)。默认值为[3, 48, 320]

rec_batch_num (int): 批次推理的batch大小,一般采用默认值即可,太大并没有明显提速,效果还可能会差。默认值为6。

评论