Skip to content

Commit 0bfb220

Browse files
committed
chore: update files
1 parent 8b294f7 commit 0bfb220

File tree

1 file changed

+87
-63
lines changed

1 file changed

+87
-63
lines changed

docs/install_usage/rapidocr/usage.md

Lines changed: 87 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -40,67 +40,73 @@ result.vis("vis_result.jpg")
4040

4141
1. 生成**default_rapidocr.yaml**的配置文件。终端执行以下代码,即可在当前目录下生成默认的**default_rapidocr.yaml**文件。
4242

43-
```bash linenums="1"
44-
$ rapidocr config
45-
# The config file has saved in ./default_rapidocr.yaml
46-
```
47-
48-
2. 根据自己的需要更改 **default_rapidocr.yaml** 相应的值。例如使用OpenVINO作为推理引擎,更改如下:
43+
```bash linenums="1"
44+
$ rapidocr config
45+
# The config file has saved in ./default_rapidocr.yaml
46+
```
4947

50-
```yaml linenums="1" hl_lines="19"
51-
# 该配置文件命名为1.yaml
52-
Global:
53-
lang_det: "ch_mobile" # ch_server
54-
lang_rec: "ch_mobile"
55-
text_score: 0.5
48+
2. 根据自己的需要更改 **default_rapidocr.yaml** 相应的值。例如使用OpenVINO作为文本检测的推理引擎,更改如下:
5649

57-
use_det: true
58-
use_cls: true
59-
use_rec: true
50+
```yaml linenums="1" hl_lines="3"
51+
# 该配置文件命名为1.yaml
52+
Det:
53+
engine_type: 'openvino'
54+
lang_type: 'ch'
55+
model_type: 'mobile'
56+
ocr_version: 'PP-OCRv4'
6057

61-
min_height: 30
62-
width_height_ratio: 8
63-
max_side_len: 2000
64-
min_side_len: 30
58+
task_type: 'det'
6559

66-
return_word_box: false
60+
model_path: null
61+
model_dir: null
6762

68-
with_onnx: false
69-
with_openvino: true # 更改这里为true
70-
with_paddle: false
71-
with_torch: false
63+
limit_side_len: 736
64+
limit_type: min
65+
std: [ 0.5, 0.5, 0.5 ]
66+
mean: [ 0.5, 0.5, 0.5 ]
7267

73-
font_path: null
74-
```
68+
thresh: 0.3
69+
box_thresh: 0.5
70+
max_candidates: 1000
71+
unclip_ratio: 1.6
72+
use_dilation: true
73+
score_mode: fast
74+
```
7575

7676
3. 传入到`RapidOCR`中使用。
7777

78-
```python linenums="1" hl_lines="4-5"
79-
from rapidocr import RapidOCR
78+
```python linenums="1" hl_lines="4-5"
79+
from rapidocr import RapidOCR
8080

81-
# 步骤2中的1.yaml
82-
config_path = "1.yaml"
83-
engine = RapidOCR(config_path=config_path)
81+
# 步骤2中的1.yaml
82+
config_path = "1.yaml"
83+
engine = RapidOCR(config_path=config_path)
8484

85-
img_url = "https://img1.baidu.com/it/u=3619974146,1266987475&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=516"
86-
result = engine(img_url)
87-
print(result)
85+
img_url = "https://img1.baidu.com/it/u=3619974146,1266987475&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=516"
86+
result = engine(img_url)
87+
print(result)
8888

89-
result.vis("vis_result.jpg")
90-
```
89+
result.vis("vis_result.jpg")
90+
```
9191

9292
=== "方法二:直接传入相应参数"
9393

9494
由于rapidocr中涉及可调节的参数众多,为了便于维护,引入[omageconf](https://github.com/omry/omegaconf)库来更新参数。这样带来的代价是传入参数没有1.x系列中直观一些。但是现阶段方式也容易理解和使用。
9595

96-
例如,我想使用OpenVINO作为推理引擎,可以通过下面这种方式使用:
96+
例如,我想使用OpenVINO作为各个流程的推理引擎,可以通过下面这种方式使用:
9797

98-
```python linenums="1" hl_lines="3"
99-
from rapidocr import RapidOCR
98+
```python linenums="1" hl_lines="5-7"
99+
from rapidocr import EngineType, ModelType, OCRVersion, RapidOCR
100100

101-
engine = RapidOCR(params={"Global.with_openvino": True})
101+
engine = RapidOCR(
102+
params={
103+
"Det.engine_type": EngineType.OPENVINO,
104+
"Cls.engine_type": EngineType.OPENVINO,
105+
"Rec.engine_type": EngineType.OPENVINO,
106+
}
107+
)
102108

103-
img_url = "https://github.com/RapidAI/RapidOCR/blob/main/python/tests/test_files/ch_en_num.jpg?raw=true"
109+
img_url = "<https://github.com/RapidAI/RapidOCR/blob/main/python/tests/test_files/ch_en_num.jpg?raw=true>"
104110
result = engine(img_url)
105111
print(result)
106112

@@ -112,8 +118,8 @@ result.vis("vis_result.jpg")
112118
`config.yaml`部分参数示例:
113119

114120
```yaml linenums="1"
115-
Global:
116-
with_torch: true
121+
Det:
122+
engine_type: 'torch'
117123

118124
EngineConfig:
119125
torch:
@@ -123,10 +129,12 @@ result.vis("vis_result.jpg")
123129

124130
**对应参数写法**
125131

126-
```python linenums="1"
132+
```python linenums="1" hl_lines="5-7"
133+
from rapidocr import EngineType, RapidOCR
134+
127135
engine = RapidOCR(
128136
params={
129-
"Global.with_torch": True,
137+
"Det.engine_type": EngineType.TORCH,
130138
"EngineConfig.torch.use_cuda": True, # 使用torch GPU版推理
131139
"EngineConfig.torch.gpu_id": 0, # 指定GPU id
132140
}
@@ -565,10 +573,14 @@ RapidOCR输出包括4种类型:`Union[TextDetOutput, TextClsOutput, TextRecOut
565573

566574
### 选择不同推理引擎
567575

568-
`rapidocr`支持4种推理引擎(**ONNXRuntime / OpenVINO / PaddlePaddle / PyTorch**),推荐首先使用**ONNXRuntime CPU**
576+
`rapidocr`支持4种推理引擎(**ONNXRuntime / OpenVINO / PaddlePaddle / PyTorch**),推荐首先使用 **ONNXRuntime CPU** 版。默认为ONNXRuntie
569577

570578
`rapidocr`是通过指定不同参数来选择使用不同的推理引擎的。当然,使用不同推理引擎的前提是事先安装好对应的推理引擎库,并确保安装正确。
571579

580+
!!! info
581+
582+
`rapidocr>=3.0.0`版本,可以单独为文本检测、文本行方向分类和文本识别单独指定不同的推理引擎。例如:文本检测使用ONNXRuntime,文本识别使用Paddle(`params={"Rec.engine_type": EngineType.PADDLE}`)。同时,不同版本的OCR也可以通过`Det.ocr_version`灵活指定。
583+
572584
=== "使用ONNXRuntime"
573585

574586
1. 安装ONNXRuntime。推荐用CPU版的ONNXRuntime,GPU版不推荐在`rapidocr`中使用,相关原因参见:[ONNXRuntime GPU推理](../../blog/posts/inference_engine/onnxruntime/onnxruntime-gpu.md)
@@ -612,17 +624,23 @@ RapidOCR输出包括4种类型:`Union[TextDetOutput, TextClsOutput, TextRecOut
612624

613625
2. 指定OpenVINO作为推理引擎
614626

615-
```python linenums="1" hl_lines="3"
616-
from rapidocr import RapidOCR
627+
```python linenums="1" hl_lines="5-7"
628+
from rapidocr import RapidOCR, EngineType
617629

618-
engine = RapidOCR(params={"Global.with_openvino": True})
630+
engine = RapidOCR(
631+
params={
632+
"Det.engine_type": EngineType.OPENVINO,
633+
"Cls.engine_type": EngineType.OPENVINO,
634+
"Rec.engine_type": EngineType.OPENVINO,
635+
}
636+
)
619637

620-
img_url = "https://github.com/RapidAI/RapidOCR/blob/main/python/tests/test_files/ch_en_num.jpg?raw=true"
621-
result = engine(img_url)
622-
print(result)
638+
img_url = "https://github.com/RapidAI/RapidOCR/blob/main/python/tests/test_files/ch_en_num.jpg?raw=true"
639+
result = engine(img_url)
640+
print(result)
623641

624-
result.vis('vis_result.jpg')
625-
```
642+
result.vis('vis_result.jpg')
643+
```
626644

627645
3. 查看输出日志。下面日志中打印出了**Using engine_name: openvino**,则证明使用的推理引擎是OpenVINO。
628646

@@ -647,10 +665,16 @@ RapidOCR输出包括4种类型:`Union[TextDetOutput, TextClsOutput, TextRecOut
647665

648666
- CPU版
649667

650-
```python linenums="1" hl_lines="3"
651-
from rapidocr import RapidOCR
668+
```python linenums="1" hl_lines="5-7"
669+
from rapidocr import EngineType, RapidOCR
652670

653-
engine = RapidOCR(params={"Global.with_paddle": True})
671+
engine = RapidOCR(
672+
params={
673+
"Det.engine_type": EngineType.PADDLE,
674+
"Cls.engine_type": EngineType.PADDLE,
675+
"Rec.engine_type": EngineType.PADDLE,
676+
}
677+
)
654678

655679
img_url = "https://github.com/RapidAI/RapidOCR/blob/main/python/tests/test_files/ch_en_num.jpg?raw=true"
656680
result = engine(img_url)
@@ -662,11 +686,11 @@ RapidOCR输出包括4种类型:`Union[TextDetOutput, TextClsOutput, TextRecOut
662686
- GPU版
663687

664688
```python linenums="1" hl_lines="3-9"
665-
from rapidocr import RapidOCR
689+
from rapidocr import EngineType, RapidOCR
666690

667691
engine = RapidOCR(
668692
params={
669-
"Global.with_paddle": True,
693+
"Det.engine_type": EngineType.PADDLE,
670694
"EngineConfig.paddlepaddle.use_cuda": True, # 使用PaddlePaddle GPU版推理
671695
"EngineConfig.paddlepaddle.gpu_id": 0, # 指定GPU id
672696
}
@@ -719,13 +743,13 @@ RapidOCR输出包括4种类型:`Union[TextDetOutput, TextClsOutput, TextRecOut
719743
- GPU版
720744

721745
```python linenums="1" hl_lines="3-9"
722-
from rapidocr import RapidOCR
746+
from rapidocr import EngineType, RapidOCR
723747

724748
engine = RapidOCR(
725749
params={
726-
"Global.with_torch": True,
727-
"EngineConfig.torch.use_cuda": True, # 使用torch GPU版推理
728-
"EngineConfig.torch.gpu_id": 0, # 指定GPU id
750+
"Det.engine_type": EngineType.TORCH,
751+
"Cls.engine_type": EngineType.TORCH,
752+
"Rec.engine_type": EngineType.TORCH,
729753
}
730754
)
731755

0 commit comments

Comments
 (0)