44 </div >
55
66<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 >
88<a href =" " ><img src =" https://img.shields.io/badge/OS-Linux%2C%20Win%2C%20Mac-pink.svg " ></a >
99<a href =" https://pypi.org/project/rapid-layout/ " ><img alt =" PyPI " src =" https://img.shields.io/pypi/v/rapid-layout " ></a >
1010<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
4343
4444### TODO
4545
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 ) 整理
4747
4848### 安装
4949
5050由于模型较小,预先将中文版面分析模型(` layout_cdla.onnx ` )打包进了whl包内,如果做中文版面分析,可直接安装使用
5151
5252``` bash
53- pip install rapid-layout
53+ pip install rapid-layout onnxruntime
5454```
5555
5656### 使用方式
5757
5858#### python脚本运行
5959
6060``` 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
6362
64- from rapid_layout import RapidLayout, VisLayout
63+ cfg = RapidLayoutInput()
64+ layout_engine = RapidLayout(cfg = cfg)
6565
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)
6869
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" )
7671```
7772
7873### 可视化结果
7974
8075<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%">
8277</div >
8378
8479#### 终端运行
8580
8681``` 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
10783```
10884
109- - 示例:
110-
111- ``` bash
112- rapid_layout -v -img test_images/layout.png
113- ```
114-
11585### GPU推理
11686
11787- 因为版面分析模型输入图像尺寸固定,故可使用` onnxruntime-gpu ` 来提速。
@@ -132,25 +102,41 @@ pip install onnxruntime-gpu
132102#### 使用
133103
134104``` 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)
138117
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
141127
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)
144134
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)
151138
152- avg_elapse = sum(elapses) / len(elapses)
153- print(f' avg elapse: {avg_elapse:.4f}' )
139+ results.vis(" layout_res.png" )
154140```
155141
156142### 参考项目
0 commit comments