Skip to content

Commit 5cdd863

Browse files
committed
chore: update files
1 parent 0594ecc commit 5cdd863

8 files changed

Lines changed: 171 additions & 197 deletions

File tree

README.md

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<div>&nbsp;</div>
66
<a href="https://huggingface.co/spaces/SWHL/PaddleOCRModelConverter" target="_blank"><img src="https://img.shields.io/badge/%F0%9F%A4%97 -Online Convert-blue"></a>
77
<a href="https://www.modelscope.cn/studios/liekkas/PaddleOCRModelConverter/summary" target="_blank"><img src="https://img.shields.io/badge/ModelScope-Online Convert -blue"></a>
8-
<a href=""><img src="https://img.shields.io/badge/Python->=3.6,<3.13-aff.svg"></a>
8+
<a href=""><img src="https://img.shields.io/badge/Python->=3.6-aff.svg"></a>
99
<a href=""><img src="https://img.shields.io/badge/OS-Linux%2C%20Win%2C%20Mac-pink.svg"></a>
1010
<a href="https://pypi.org/project/paddleocr_convert/"><img alt="PyPI" src="https://img.shields.io/pypi/v/paddleocr_convert"></a>
1111
<a href="https://pepy.tech/project/paddleocr_convert"><img src="https://static.pepy.tech/personalized-badge/paddleocr_convert?period=total&units=abbreviation&left_color=grey&right_color=blue&left_text=Downloads "></a>
@@ -14,15 +14,16 @@
1414
</div>
1515

