Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
wangsen
paddle_dbnet
Commits
8a591a74
Commit
8a591a74
authored
Apr 19, 2022
by
MissPenguin
Browse files
update
parent
f9a9492f
Changes
31
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
71 additions
and
41 deletions
+71
-41
ppstructure/docs/vqa/input/zh_val_0.jpg
ppstructure/docs/vqa/input/zh_val_0.jpg
+0
-0
ppstructure/docs/vqa/input/zh_val_21.jpg
ppstructure/docs/vqa/input/zh_val_21.jpg
+0
-0
ppstructure/docs/vqa/input/zh_val_40.jpg
ppstructure/docs/vqa/input/zh_val_40.jpg
+0
-0
ppstructure/docs/vqa/input/zh_val_42.jpg
ppstructure/docs/vqa/input/zh_val_42.jpg
+0
-0
ppstructure/docs/vqa/result_re/zh_val_21_re.jpg
ppstructure/docs/vqa/result_re/zh_val_21_re.jpg
+0
-0
ppstructure/docs/vqa/result_re/zh_val_40_re.jpg
ppstructure/docs/vqa/result_re/zh_val_40_re.jpg
+0
-0
ppstructure/docs/vqa/result_ser/zh_val_0_ser.jpg
ppstructure/docs/vqa/result_ser/zh_val_0_ser.jpg
+0
-0
ppstructure/docs/vqa/result_ser/zh_val_42_ser.jpg
ppstructure/docs/vqa/result_ser/zh_val_42_ser.jpg
+0
-0
ppstructure/layout/README_ch.md
ppstructure/layout/README_ch.md
+15
-9
ppstructure/table/README_ch.md
ppstructure/table/README_ch.md
+21
-10
ppstructure/vqa/README.md
ppstructure/vqa/README.md
+35
-22
No files found.
doc/vqa/input/zh_val_0.jpg
→
ppstructure/
doc
s
/vqa/input/zh_val_0.jpg
View file @
8a591a74
File moved
doc/vqa/input/zh_val_21.jpg
→
ppstructure/
doc
s
/vqa/input/zh_val_21.jpg
View file @
8a591a74
File moved
doc/vqa/input/zh_val_40.jpg
→
ppstructure/
doc
s
/vqa/input/zh_val_40.jpg
View file @
8a591a74
File moved
doc/vqa/input/zh_val_42.jpg
→
ppstructure/
doc
s
/vqa/input/zh_val_42.jpg
View file @
8a591a74
File moved
doc/vqa/result_re/zh_val_21_re.jpg
→
ppstructure/
doc
s
/vqa/result_re/zh_val_21_re.jpg
View file @
8a591a74
File moved
doc/vqa/result_re/zh_val_40_re.jpg
→
ppstructure/
doc
s
/vqa/result_re/zh_val_40_re.jpg
View file @
8a591a74
File moved
doc/vqa/result_ser/zh_val_0_ser.jpg
→
ppstructure/
doc
s
/vqa/result_ser/zh_val_0_ser.jpg
View file @
8a591a74
File moved
doc/vqa/result_ser/zh_val_42_ser.jpg
→
ppstructure/
doc
s
/vqa/result_ser/zh_val_42_ser.jpg
View file @
8a591a74
File moved
ppstructure/layout/README_ch.md
View file @
8a591a74
[
English
](
README.md
)
| 简体中文
-
[
版面分析使用说明
](
#版面分析使用说明
)
-
[
1. 安装whl包
](
#1--安装whl包
)
-
[
2. 使用
](
#2-使用
)
-
[
3. 后处理
](
#3-后处理
)
-
[
4. 指标
](
#4-指标
)
-
[
5. 训练版面分析模型
](
#5-训练版面分析模型
)
# 版面分析使用说明
-
[
1. 安装whl包
](
#1
)
-
[
2. 使用
](
#2
)
-
[
3. 后处理
](
#3
)
-
[
4. 指标
](
#4
)
-
[
5. 训练版面分析模型
](
#5
)
<a
name=
"1"
></a>
## 1. 安装whl包
```
bash
pip
install
-U
https://paddleocr.bj.bcebos.com/whl/layoutparser-0.0.0-py3-none-any.whl
```
<a
name=
"2"
></a>
## 2. 使用
使用layoutparser识别给定文档的布局:
...
...
@@ -20,7 +23,7 @@ pip install -U https://paddleocr.bj.bcebos.com/whl/layoutparser-0.0.0-py3-none-a
```
python
import
cv2
import
layoutparser
as
lp
image
=
cv2
.
imread
(
"doc/table/layout.jpg"
)
image
=
cv2
.
imread
(
"
ppstructure/
doc
s
/table/layout.jpg"
)
image
=
image
[...,
::
-
1
]
# 加载模型
...
...
@@ -40,7 +43,7 @@ show_img.show()
下图展示了结果,不同颜色的检测框表示不同的类别,并通过
`show_element_type`
在框的左上角显示具体类别:
<div
align=
"center"
>
<img
src=
"../
../
doc/table/result_all.jpg"
width =
"600"
/>
<img
src=
"../doc
s
/table/result_all.jpg"
width =
"600"
/>
</div>
`PaddleDetectionLayoutModel`
函数参数说明如下:
...
...
@@ -68,6 +71,7 @@ show_img.show()
*
TableBank word和TableBank latex分别在word文档、latex文档数据集训练;
*
下载的TableBank数据集里同时包含word和latex。
<a
name=
"3"
></a>
## 3. 后处理
版面分析检测包含多个类别,如果只想获取指定类别(如"Text"类别)的检测框、可以使用下述代码:
...
...
@@ -106,9 +110,10 @@ show_img.show()
显示只有"Text"类别的结果:
<div
align=
"center"
>
<img
src=
"../
../
doc/table/result_text.jpg"
width =
"600"
/>
<img
src=
"../doc
s
/table/result_text.jpg"
width =
"600"
/>
</div>
<a
name=
"4"
></a>
## 4. 指标
| Dataset | mAP | CPU time cost | GPU time cost |
...
...
@@ -122,6 +127,7 @@ show_img.show()
**GPU:**
a single NVIDIA Tesla P40
<a
name=
"5"
></a>
## 5. 训练版面分析模型
上述模型基于
[
PaddleDetection
](
https://github.com/PaddlePaddle/PaddleDetection
)
训练,如果您想训练自己的版面分析模型,请参考:
[
train_layoutparser_model
](
train_layoutparser_model_ch.md
)
ppstructure/table/README_ch.md
View file @
8a591a74
-
[
表格识别
](
#表格识别
)
-
[
1. 表格识别 pipeline
](
#1-表格识别-pipeline
)
-
[
2. 性能
](
#2-性能
)
-
[
3. 使用
](
#3-使用
)
-
[
3.1 快速开始
](
#31-快速开始
)
-
[
3.2 训练
](
#32-训练
)
-
[
3.3 评估
](
#33-评估
)
-
[
3.4 预测
](
#34-预测
)
[
English
](
README.md
)
| 简体中文
# 表格识别
-
[
1. 表格识别 pipeline
](
#1
)
-
[
2. 性能
](
#2
)
-
[
3. 使用
](
#3
)
-
[
3.1 快速开始
](
#31
)
-
[
3.2 训练
](
#32
)
-
[
3.3 评估
](
#33
)
-
[
3.4 预测
](
#34
)
<a
name=
"1"
></a>
## 1. 表格识别 pipeline
表格识别主要包含三个模型
...
...
@@ -18,7 +21,7 @@
具体流程图如下


流程说明:
...
...
@@ -28,7 +31,9 @@
4.
单元格的识别结果和表格结构一起构造表格的html字符串。
<a
name=
"2"
></a>
## 2. 性能
我们在 PubTabNet
<sup>
[1]
</sup>
评估数据集上对算法进行了评估,性能如下
...
...
@@ -37,8 +42,10 @@
| EDD
<sup>
[2]
</sup>
| 88.3 |
| Ours | 93.32 |
<a
name=
"3"
></a>
## 3. 使用
<a
name=
"31"
></a>
### 3.1 快速开始
```
python
...
...
@@ -60,6 +67,7 @@ python3 table/predict_table.py --det_model_dir=inference/en_ppocr_mobile_v2.0_ta
note: 上述模型是在 PubLayNet 数据集上训练的表格识别模型,仅支持英文扫描场景,如需识别其他场景需要自己训练模型后替换
`det_model_dir`
,
`rec_model_dir`
,
`table_model_dir`
三个字段即可。
<a
name=
"32"
></a>
### 3.2 训练
在这一章节中,我们仅介绍表格结构模型的训练,
[
文字检测
](
../../doc/doc_ch/detection.md
)
和
[
文字识别
](
../../doc/doc_ch/recognition.md
)
的模型训练请参考对应的文档。
...
...
@@ -89,6 +97,7 @@ python3 tools/train.py -c configs/table/table_mv3.yml -o Global.checkpoints=./yo
**注意**
:
`Global.checkpoints`
的优先级高于
`Global.pretrain_weights`
的优先级,即同时指定两个参数时,优先加载
`Global.checkpoints`
指定的模型,如果
`Global.checkpoints`
指定的模型路径有误,会加载
`Global.pretrain_weights`
指定的模型。
<a
name=
"33"
></a>
### 3.3 评估
表格使用
[
TEDS(Tree-Edit-Distance-based Similarity)
](
https://github.com/ibm-aur-nlp/PubTabNet/tree/master/src
)
作为模型的评估指标。在进行模型评估之前,需要将pipeline中的三个模型分别导出为inference模型(我们已经提供好),还需要准备评估的gt, gt示例如下:
...
...
@@ -113,6 +122,8 @@ python3 table/eval_table.py --det_model_dir=path/to/det_model_dir --rec_model_di
```
bash
teds: 93.32
```
<a
name=
"34"
></a>
### 3.4 预测
```
python
...
...
@@ -120,6 +131,6 @@ cd PaddleOCR/ppstructure
python3
table
/
predict_table
.
py
--
det_model_dir
=
path
/
to
/
det_model_dir
--
rec_model_dir
=
path
/
to
/
rec_model_dir
--
table_model_dir
=
path
/
to
/
table_model_dir
--
image_dir
=
..
/
doc
/
table
/
1.
png
--
rec_char_dict_path
=
..
/
ppocr
/
utils
/
dict
/
table_dict
.
txt
--
table_char_dict_path
=
..
/
ppocr
/
utils
/
dict
/
table_structure_dict
.
txt
--
rec_char_type
=
EN
--
det_limit_side_len
=
736
--
det_limit_type
=
min
--
output
..
/
output
/
table
```
Reference
#
Reference
1.
https://github.com/ibm-aur-nlp/PubTabNet
2.
https://arxiv.org/pdf/1911.10683
ppstructure/vqa/README.md
View file @
8a591a74
-
[
文档视觉问答(DOC-VQA)
](
#文档视觉问答doc-vqa
)
-
[
1. 简介
](
#1-简介
)
-
[
2. 性能
](
#2-性能
)
-
[
3. 效果演示
](
#3-效果演示
)
-
[
3.1 SER
](
#31-ser
)
-
[
3.2 RE
](
#32-re
)
-
[
4. 安装
](
#4-安装
)
-
[
4.1 安装依赖
](
#41-安装依赖
)
-
[
4.2 安装PaddleOCR(包含 PP-OCR 和 VQA)
](
#42-安装paddleocr包含-pp-ocr-和-vqa
)
-
[
5. 使用
](
#5-使用
)
-
[
5.1 数据和预训练模型准备
](
#51-数据和预训练模型准备
)
-
[
5.2 SER
](
#52-ser
)
-
[
5.3 RE
](
#53-re
)
-
[
6. 参考链接
](
#6-参考链接
)
# 文档视觉问答(DOC-VQA)
# 文档视觉问答(DocVQA)
-
[
1. 简介
](
#1
)
-
[
2. 性能
](
#2
)
-
[
3. 效果演示
](
#3
)
-
[
3.1 SER
](
#31
)
-
[
3.2 RE
](
#32
)
-
[
4. 安装
](
#4
)
-
[
4.1 安装依赖
](
#41
)
-
[
4.2 安装PaddleOCR
](
#42
)
-
[
5. 使用
](
#5
)
-
[
5.1 数据和预训练模型准备
](
#51
)
-
[
5.2 SER
](
#52
)
-
[
5.3 RE
](
#53
)
-
[
6. 参考链接
](
#6
)
<a
name=
"1"
></a>
## 1. 简介
VQA指视觉问答,主要针对图像内容进行提问和回答
,DOC-
VQA是VQA任务中的一种,D
OC-
VQA主要针对文本图像的文字内容提出问题。
VQA指视觉问答,主要针对图像内容进行提问和回答
,Doc
VQA是VQA任务中的一种,D
oc
VQA主要针对文本图像的文字内容提出问题。
PP-Structure 里的
DOC-
VQA算法基于PaddleNLP自然语言处理算法库进行开发。
PP-Structure 里的
Doc
VQA算法基于PaddleNLP自然语言处理算法库进行开发。
主要特性如下:
...
...
@@ -34,6 +35,7 @@ PP-Structure 里的 DOC-VQA算法基于PaddleNLP自然语言处理算法库进
本项目是
[
LayoutXLM: Multimodal Pre-training for Multilingual Visually-rich Document Understanding
](
https://arxiv.org/pdf/2104.08836.pdf
)
在 Paddle 2.2上的开源实现,
包含了在
[
XFUND数据集
](
https://github.com/doc-analysis/XFUND
)
上的微调代码。
<a
name=
"2"
></a>
## 2. 性能
我们在
[
XFUN
](
https://github.com/doc-analysis/XFUND
)
的中文数据集上对算法进行了评估,性能如下
...
...
@@ -46,13 +48,15 @@ PP-Structure 里的 DOC-VQA算法基于PaddleNLP自然语言处理算法库进
| LayoutLMv2 | RE | 0.6777 |
[
链接
](
https://paddleocr.bj.bcebos.com/pplayout/re_LayoutLMv2_xfun_zh.tar
)
|
| LayoutLM | SER | 0.7731 |
[
链接
](
https://paddleocr.bj.bcebos.com/pplayout/ser_LayoutLM_xfun_zh.tar
)
|
<a
name=
"3"
></a>
## 3. 效果演示
**注意:**
测试图片来源于XFUN数据集。
<a
name=
"31"
></a>
### 3.1 SER

