44 - toc
55---
66
7- ### ` config.yaml ` 的生成
7+ ### ` config.yaml ` 的生成
88
99``` bash linenums="1"
1010rapidocr config
1111```
1212
13- ### ` default_rapidocr.yaml ` 常用参数介绍
13+ ### ` default_rapidocr.yaml ` 常用参数介绍
1414
1515#### Global
1616
@@ -38,45 +38,47 @@ Global:
3838
3939` text_score (float)`: 文本识别结果置信度,值越大,把握越大。取值范围:`[0, 1]`, 默认值是0.5。
4040
41- `use_det (bool)` : 是否使用文本检测。默认为`True`。
41+ `use_det (bool)` : 是否使用文本检测。默认为 `True`。
4242
43- `use_cls (bool)` : 是否使用文本行方向分类。默认为`True`。
43+ `use_cls (bool)` : 是否使用文本行方向分类。默认为 `True`。
4444
45- `use_rec (bool)` : 是否使用文本行识别。默认为`True`。
45+ `use_rec (bool)` : 是否使用文本行识别。默认为 `True`。
4646
47- `min_height (int)` : 图像最小高度(单位是像素),低于这个值,会跳过文本检测阶段,直接进行后续识别。默认值为30。`min_height`是用来过滤只有一行文本的图像(如下图),这类图像不会进入文本检测模块,直接进入后续过程。
47+ > ⚠️注意:如果配置文件和调用时候同时声明 `use_det | use_cls | use_rec` 这三个参数,调用时参数会覆盖配置文件参数。
48+
49+ `min_height (int)` : 图像最小高度(单位是像素),低于这个值,会跳过文本检测阶段,直接进行后续识别。默认值为30。 `min_height` 是用来过滤只有一行文本的图像(如下图),这类图像不会进入文本检测模块,直接进入后续过程。
4850
4951
5052
51- `width_height_ratio (float)` : 如果输入图像的宽高比大于`width_height_ratio`,则会跳过文本检测,直接进行后续识别,取值为-1时:不用这个参数. 默认值为8。
53+ `width_height_ratio (float)` : 如果输入图像的宽高比大于 `width_height_ratio`,则会跳过文本检测,直接进行后续识别,取值为-1时:不用这个参数. 默认值为8。
5254
53- `max_side_len (int)` : 如果输入图像的最大边大于`max_side_len`,则会按宽高比,将最大边缩放到`max_side_len`。默认为2000px。
55+ `max_side_len (int)` : 如果输入图像的最大边大于 `max_side_len`,则会按宽高比,将最大边缩放到 `max_side_len`。默认为2000px。
5456
55- `min_side_len (int)` : 如果输入图像的最小边小于`min_side_len`,则会按宽高比,将最小边缩放到`min_side_len`。默认为30px。
57+ `min_side_len (int)` : 如果输入图像的最小边小于 `min_side_len`,则会按宽高比,将最小边缩放到 `min_side_len`。默认为30px。
5658
57- `return_word_box (bool)` : 是否返回文字的单字坐标。默认为`False`。
59+ `return_word_box (bool)` : 是否返回文字的单字坐标。默认为 `False`。
5860
59- > 在`rapidocr>=2.1.0`中,纯中文、中英文混合返回单字坐标,纯英文返回单词坐标。
61+ > 在 `rapidocr>=2.1.0` 中,纯中文、中英文混合返回单字坐标,纯英文返回单词坐标。
6062
61- > 在`rapidocr<=2.0.7`中,纯中文、中英文混合和纯英文均返回单字坐标。
63+ > 在 `rapidocr<=2.0.7` 中,纯中文、中英文混合和纯英文均返回单字坐标。
6264
63- > 在`rapidocr_onnxruntime>=1.4.1`中,汉字返回单字坐标,英语返回单字母坐标。
65+ > 在 `rapidocr_onnxruntime>=1.4.1` 中,汉字返回单字坐标,英语返回单字母坐标。
6466
65- > 在`rapidocr_onnxruntime==1.4.0`中,汉字会返回单字坐标,英语返回单词坐标。
67+ > 在 `rapidocr_onnxruntime==1.4.0` 中,汉字会返回单字坐标,英语返回单词坐标。
6668
67- `return_single_char_box (bool)` : 文本内容只有英文和数字情况下,是否返回单字坐标。默认为`False`。
69+ `return_single_char_box (bool)` : 文本内容只有英文和数字情况下,是否返回单字坐标。默认为 `False`。
6870
69- > 在`rapidocr>=3.1.0`中添加该参数,该参数只有在`return_word_box=True`时,才能生效。
71+ > 在 `rapidocr>=3.1.0` 中添加该参数,该参数只有在 `return_word_box=True` 时,才能生效。
7072
7173` ` ` python
7274result = engine(img_url, return_word_box=True, return_single_char_box=True)
7375` ` `
7476
75- `font_path (str)` : 字体文件路径。如不提供,程序会自动下载预置的字体文件模型到本地。默认为`null`。
77+ `font_path (str)` : 字体文件路径。如不提供,程序会自动下载预置的字体文件模型到本地。默认为 `null`。
7678
77- `log_level (str)` : 日志级别设置。可选择的有`debug / info / warning / error / critical`,默认为`info`,会打印加载模型等日志。如果设置`critical`,则不会打印任何日志。
79+ `log_level (str)` : 日志级别设置。可选择的有 `debug / info / warning / error / critical`,默认为 `info`,会打印加载模型等日志。如果设置 `critical`,则不会打印任何日志。
7880
79- > 在`rapidocr>=3.4.0`中,才添加此参数。
81+ > 在 `rapidocr>=3.4.0` 中,才添加此参数。
8082
8183# ### EngineConfig
8284
@@ -115,6 +117,18 @@ EngineConfig:
115117 optypelist_for_implmode: "Gelu"
116118 enable_cann_graph: true
117119
120+ # rapidocr >= 3.7.0
121+ use_coreml: false
122+ coreml_ep_cfg:
123+ ModelFormat: "MLProgram"
124+ MLComputeUnits: "ALL"
125+ RequireStaticInputShapes: 0
126+ EnableOnSubgraphs: 0
127+ SpecializationStrategy: "FastPrediction"
128+ ProfileComputePlan: 0
129+ AllowLowPrecisionAccumulationOnGPU: 0
130+ ModelCacheDirectory: "/tmp/RapidOCR"
131+
118132 openvino:
119133 inference_num_threads: -1
120134 performance_hint: null
@@ -152,6 +166,31 @@ EngineConfig:
152166 npu_ep_cfg:
153167 device_id: 0
154168
169+ # rapidocr >= 3.7.0
170+ tensorrt:
171+ device_id: 0
172+ use_fp16: true
173+ use_int8: false
174+ workspace_size: 1073741824 # 1GB = 1 << 30
175+
176+ cache_dir: null
177+ force_rebuild: false
178+
179+ det_profile:
180+ min_shape: [1, 3, 32, 32]
181+ opt_shape: [1, 3, 736, 736]
182+ max_shape: [1, 3, 2048, 2048]
183+
184+ rec_profile:
185+ min_shape: [1, 3, 48, 32]
186+ opt_shape: [6, 3, 48, 320]
187+ max_shape: [6, 3, 48, 2048]
188+
189+ cls_profile:
190+ min_shape: [1, 3, 48, 32]
191+ opt_shape: [6, 3, 48, 192]
192+ max_shape: [6, 3, 48, 192]
193+
155194 mnn: {} # rapidocr>=3.6.0
156195` ` `
157196
@@ -164,13 +203,14 @@ EngineConfig:
164203- PaddlePaddle API 参见:[API 文档](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/index_cn.html)
165204- PyTorch API 参见:[PyTorch documentation](https://docs.pytorch.org/docs/stable/index.html)
166205- MNN API 参见:[MNN](https://mnn-docs.readthedocs.io/en/latest/index.html)
206+ - TensorRT API 参见:[TensorRT Python API](https://docs.nvidia.com/deeplearning/tensorrt/latest/_static/python-api/index.html)
167207
168208以下三部分前4个参数基本类似,对应关系如下表,具体请参见[模型列表](../../model_list.md)文档:
169209
170210| YAML 参数 | 对应枚举类 | 可用枚举值(示例) |导入方式 | 备注 |
171211|-----------------|------------------|------------------|-------------------|-------------------------------------|
172- | `engine_type` | `EngineType` | `ONNXRUNTIME`(onnxruntime)<br>`OPENVINO`(openvino)<br>`PADDLE`(paddle)<br>`TORCH`(torch)<br>`MNN` (mnn)(`rapidocr>=3.6.0`) | `from rapidocr import EngineType`|推理引擎类型 |
173- | `lang_type` | `LangDet`<br> `LangCls`<br> `LangRec` | **检测(Det)**:`CH`/`EN`/`MULTI`<br>**分类(Cls)**:`CH`<br>**识别(Rec)**:`CH`/`CH_DOC`/`EN`/`ARABIC`/... |`from rapidocr import LangDet`<br/> `from rapidocr import LangCls` <br/>`from rapidocr import LangRec`| 根据OCR处理阶段选择不同枚举值 |
212+ | `engine_type` | `EngineType` | `ONNXRUNTIME`(onnxruntime)<br>`OPENVINO`(openvino)<br>`PADDLE`(paddle)<br>`TORCH`(torch)<br>`MNN` (mnn)(`rapidocr>=3.6.0`)<br>`TENSORRT`(`rapidocr>=3.7.0`) | `from rapidocr import EngineType`|推理引擎类型 |
213+ | `lang_type` | `LangDet`<br> `LangCls`<br> `LangRec` | **检测(Det)**:`CH`/`EN`/`MULTI`<br>**分类(Cls)**:`CH`<br>**识别(Rec)**:`CH`/`CH_DOC`/`EN`/`ARABIC`/... |`from rapidocr import LangDet`<br/> `from rapidocr import LangCls` <br/>`from rapidocr import LangRec`| 根据 OCR 处理阶段选择不同枚举值 |
174214| `model_type` | `ModelType` | `MOBILE`(mobile)<br>`SERVER`(server) |`from rapidocr import ModelType`| 模型大小与性能级别 |
175215| `ocr_version` | `OCRVersion` | `PPOCRV4`(PP-OCRv4)<br>`PPOCRV5`(PP-OCRv5) |`from rapidocr import OCRVersion`| 模型版本 |
176216
@@ -201,21 +241,21 @@ Det:
201241 score_mode: fast
202242` ` `
203243
204- `engine_type (str)` : 选定推理引擎。支持`onnxruntime`、`openvino`、`paddle`和 `torch`四个值。默认为`onnxruntime`。
244+ `engine_type (str)` : 选定推理引擎。支持 `onnxruntime`、`openvino`、`paddle` 和 `torch` 四个值。默认为 `onnxruntime`。
205245
206- `lang_type (str)` : 支持检测的语种类型。这里指的是`LangDet`,具体支持`ch`、`en`和 `multi`3个值。 `ch`可以识别中文和中英文混合文本检测。`en`支持英文文字检测。`multi`支持多语言文本检测。默认为`ch`。详细参见:[docs](https://rapidai.github.io/RapidOCRDocs/main/model_list/#_1)
246+ `lang_type (str)` : 支持检测的语种类型。这里指的是 `LangDet`,具体支持 `ch`、`en` 和 `multi` 3 个值。 `ch` 可以识别中文和中英文混合文本检测。 `en` 支持英文文字检测。 `multi` 支持多语言文本检测。默认为 `ch`。详细参见:[docs](https://rapidai.github.io/RapidOCRDocs/main/model_list/#_1)
207247
208- `model_type (str)` : 模型量级选择,支持`mobile`(轻量型)和`server`(服务型)。默认为`mobile`。
248+ `model_type (str)` : 模型量级选择,支持 `mobile`(轻量型)和 `server`(服务型)。默认为 `mobile`。
209249
210- `ocr_version (str)` : ocr版本的选择 ,支持`PP-OCRv4`和 `PP-OCRv5`,默认为`PP-OCRv4`。
250+ `ocr_version (str)` : OCR 版本的选择 ,支持 `PP-OCRv4` 和 `PP-OCRv5`,默认为 `PP-OCRv4`。
211251
212- `model_path (str)` : 文本检测模型路径,仅限于基于PaddleOCR训练所得DBNet文本检测模型 。默认值为`null`。
252+ `model_path (str)` : 文本检测模型路径,仅限于基于 PaddleOCR 训练所得 DBNet 文本检测模型 。默认值为 `null`。
213253
214- `model_dir (str)` : 模型存放路径或目录。如果是PaddlePaddle ,该参数则对应模型存在目录。其余推理引擎请使用`model_path`参数。
254+ `model_dir (str)` : 模型存放路径或目录。如果是 PaddlePaddle ,该参数则对应模型存在目录。其余推理引擎请使用 `model_path` 参数。
215255
216256`limit_side_len (float)` : 限制图像边的长度的像素值。默认值为736。
217257
218- `limit_type (str)` : 限制图像的最小边长度还是最大边为`limit_side_len`。 示例解释:当`limit_type=min`和 `limit_side_len=736`时,图像最小边小于736时,会将图像最小边拉伸到736,另一边则按图像原始比例等比缩放。 取值范围为:`[min, max]`,默认值为`min`。
258+ `limit_type (str)` : 限制图像的最小边长度还是最大边为 `limit_side_len`。 示例解释:当 `limit_type=min` 和 `limit_side_len=736` 时,图像最小边小于736时,会将图像最小边拉伸到736,另一边则按图像原始比例等比缩放。 取值范围为:`[min, max]`,默认值为 `min`。
219259
220260`thresh (float)` : 图像中文字部分和背景部分分割阈值。值越大,文字部分会越小。取值范围:`[0, 1]`,默认值为0.3。
221261
225265
226266`unclip_ratio (float)` : 控制文本检测框的大小,值越大,检测框整体越大。取值范围:`[1.6, 2.0]`,默认值为1.6。
227267
228- `use_dilation (bool)` : 是否使用膨胀。默认为`true`。该参数用于将检测到的文本区域做形态学的膨胀处理。
268+ `use_dilation (bool)` : 是否使用膨胀。默认为 `true`。该参数用于将检测到的文本区域做形态学的膨胀处理。
229269
230- `score_mode (str)` : 计算文本框得分的方式。取值范围为:`[slow, fast]`,默认值为`fast`。
270+ `score_mode (str)` : 计算文本框得分的方式。取值范围为:`[slow, fast]`,默认值为 `fast`。
231271
232272# ### Cls
233273
@@ -249,25 +289,25 @@ Cls:
249289 label_list: ["0", "180"]
250290` ` `
251291
252- `engine_type (str)` : 同Det部分介绍 。
292+ `engine_type (str)` : 同 Det 部分介绍 。
253293
254- `lang_type (str)` : 支持检测的语种类型。这里指的是`LangCls`,目前只有一种选项:`ch`。默认为`ch`。
294+ `lang_type (str)` : 支持检测的语种类型。这里指的是 `LangCls`,目前只有一种选项:`ch`。默认为 `ch`。
255295
256- `model_type (str)` : 同Det部分介绍 。
296+ `model_type (str)` : 同 Det 部分介绍 。
257297
258- `ocr_version (str)` : 同Det部分介绍 。
298+ `ocr_version (str)` : 同 Det 部分介绍 。
259299
260- `model_path (str)` : 文本行方向分类模型路径,仅限于PaddleOCR训练所得二分类分类模型 。默认值为`None`。
300+ `model_path (str)` : 文本行方向分类模型路径,仅限于 PaddleOCR 训练所得二分类分类模型 。默认值为 `None`。
261301
262302`model_dir (str)` : 占位参数,暂时无效。
263303
264- `cls_image_shape (List[int])` : 输入方向分类模型的图像Shape (CHW)。默认值为`[3, 48, 192]`。
304+ `cls_image_shape (List[int])` : 输入方向分类模型的图像 Shape (CHW)。默认值为 `[3, 48, 192]`。
265305
266- `cls_batch_num (int)` : 批次推理的batch大小 ,一般采用默认值即可,太大并没有明显提速,效果还可能会差。默认值为6。
306+ `cls_batch_num (int)` : 批次推理的 batch 大小 ,一般采用默认值即可,太大并没有明显提速,效果还可能会差。默认值为6。
267307
268308`cls_thresh (float)` : 方向分类结果的置信度。取值范围:`[0, 1]`,默认值为0.9。
269309
270- `label_list (List[str])` : 方向分类的标签,0°或者180°,**该参数不能动** 。默认值为`["0", "180"]`。
310+ `label_list (List[str])` : 方向分类的标签,0°或者180°,**该参数不能动** 。默认值为 `["0", "180"]`。
271311
272312# ### Rec
273313
@@ -288,20 +328,20 @@ Rec:
288328 rec_batch_num: 6
289329` ` `
290330
291- `engine_type (str)` : 同Det部分介绍 。
331+ `engine_type (str)` : 同 Det 部分介绍 。
292332
293- `lang_type (str)` : 支持检测的语种类型。这里指的是`LangRec`,具体支持的语种参见:[model_list](../../model_list.md).
333+ `lang_type (str)` : 支持检测的语种类型。这里指的是 `LangRec`,具体支持的语种参见:[model_list](../../model_list.md).
294334
295- `model_type (str)` : 同Det部分介绍 。
335+ `model_type (str)` : 同 Det 部分介绍 。
296336
297- `ocr_version (str)` : 同Det部分介绍 。
337+ `ocr_version (str)` : 同 Det 部分介绍 。
298338
299- `model_path (str)` : 文本识别模型路径,仅限于PaddleOCR训练文本识别模型 。默认值为`None`。
339+ `model_path (str)` : 文本识别模型路径,仅限于 PaddleOCR 训练文本识别模型 。默认值为 `None`。
300340
301- `model_dir (str)` : 模型存放路径或目录。如果是PaddlePaddle ,该参数则对应模型存在目录。其余推理引擎请使用`model_path`参数。
341+ `model_dir (str)` : 模型存放路径或目录。如果是 PaddlePaddle ,该参数则对应模型存在目录。其余推理引擎请使用 `model_path` 参数。
302342
303- `rec_keys_path (str)` : 文本识别模型对应的字典文件,默认为`None`。
343+ `rec_keys_path (str)` : 文本识别模型对应的字典文件,默认为 `None`。
304344
305- `rec_img_shape (List[int])` : 输入文本识别模型的图像Shape (CHW)。默认值为`[3, 48, 320]`。
345+ `rec_img_shape (List[int])` : 输入文本识别模型的图像 Shape (CHW)。默认值为 `[3, 48, 320]`。
306346
307347`rec_batch_num (int)` : 批次推理的batch大小,一般采用默认值即可,太大并没有明显提速,效果还可能会差。默认值为6。
0 commit comments