Skip to content

Commit

Permalink
chore: Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
SWHL committed Jun 19, 2024
1 parent 51c2851 commit c44b641
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 71 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gen_whl_to_pypi_rapid_layout.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- v*

env:
RESOURCES_URL: https://github.com/RapidAI/RapidStructure/releases/download/v0.0.0/rapid_layout_models.zip
RESOURCES_URL: https://github.com/RapidAI/RapidLayout/releases/download/v0.0.0/rapid_layout_models.zip

jobs:
UnitTesting:
Expand Down
107 changes: 51 additions & 56 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
## Rapid Layout
<p align="left">
<a href=""><img src="https://img.shields.io/badge/Python->=3.6,<3.12-aff.svg"></a>
<a href=""><img src="https://img.shields.io/badge/OS-Linux%2C%20Win%2C%20Mac-pink.svg"></a>
<a href="https://pypi.org/project/rapid-layout/"><img alt="PyPI" src="https://img.shields.io/pypi/v/rapid-layout"></a>
<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>
</p>
<div align="center">
<div align="center">
<h1><b>📃 Rapid Layout</b></h1>
</div>
<br/>

#### 简介和说明
<a href=""><img src="https://img.shields.io/badge/Python->=3.6,<3.13-aff.svg"></a>
<a href=""><img src="https://img.shields.io/badge/OS-Linux%2C%20Win%2C%20Mac-pink.svg"></a>
<a href="https://pypi.org/project/rapid-layout/"><img alt="PyPI" src="https://img.shields.io/pypi/v/rapid-layout"></a>
<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>

</div>

### 简介
- 该部分主要是做文档类图像的版面分析。模型来源:[PaddleOCR 版面分析](https://github.com/PaddlePaddle/PaddleOCR/blob/133d67f27dc8a241d6b2e30a9f047a0fb75bebbe/ppstructure/layout/README_ch.md)
- 具体来说,就是分析给定的文档类别图像(论文截图等),定位其中类别和位置,如标题、段落、表格和图片等各个部分。
- 目前支持三种类别的版面分析模型:中文、英文和表格版面分析模型,具体可参见下面表格:
Expand All @@ -19,64 +24,54 @@

- 模型下载地址为:[百度网盘](https://pan.baidu.com/s/1PI9fksW6F6kQfJhwUkewWg?pwd=p29g) | [Google Drive](https://drive.google.com/drive/folders/1DAPWSN2zGQ-ED_Pz7RaJGTjfkN2-Mvsf?usp=sharing)

#### 安装
### 安装
由于模型较小,预先将中文版面分析模型(`layout_cdla.onnx`)打包进了whl包内,如果做中文版面分析,可直接安装使用

```bash
$ pip install rapid-layout
```

#### 使用方式
1. python脚本运行
```python
import cv2
from rapid_layout import RapidLayout,vis_layout
### 使用方式
#### python脚本运行
```python
import cv2
from rapid_layout import RapidLayout,vis_layout

# model_type类型参见上表。指定不同model_type时,会自动下载相应模型到安装目录下的。
layout_engine = RapidLayout(box_threshold=0.5, model_type="pp_layout_cdla")
# model_type类型参见上表。指定不同model_type时,会自动下载相应模型到安装目录下的。
layout_engine = RapidLayout(box_threshold=0.5, model_type="pp_layout_cdla")

img = cv2.imread('test_images/layout.png')
img = cv2.imread('test_images/layout.png')

layout_res, elapse = layout_engine(img)

ploted_img = vis_layout(img, layout_res)
boxes, scores, class_names, *elapse = layout_engine(img)
ploted_img = VisLayout.draw_detections(img, boxes, scores, class_names)
if ploted_img is not None:
cv2.imwrite("layout_res.png", ploted_img)
print(layout_res)
```
```

#### 终端运行
- 用法:
```bash
$ rapid_layout -h
usage: rapid_layout [-h] -img IMG_PATH [-m {pp_layout_cdla,pp_layout_publaynet,pp_layout_table}]
[--box_threshold {pp_layout_cdla,pp_layout_publaynet,pp_layout_table}] [-v]

2. 终端运行
- 用法:
```bash
$ rapid_layout -h
usage: rapid_layout [-h] -img IMG_PATH [-m {pp_layout_cdla,pp_layout_publaynet,pp_layout_table}]
[--box_threshold {pp_layout_cdla,pp_layout_publaynet,pp_layout_table}] [-v]
options:
-h, --help show this help message and exit
-img IMG_PATH, --img_path IMG_PATH
Path to image for layout.
-m {pp_layout_cdla,pp_layout_publaynet,pp_layout_table}, --model_type {pp_layout_cdla,pp_layout_publaynet,pp_layout_table}
Support model type
--box_threshold {pp_layout_cdla,pp_layout_publaynet,pp_layout_table}
Box threshold, the range is [0, 1]
-v, --vis Wheter to visualize the layout results.
```
- 示例:
```bash
$ rapid_layout -v -img test_images/layout.png
```

options:
-h, --help show this help message and exit
-img IMG_PATH, --img_path IMG_PATH
Path to image for layout.
-m {pp_layout_cdla,pp_layout_publaynet,pp_layout_table}, --model_type {pp_layout_cdla,pp_layout_publaynet,pp_layout_table}
Support model type
--box_threshold {pp_layout_cdla,pp_layout_publaynet,pp_layout_table}
Box threshold, the range is [0, 1]
-v, --vis Wheter to visualize the layout results.
```
- 示例:
```bash
$ rapid_layout -v -img test_images/layout.png
```
### 可视化结果

3. 结果
- 返回结果
```python
# bbox: [左上角x0,左上角y0, 右下角x1, 右下角y1]
# label: 类别
[
{'bbox': array([321.4160495, 91.53214898, 562.06141263, 199.85522603]), 'label': 'text'},
{'bbox': array([58.67292211, 107.29000663, 300.25448676, 199.68142]), 'label': 'table_caption'}
]
```
- 可视化结果
<div align="center">
<img src="https://github.com/RapidAI/RapidStructure/releases/download/v0.0.0/layout_result.jpg" width="80%" height="80%">
</div>
<div align="center">
<img src="https://github.com/RapidAI/RapidLayout/releases/download/v0.0.0/layout_res.png" width="80%" height="80%">
</div>
18 changes: 4 additions & 14 deletions rapid_layout/main.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# -*- encoding: utf-8 -*-
# @Author: SWHL
# @Contact: liekkaskono@163.com
import argparse
import time
from pathlib import Path
Expand All @@ -34,7 +24,7 @@
ROOT_DIR = Path(__file__).resolve().parent
logger = get_logger("rapid_layout")

ROOT_URL = "https://github.com/RapidAI/RapidStructure/releases/download/v0.0.0/"
ROOT_URL = "https://github.com/RapidAI/RapidLayout/releases/download/v0.0.0/"
KEY_TO_MODEL_URL = {
"pp_layout_cdla": f"{ROOT_URL}/layout_cdla.onnx",
"pp_layout_publaynet": f"{ROOT_URL}/layout_publaynet.onnx",
Expand Down

0 comments on commit c44b641

Please sign in to comment.