4
4
</div >
5
5
6
6
<a href =" https://huggingface.co/spaces/SWHL/RapidLayout " target =" _blank " ><img src =" https://img.shields.io/badge/%F0%9F%A4%97-Hugging Face Demo-blue " ></a >
7
- <a href =" " ><img src =" https://img.shields.io/badge/Python->=3.6,<3.13 -aff.svg " ></a >
7
+ <a href =" " ><img src =" https://img.shields.io/badge/Python->=3.6-aff.svg " ></a >
8
8
<a href =" " ><img src =" https://img.shields.io/badge/OS-Linux%2C%20Win%2C%20Mac-pink.svg " ></a >
9
9
<a href =" https://pypi.org/project/rapid-layout/ " ><img alt =" PyPI " src =" https://img.shields.io/pypi/v/rapid-layout " ></a >
10
10
<a href =" https://pepy.tech/project/rapid-layout " ><img src =" https://static.pepy.tech/personalized-badge/rapid-layout?period=total&units=abbreviation&left_color=grey&right_color=blue&left_text=Downloads " ></a >
@@ -43,75 +43,45 @@ yolov8n系列来源:[360LayoutAnalysis](https://github.com/360AILAB-NLP/360Lay
43
43
44
44
### TODO
45
45
46
- - [ ] [ PP-DocLayout] ( https://github.com/PaddlePaddle/PaddleX/blob/release/3.0-rc/docs/module_usage/tutorials/ocr_modules/layout_detection.md ) 整理
46
+ - [ ] [ PP-DocLayout] ( https://github.com/PaddlePaddle/PaddleX/blob/release/3.0-rc/docs/module_usage/tutorials/ocr_modules/layout_detection.md ) 整理
47
47
48
48
### 安装
49
49
50
50
由于模型较小,预先将中文版面分析模型(` layout_cdla.onnx ` )打包进了whl包内,如果做中文版面分析,可直接安装使用
51
51
52
52
``` bash
53
- pip install rapid-layout
53
+ pip install rapid-layout onnxruntime
54
54
```
55
55
56
56
### 使用方式
57
57
58
58
#### python脚本运行
59
59
60
60
``` python
61
- import cv2
62
- from imread_from_url import imread_from_url # pip install imread_from_url
61
+ from rapid_layout import EngineType, ModelType, RapidLayout, RapidLayoutInput
63
62
64
- from rapid_layout import RapidLayout, VisLayout
63
+ cfg = RapidLayoutInput()
64
+ layout_engine = RapidLayout(cfg = cfg)
65
65
66
- # model_type类型参见上表。指定不同model_type时,会自动下载相应模型到安装目录下的。
67
- layout_engine = RapidLayout(model_type = " doclayout_docstructbench" , conf_thres = 0.2 )
66
+ img_path = " https://raw.githubusercontent.com/RapidAI/RapidLayout/refs/heads/develop/tests/test_files/layout.jpg"
67
+ results = layout_engine(img_path)
68
+ print (results)
68
69
69
- img_url = " https://raw.githubusercontent.com/opendatalab/DocLayout-YOLO/refs/heads/main/assets/example/financial.jpg"
70
- img = imread_from_url(img_url)
71
-
72
- boxes, scores, class_names, elapse = layout_engine(img)
73
- ploted_img = VisLayout.draw_detections(img, boxes, scores, class_names)
74
- if ploted_img is not None :
75
- cv2.imwrite(" layout_res.png" , ploted_img)
70
+ results.vis(" layout_res.png" )
76
71
```
77
72
78
73
### 可视化结果
79
74
80
75
<div align =" center " >
81
- <img src="https://github.com/RapidAI/RapidLayout/releases/download/v0.0.0/layout_res.png " width="80%">
76
+ <img src="https://github.com/RapidAI/RapidLayout/releases/download/v0.0.0/layout_vis.jpg " width="80%" height ="80%">
82
77
</div >
83
78
84
79
#### 终端运行
85
80
86
81
``` bash
87
- $ rapid_layout -h
88
- usage: rapid_layout [-h] -img IMG_PATH
89
- [-m {pp_layout_cdla,pp_layout_publaynet,pp_layout_table,yolov8n_layout_paper,yolov8n_layout_report,yolov8n_layout_publaynet,yolov8n_layout_general6,doclayout_docstructbench,doclayout_d4la,doclayout_docsynth}]
90
- [--conf_thres {pp_layout_cdla,pp_layout_publaynet,pp_layout_table,yolov8n_layout_paper,yolov8n_layout_report,yolov8n_layout_publaynet,yolov8n_layout_general6,doclayout_docstructbench,doclayout_d4la,doclayout_docsynth}]
91
- [--iou_thres {pp_layout_cdla,pp_layout_publaynet,pp_layout_table,yolov8n_layout_paper,yolov8n_layout_report,yolov8n_layout_publaynet,yolov8n_layout_general6,doclayout_docstructbench,doclayout_d4la,doclayout_docsynth}]
92
- [--use_cuda] [--use_dml] [-v]
93
-
94
- options:
95
- -h, --help show this help message and exit
96
- -img IMG_PATH, --img_path IMG_PATH
97
- Path to image for layout.
98
- -m {pp_layout_cdla,pp_layout_publaynet,pp_layout_table,yolov8n_layout_paper,yolov8n_layout_report,yolov8n_layout_publaynet,yolov8n_layout_general6,doclayout_docstructbench,doclayout_d4la,doclayout_docsynth}, --model_type {pp_layout_cdla,pp_layout_publaynet,pp_layout_table,yolov8n_layout_paper,yolov8n_layout_report,yolov8n_layout_publaynet,yolov8n_layout_general6,doclayout_docstructbench,doclayout_d4la,doclayout_docsynth}
99
- Support model type
100
- --conf_thres {pp_layout_cdla,pp_layout_publaynet,pp_layout_table,yolov8n_layout_paper,yolov8n_layout_report,yolov8n_layout_publaynet,yolov8n_layout_general6,doclayout_docstructbench,doclayout_d4la,doclayout_docsynth}
101
- Box threshold, the range is [0, 1]
102
- --iou_thres {pp_layout_cdla,pp_layout_publaynet,pp_layout_table,yolov8n_layout_paper,yolov8n_layout_report,yolov8n_layout_publaynet,yolov8n_layout_general6,doclayout_docstructbench,doclayout_d4la,doclayout_docsynth}
103
- IoU threshold, the range is [0, 1]
104
- --use_cuda Whether to use cuda.
105
- --use_dml Whether to use DirectML, which only works in Windows10+.
106
- -v, --vis Wheter to visualize the layout results.
82
+ rapid_layout test_images/layout.png
107
83
```
108
84
109
- - 示例:
110
-
111
- ``` bash
112
- rapid_layout -v -img test_images/layout.png
113
- ```
114
-
115
85
### GPU推理
116
86
117
87
- 因为版面分析模型输入图像尺寸固定,故可使用` onnxruntime-gpu ` 来提速。
@@ -132,25 +102,41 @@ pip install onnxruntime-gpu
132
102
#### 使用
133
103
134
104
``` python
135
- import cv2
136
- from rapid_layout import RapidLayout
137
- from pathlib import Path
105
+ from rapid_layout import EngineType, ModelType, RapidLayout, RapidLayoutInput
106
+
107
+ cfg = RapidLayoutInput(
108
+ model_type = ModelType.PP_LAYOUT_CDLA ,
109
+ engine_type = EngineType.ONNXRUNTIME ,
110
+ engine_cfg = {" use_cuda" : True , " cuda_ep_cfg.gpu_id" : 1 },
111
+ )
112
+ layout_engine = RapidLayout(cfg = cfg)
113
+
114
+ img_path = " https://raw.githubusercontent.com/RapidAI/RapidLayout/refs/heads/develop/tests/test_files/layout.jpg"
115
+ results = layout_engine(img_path)
116
+ print (results)
138
117
139
- # 注意:这里需要使用use_cuda指定参数
140
- layout_engine = RapidLayout(model_type=" doclayout_yolo" , conf_thres=0.2, use_cuda=True)
118
+ results.vis(" layout_res.png" )
119
+ ```
120
+
121
+ ### NPU使用
122
+
123
+ 详细配置参数参见:[ link] ( https://github.com/RapidAI/RapidLayout/blob/a7ab63ff291bd72e1a98ac2bb11860575514f432/rapid_layout/configs/engine_cfg.yaml )
124
+
125
+ ``` python
126
+ from rapid_layout import EngineType, ModelType, RapidLayout, RapidLayoutInput
141
127
142
- # warm up
143
- layout_engine(" images/12027_5.png" )
128
+ cfg = RapidLayoutInput(
129
+ model_type = ModelType.PP_LAYOUT_CDLA ,
130
+ engine_type = EngineType.ONNXRUNTIME ,
131
+ engine_cfg = {" use_cann" : True , " cann_ep_cfg.gpu_id" : 0 },
132
+ )
133
+ layout_engine = RapidLayout(cfg = cfg)
144
134
145
- elapses = []
146
- img_list = list(Path('images').iterdir ())
147
- for img_path in img_list:
148
- boxes, scores, class_names, elapse = layout_engine(img_path)
149
- print(f" {img_path}: {elapse}s" )
150
- elapses.append(elapse)
135
+ img_path = " https://raw.githubusercontent.com/RapidAI/RapidLayout/refs/heads/develop/tests/test_files/layout.jpg"
136
+ results = layout_engine(img_path)
137
+ print (results)
151
138
152
- avg_elapse = sum(elapses) / len(elapses)
153
- print(f' avg elapse: {avg_elapse:.4f}' )
139
+ results.vis(" layout_res.png" )
154
140
```
155
141
156
142
### 参考项目
0 commit comments