1616
### Introduction
17+
1718
- This repository is mainly to convert [Inference Model in PaddleOCR](https://github.com/PaddlePaddle/PaddleOCR/blob/release/2.6/doc/doc_ch/models_list.md) into ONNX format.
1819
- **Input**: **url** or local **tar** path of inference model
1920
- **Output**: converted **ONNX** model
2021
- If it is a recognition model, you need to provide the original txt path of the corresponding dictionary (**Open the txt file in github, click the path after raw in the upper right corner, similar to [this](https://raw.githubusercontent.com/PaddlePaddle/PaddleOCR/release/2.6/ppocr/utils/ppocr_keys_v1.txt)**), used to write the dictionary into the ONNX model
2122
- ☆ It needs to be used with the relevant reasoning code in [RapidOCR](https://github.com/RapidAI/RapidOCR)
2223
- If you encounter a model that cannot be successfully converted, you can check which steps are wrong one by one according to the ideas in the figure below.
2324

24-
2525
### Overall framework
26+
2627
```mermaid
2728
flowchart TD
2829
@@ -32,19 +33,23 @@ D --> E([Save])
3233
```
3334

3435
### Installation
36+
3537
```bash
3638
pip install paddleocr_convert
3739
```
3840

3941
### Usage
42+
>
4043
> [!WARNING]
4144
>
4245
> Only support the **reasoning model** in the download address in [link](https://github.com/PaddlePaddle/PaddleOCR/blob/release/2.6/doc/doc_ch/models_list.md), if it is a training model, Manual conversion to inference format is required.
4346
>
4447
> The **slim quantized model** in PaddleOCR does not support conversion.
4548
4649
#### Using the command line
50+
4751
- Usage:
52+
4853
```bash
4954
$ paddleocr_convert -h
5055
usage: paddleocr_convert [-h] [-p MODEL_PATH] [-o SAVE_DIR]
@@ -63,9 +68,11 @@ pip install paddleocr_convert
6368
The raw txt url or local txt path, if the model is
6469
recognition model.
6570
```
71+
6672
- Example:
73+
6774
```bash
68-
#online
75+
# online
6976
$ paddleocr_convert -p https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/ch_PP-OCRv3_det_infer.tar \
7077
-o models
7178

@@ -74,16 +81,18 @@ pip install paddleocr_convert
7481
-txt_path https://raw.githubusercontent.com/PaddlePaddle/PaddleOCR/release/2.6/ppocr/utils/ppocr_keys_v1.txt
7582

7683
# offline
77-
$ paddleocr_convert -p models/ch_PP-OCRv3_det_infer.tar\
84+
$ paddleocr_convert -p models/ch_PP-OCRv3_det_infer.tar \
7885
-o models
7986

80-
$ paddleocr_convert -p models/ch_PP-OCRv3_rec_infer.tar\
87+
$ paddleocr_convert -p models/ch_PP-OCRv3_rec_infer.tar \
8188
-o models\
8289
-txt_path models/ppocr_keys_v1.txt
8390
```
8491
8592
#### Script use
93+
8694
- online mode
95+
8796
```python
8897
from paddleocr_convert import PaddleOCRModelConvert
8998

@@ -94,7 +103,9 @@ pip install paddleocr_convert
94103

95104
converter(url, save_dir, txt_path=txt_url)
96105
```
106+
97107
- offline mode
108+
98109
```python
99110
from paddleocr_convert import PaddleOCRModelConvert
100111

@@ -106,47 +117,50 @@ pip install paddleocr_convert
106117
```
107118
108119
### Use the model
120+
109121
Assuming that the model needs to be recognized in Japanese, and it has been converted, the path is `local/models/japan.onnx`
110122
111-
1. Install `rapidocr_onnxruntime` library
123+
1. Install `rapidocr` library
124+
112125
```bash
113-
pip install rapidocr_onnxruntime
126+
# rapidocr v3.2.0
127+
pip install rapidocr onnxruntime
114128
```
129+
115130
2. Script use
131+
116132
```python
117-
from rapidocr_onnxruntime import RapidOCR
133+
from rapidocr import RapidOCR
118134

119135
model_path = 'local/models/japan.onnx'
120-
engine = RapidOCR(rec_model_path=model_path)
136+
engine = RapidOCR(params={'Rec.model_path': model_path})
121137

122-
img = '1.jpg'
123-
result, elapse = engine(img)
124-
```
125-
3. CLI use
126-
```bash
127-
rapidocr_onnxruntime -img 1.jpg --rec_model_path local/models/japan.onnx
138+
img_url = "https://img1.baidu.com/it/u=3619974146,1266987475&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=516"
139+
result = engine(img_url)
140+
print(result)
141+
result.vis('vis_result.jpg)
128142
```
129143
130-
### Changelog
144+
### Changelog ([more](https://github.com/RapidAI/PaddleOCRModelConvert/releases))
131145
132146
<details>
133147
<summary>Click to expand</summary>
134148
135149
- 2023-09-22 v0.0.17 update:
136150
- Improve the log when meets the error.
137151
- 2023-07-27 v0.0.16 update:
138-
- Added the online conversion version of ModelScope.
139-
- Change python version from python 3.6 ~ 3.11.
152+
- Added the online conversion version of ModelScope.
153+
- Change python version from python 3.6 ~ 3.11.
140154
- 2023-04-13 update:
141-
- Add online conversion program [link](https://huggingface.co/spaces/SWHL/PaddleOCRModelConverter)
155+
- Add online conversion program [link](https://huggingface.co/spaces/SWHL/PaddleOCRModelConverter)
142156
- 2023-03-05 v0.0.4~7 update:
143-
- Support transliteration of local models and dictionaries
144-
- Optimize internal logic and error feedback
157+
- Support transliteration of local models and dictionaries
158+
- Optimize internal logic and error feedback
145159
- 2023-02-28 v0.0.3 update:
146-
- Added setting to automatically change to dynamic input for models that are not dynamic input
160+
- Added setting to automatically change to dynamic input for models that are not dynamic input
147161
- 2023-02-27 v0.0.2 update:
148-
- Encapsulate the conversion model code into a package, which is convenient for self-help model conversion
162+
- Encapsulate the conversion model code into a package, which is convenient for self-help model conversion
149163
- 2022-08-15 v0.0.1 update:
150-
- Write the dictionary of the recognition model into the meta in the onnx model for subsequent distribution.
164+
- Write the dictionary of the recognition model into the meta in the onnx model for subsequent distribution.
151165
152166
</details>

demo.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# @Contact: liekkaskono@163.com
44
from paddleocr_convert import PaddleOCRModelConvert
55

6-
76
converter = PaddleOCRModelConvert()
87

98
# converter('ch_PP-OCRv3_det_infer.tar', save_dir)
@@ -12,9 +11,12 @@
1211

1312
# url = 'https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_cls_infer.tar'
1413

15-
url = 'https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/ch_PP-OCRv3_rec_infer.tar'
14+
url = "https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0.0/PP-OCRv5_mobile_det_infer.tar"
15+
16+
# url = "https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/ch_PP-OCRv3_rec_infer.tar"
1617

17-
save_dir = 'models'
18-
txt_path = 'https://gitee.com/paddlepaddle/PaddleOCR/raw/release/2.6/ppocr/utils/ppocr_keys_v1.txt'
18+
save_dir = "models"
19+
# txt_path = "https://gitee.com/paddlepaddle/PaddleOCR/raw/release/2.6/ppocr/utils/ppocr_keys_v1.txt"
1920

20-
converter(url, save_dir, txt_path=txt_path, is_del_raw=True)
21+
result = converter(url, save_dir, is_del_raw=False)
22+
print(result)

docs/docs_whl.md

Lines changed: 1 addition & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1 @@
1-
## paddleocr_convert
2-
<p>
3-
<a href="https://huggingface.co/spaces/SWHL/PaddleOCRModelConverter" target="_blank"><img src="https://img.shields.io/badge/%F0%9F%A4%97-Online Convert-blue"></a>
4-
<a href="https://www.modelscope.cn/studios/liekkas/PaddleOCRModelConverter/summary" target="_blank"><img src="https://img.shields.io/badge/ModelScope-Online Convert -blue"></a>
5-
<a href=""><img src="https://img.shields.io/badge/Python->=3.7,<=3.10-aff.svg"></a>
6-
<a href=""><img src="https://img.shields.io/badge/OS-Linux%2C%20Win%2C%20Mac-pink.svg"></a>
7-
<a href="https://pypi.org/project/paddleocr_convert/"><img alt="PyPI" src="https://img.shields.io/pypi/v/paddleocr_convert"></a>
8-
<a href="https://pepy.tech/project/paddleocr_convert"><img src="https://static.pepy.tech/personalized-badge/paddleocr_convert?period=total&units=abbreviation&left_color=grey&right_color=blue&left_text=Downloads"></a>
9-
<a href="http://rapidai-team.com/PaddleOCRModelConverter/paddleocr_convert.html"><img height="20" alt="paddleocr_convert documentation" src="https://shields.mitmproxy.org/badge/API Docs-paddocr_convert-brightgreen.svg"></a>
10-
</p>
11-
12-
### 1. Install package by pypi.
13-
```bash
14-
pip install paddleocr_convert
15-
```
16-
17-
### 2. Run by command line.
18-
- Usage:
19-
```bash
20-
$ paddleocr_convert -h
21-
usage: paddleocr_convert [-h] [-p MODEL_PATH] [-o SAVE_DIR]
22-
[-txt_path TXT_PATH]
23-
24-
optional arguments:
25-
-h, --help show this help message and exit
26-
-p MODEL_PATH, --model_path MODEL_PATH
27-
The inference model url or local path of paddleocr.
28-
e.g. https://paddleocr.bj.bcebos.com/PP-
29-
OCRv3/chinese/ch_PP-OCRv3_det_infer.tar or
30-
models/ch_PP-OCRv3_det_infer.tar
31-
-o SAVE_DIR, --save_dir SAVE_DIR
32-
The directory of saving the model.
33-
-txt_path TXT_PATH, --txt_path TXT_PATH
34-
The raw txt url or local txt path, if the model is
35-
recognition model.
36-
```
37-
- Example:
38-
```bash
39-
# online
40-
$ paddleocr_convert -p https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/ch_PP-OCRv3_det_infer.tar \
41-
-o models
42-
43-
$ paddleocr_convert -p https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/ch_PP-OCRv3_rec_infer.tar \
44-
-o models \
45-
-txt_path https://raw.githubusercontent.com/PaddlePaddle/PaddleOCR/release/2.6/ppocr/utils/ppocr_keys_v1.txt
46-
47-
# offline
48-
$ paddleocr_convert -p models/ch_PP-OCRv3_det_infer.tar \
49-
-o models
50-
51-
$ paddleocr_convert -p models/ch_PP-OCRv3_rec_infer.tar \
52-
-o models \
53-
-txt_path models/ppocr_keys_v1.txt
54-
```
55-
56-
### 3. Run by script.
57-
- online mode
58-
```python
59-
from paddleocr_convert import PaddleOCRModelConvert
60-
61-
converter = PaddleOCRModelConvert()
62-
63-
save_dir = 'models'
64-
url = 'https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/ch_PP-OCRv3_rec_infer.tar'
65-
txt_url = 'https://raw.githubusercontent.com/PaddlePaddle/PaddleOCR/release/2.6/ppocr/utils/ppocr_keys_v1.txt'
66-
67-
converter(url, save_dir, txt_path=txt_url)
68-
```
69-
- offline mode
70-
```python
71-
from paddleocr_convert import PaddleOCRModelConvert
72-
73-
converter = PaddleOCRModelConvert()
74-
75-
save_dir = 'models'
76-
model_path = 'models/ch_PP-OCRv3_rec_infer.tar'
77-
txt_path = 'models/ppocr_keys_v1.txt'
78-
converter(model_path, save_dir, txt_path=txt_path)
79-
```
80-
81-
### See more details for [PaddleOCRModelConvert](https://github.com/RapidAI/PaddleOCRModelConvert).
1+
See [link](https://github.com/RapidAI/PaddleOCRModelConvert) for details.

0 commit comments

Comments
 (0)