| !
[](
../
../
doc/vqa/result_ser/zh_val_42_ser.jpg
)

| !
[](
../doc
s
/vqa/result_ser/zh_val_42_ser.jpg
)
---|---
图中不同颜色的框表示不同的类别,对于XFUN数据集,有
`QUESTION`
,
`ANSWER`
,
`HEADER`
3种类别
...
...
@@ -63,16 +67,19 @@ PP-Structure 里的 DOC-VQA算法基于PaddleNLP自然语言处理算法库进
在OCR检测框的左上方也标出了对应的类别和OCR识别结果。
<a
name=
"32"
></a>
### 3.2 RE

| !
[](
../
../
doc/vqa/result_re/zh_val_40_re.jpg
)

| !
[](
../doc
s
/vqa/result_re/zh_val_40_re.jpg
)
---|---
图中红色框表示问题,蓝色框表示答案,问题和答案之间使用绿色线连接。在OCR检测框的左上方也标出了对应的类别和OCR识别结果。
<a
name=
"4"
></a>
## 4. 安装
<a
name=
"41"
></a>
### 4.1 安装依赖
-
**(1) 安装PaddlePaddle**
...
...
@@ -89,7 +96,8 @@ python3 -m pip install "paddlepaddle>=2.2" -i https://mirror.baidu.com/pypi/simp
```
更多需求,请参照
[
安装文档
](
https://www.paddlepaddle.org.cn/install/quick
)
中的说明进行操作。
### 4.2 安装PaddleOCR(包含 PP-OCR 和 VQA)
<a
name=
"42"
></a>
### 4.2 安装PaddleOCR
-
**(1)pip快速安装PaddleOCR whl包(仅预测)**
...
...
@@ -114,8 +122,10 @@ git clone https://gitee.com/paddlepaddle/PaddleOCR
python3
-m
pip
install
-r
ppstructure/vqa/requirements.txt
```
<a
name=
"5"
></a>
## 5. 使用
<a
name=
"51"
></a>
### 5.1 数据和预训练模型准备
如果希望直接体验预测过程,可以下载我们提供的预训练模型,跳过训练过程,直接预测即可。
...
...
@@ -139,6 +149,7 @@ wget https://paddleocr.bj.bcebos.com/dataset/XFUND.tar
python3 ppstructure/vqa/helper/trans_xfun_data.py
--ori_gt_path
=
path/to/json_path
--output_path
=
path/to/save_path
```
<a
name=
"52"
></a>
### 5.2 SER
启动训练之前,需要修改下面的四个字段
...
...
@@ -192,6 +203,7 @@ export CUDA_VISIBLE_DEVICES=0
python3 helper/eval_with_label_end2end.py
--gt_json_path
XFUND/zh_val/xfun_normalize_val.json
--pred_json_path
output_res/infer_results.txt
```
<a
name=
"53"
></a>
### 5.3 RE
*
启动训练
...
...
@@ -237,6 +249,7 @@ python3 tools/infer_vqa_token_ser_re.py -c configs/vqa/re/layoutxlm.yml -o Archi
最终会在
`config.Global.save_res_path`
字段所配置的目录下保存预测结果可视化图像以及预测结果文本文件,预测结果文本文件名为
`infer_results.txt`
。
<a
name=
"6"
></a>
## 6. 参考链接
-
LayoutXLM: Multimodal Pre-training for Multilingual Visually-rich Document Understanding, https://arxiv.org/pdf/2104.08836.pdf
...
...
Prev
1
2
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment