2022-04-19 15:08:34 +08:00
|
|
|
|
[English](README.md) | 简体中文
|
2021-06-10 14:24:59 +08:00
|
|
|
|
|
2022-02-12 16:26:58 +08:00
|
|
|
|
# 表格识别
|
2021-09-23 20:58:14 +08:00
|
|
|
|
|
2022-08-16 22:16:24 +08:00
|
|
|
|
- [1. 表格识别 pipeline](#1-表格识别-pipeline)
|
|
|
|
|
- [2. 性能](#2-性能)
|
2022-08-16 22:21:32 +08:00
|
|
|
|
- [3. 效果演示](#3-效果演示)
|
|
|
|
|
- [4. 使用](#4-使用)
|
|
|
|
|
- [4.1 快速开始](#41-快速开始)
|
2022-08-23 22:01:33 +08:00
|
|
|
|
- [4.2 模型训练、评估与推理](#42-模型训练评估与推理)
|
2022-08-16 22:21:32 +08:00
|
|
|
|
- [4.3 计算TEDS](#43-计算teds)
|
|
|
|
|
- [5. Reference](#5-reference)
|
2022-04-19 15:08:34 +08:00
|
|
|
|
|
|
|
|
|
|
2021-08-03 10:44:18 +08:00
|
|
|
|
## 1. 表格识别 pipeline
|
2021-09-23 20:58:14 +08:00
|
|
|
|
|
2021-08-03 10:44:18 +08:00
|
|
|
|
表格识别主要包含三个模型
|
2021-06-10 14:24:59 +08:00
|
|
|
|
1. 单行文本检测-DB
|
|
|
|
|
2. 单行文本识别-CRNN
|
2022-08-16 22:16:24 +08:00
|
|
|
|
3. 表格结构和cell坐标预测-SLANet
|
2021-06-10 14:24:59 +08:00
|
|
|
|
|
|
|
|
|
具体流程图如下
|
|
|
|
|
|
2022-04-19 15:08:34 +08:00
|
|
|
|

|
2021-06-10 14:24:59 +08:00
|
|
|
|
|
2021-07-29 17:59:44 +08:00
|
|
|
|
流程说明:
|
|
|
|
|
|
|
|
|
|
1. 图片由单行文字检测模型检测到单行文字的坐标,然后送入识别模型拿到识别结果。
|
2022-08-16 22:16:24 +08:00
|
|
|
|
2. 图片由SLANet模型拿到表格的结构信息和单元格的坐标信息。
|
2021-06-10 14:24:59 +08:00
|
|
|
|
3. 由单行文字的坐标、识别结果和单元格的坐标一起组合出单元格的识别结果。
|
|
|
|
|
4. 单元格的识别结果和表格结构一起构造表格的html字符串。
|
|
|
|
|
|
2021-09-23 20:58:14 +08:00
|
|
|
|
|
2021-08-03 15:30:12 +08:00
|
|
|
|
## 2. 性能
|
2022-04-19 15:08:34 +08:00
|
|
|
|
|
2021-08-03 15:30:12 +08:00
|
|
|
|
我们在 PubTabNet<sup>[1]</sup> 评估数据集上对算法进行了评估,性能如下
|
2021-06-10 14:24:59 +08:00
|
|
|
|
|
2021-08-03 15:30:12 +08:00
|
|
|
|
|
2022-08-17 11:16:38 +08:00
|
|
|
|
|算法|Acc|[TEDS(Tree-Edit-Distance-based Similarity)](https://github.com/ibm-aur-nlp/PubTabNet/tree/master/src)|Speed|
|
|
|
|
|
| --- | --- | --- | ---|
|
2022-10-24 12:14:51 +08:00
|
|
|
|
| EDD<sup>[2]</sup> |x| 88.30% |x|
|
2022-08-20 16:40:40 +08:00
|
|
|
|
| TableRec-RARE(ours) | 71.73%| 93.88% |779ms|
|
2022-08-20 16:48:01 +08:00
|
|
|
|
| SLANet(ours) |76.31%| 95.89%|766ms|
|
2022-08-17 11:16:38 +08:00
|
|
|
|
|
|
|
|
|
性能指标解释如下:
|
|
|
|
|
- Acc: 模型对每张图像里表格结构的识别准确率,错一个token就算错误。
|
|
|
|
|
- TEDS: 模型对表格信息还原的准确度,此指标评价内容不仅包含表格结构,还包含表格内的文字内容。
|
|
|
|
|
- Speed: 模型在CPU机器上,开启MKL的情况下,单张图片的推理速度。
|
2021-08-03 15:30:12 +08:00
|
|
|
|
|
2022-08-16 22:21:32 +08:00
|
|
|
|
## 3. 效果演示
|
2022-02-12 16:26:58 +08:00
|
|
|
|
|
2022-08-17 10:53:16 +08:00
|
|
|
|

|
|
|
|
|

|
|
|
|
|

|
2022-08-16 22:21:32 +08:00
|
|
|
|
|
|
|
|
|
## 4. 使用
|
|
|
|
|
|
|
|
|
|
### 4.1 快速开始
|
2021-08-02 19:42:10 +08:00
|
|
|
|
|
2022-08-25 13:49:27 +08:00
|
|
|
|
PP-Structure目前提供了中英文两种语言的表格识别模型,模型链接见 [models_list](../docs/models_list.md)。也提供了whl包的形式方便快速使用,详见 [quickstart](../docs/quickstart.md)。
|
|
|
|
|
|
|
|
|
|
下面以中文表格识别模型为例,介绍如何识别一张表格。
|
2022-08-23 22:01:33 +08:00
|
|
|
|
|
2022-08-16 22:16:24 +08:00
|
|
|
|
使用如下命令即可快速完成一张表格的识别。
|
2021-08-02 19:42:10 +08:00
|
|
|
|
```python
|
|
|
|
|
cd PaddleOCR/ppstructure
|
|
|
|
|
|
|
|
|
|
# 下载模型
|
|
|
|
|
mkdir inference && cd inference
|
2022-08-16 18:46:09 +08:00
|
|
|
|
# 下载PP-OCRv3文本检测模型并解压
|
2022-08-22 16:20:20 +08:00
|
|
|
|
wget https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/ch_PP-OCRv3_det_infer.tar && tar xf ch_PP-OCRv3_det_infer.tar
|
2022-08-16 18:46:09 +08:00
|
|
|
|
# 下载PP-OCRv3文本识别模型并解压
|
2022-08-22 16:20:20 +08:00
|
|
|
|
wget https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/ch_PP-OCRv3_rec_infer.tar && tar xf ch_PP-OCRv3_rec_infer.tar
|
2022-10-12 14:52:33 +08:00
|
|
|
|
# 下载PP-StructureV2中文表格识别模型并解压
|
2022-08-16 18:46:09 +08:00
|
|
|
|
wget https://paddleocr.bj.bcebos.com/ppstructure/models/slanet/ch_ppstructure_mobile_v2.0_SLANet_infer.tar && tar xf ch_ppstructure_mobile_v2.0_SLANet_infer.tar
|
2021-08-02 19:42:10 +08:00
|
|
|
|
cd ..
|
2022-08-16 20:42:47 +08:00
|
|
|
|
# 执行表格识别
|
2022-08-16 22:16:24 +08:00
|
|
|
|
python table/predict_table.py \
|
2022-08-22 16:20:20 +08:00
|
|
|
|
--det_model_dir=inference/ch_PP-OCRv3_det_infer \
|
|
|
|
|
--rec_model_dir=inference/ch_PP-OCRv3_rec_infer \
|
2022-08-16 18:46:09 +08:00
|
|
|
|
--table_model_dir=inference/ch_ppstructure_mobile_v2.0_SLANet_infer \
|
|
|
|
|
--rec_char_dict_path=../ppocr/utils/ppocr_keys_v1.txt \
|
|
|
|
|
--table_char_dict_path=../ppocr/utils/dict/table_structure_dict_ch.txt \
|
|
|
|
|
--image_dir=docs/table/table.jpg \
|
|
|
|
|
--output=../output/table
|
2021-08-02 19:42:10 +08:00
|
|
|
|
```
|
2022-08-10 19:01:03 +08:00
|
|
|
|
运行完成后,每张图片的excel表格会保存到output字段指定的目录下,同时在该目录下回生产一个html文件,用于可视化查看单元格坐标和识别的表格。
|
2021-08-02 19:42:10 +08:00
|
|
|
|
|
2022-08-23 17:59:10 +08:00
|
|
|
|
**NOTE**
|
2022-08-23 22:01:33 +08:00
|
|
|
|
1. 如果想使用英文模型,需要在 [models_list](../docs/models_list.md) 中下载英文文字检测识别模型和英文表格识别模型,同时替换`table_structure_dict_ch.txt`为`table_structure_dict.txt`即可。
|
2022-08-23 17:59:10 +08:00
|
|
|
|
2. 如需使用TableRec-RARE模型,需要替换`table_structure_dict_ch.txt`为`table_structure_dict.txt`,同时参数`--merge_no_span_structure=False`
|
|
|
|
|
|
2022-08-23 22:01:33 +08:00
|
|
|
|
### 4.2 模型训练、评估与推理
|
2022-02-12 16:26:58 +08:00
|
|
|
|
|
2022-08-16 22:16:24 +08:00
|
|
|
|
文本检测模型的训练、评估和推理流程可参考 [detection](../../doc/doc_ch/detection.md)
|
2022-02-12 16:26:58 +08:00
|
|
|
|
|
2022-08-16 22:16:24 +08:00
|
|
|
|
文本识别模型的训练、评估和推理流程可参考 [recognition](../../doc/doc_ch/recognition.md)
|
2022-08-16 15:45:51 +08:00
|
|
|
|
|
2022-08-16 22:16:24 +08:00
|
|
|
|
表格识别模型的训练、评估和推理流程可参考 [table_recognition](../../doc/doc_ch/table_recognition.md)
|
2022-08-16 15:45:51 +08:00
|
|
|
|
|
2022-08-16 22:21:32 +08:00
|
|
|
|
### 4.3 计算TEDS
|
2021-06-10 14:24:59 +08:00
|
|
|
|
|
2021-08-03 15:30:12 +08:00
|
|
|
|
表格使用 [TEDS(Tree-Edit-Distance-based Similarity)](https://github.com/ibm-aur-nlp/PubTabNet/tree/master/src) 作为模型的评估指标。在进行模型评估之前,需要将pipeline中的三个模型分别导出为inference模型(我们已经提供好),还需要准备评估的gt, gt示例如下:
|
2022-08-10 19:01:03 +08:00
|
|
|
|
```txt
|
2022-08-16 22:16:24 +08:00
|
|
|
|
PMC5755158_010_01.png <html><body><table><thead><tr><td></td><td><b>Weaning</b></td><td><b>Week 15</b></td><td><b>Off-test</b></td></tr></thead><tbody><tr><td>Weaning</td><td>–</td><td>–</td><td>–</td></tr><tr><td>Week 15</td><td>–</td><td>0.17 ± 0.08</td><td>0.16 ± 0.03</td></tr><tr><td>Off-test</td><td>–</td><td>0.80 ± 0.24</td><td>0.19 ± 0.09</td></tr></tbody></table></body></html>
|
2022-08-10 19:01:03 +08:00
|
|
|
|
```
|
|
|
|
|
gt每一行都由文件名和表格的html字符串组成,文件名和表格的html字符串之间使用`\t`分隔。
|
|
|
|
|
|
|
|
|
|
也可使用如下命令,由标注文件生成评估的gt文件:
|
|
|
|
|
```python
|
|
|
|
|
python3 ppstructure/table/convert_label2html.py --ori_gt_path /path/to/your_label_file --save_path /path/to/save_file
|
2021-06-10 14:24:59 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
准备完成后使用如下命令进行评估,评估完成后会输出teds指标。
|
|
|
|
|
```python
|
2021-07-29 17:59:44 +08:00
|
|
|
|
cd PaddleOCR/ppstructure
|
2022-08-16 22:16:24 +08:00
|
|
|
|
python3 table/eval_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 \
|
2022-09-23 17:05:27 +08:00
|
|
|
|
--image_dir=docs/table/table.jpg \
|
2022-08-16 22:16:24 +08:00
|
|
|
|
--rec_char_dict_path=../ppocr/utils/dict/table_dict.txt \
|
|
|
|
|
--table_char_dict_path=../ppocr/utils/dict/table_structure_dict.txt \
|
|
|
|
|
--det_limit_side_len=736 \
|
|
|
|
|
--det_limit_type=min \
|
|
|
|
|
--gt_path=path/to/gt.txt
|
2021-06-10 14:24:59 +08:00
|
|
|
|
```
|
2022-08-23 17:59:10 +08:00
|
|
|
|
|
|
|
|
|
如使用英文表格识别模型在PubLatNet数据集上进行评估
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
cd PaddleOCR/ppstructure
|
|
|
|
|
# 下载模型
|
|
|
|
|
mkdir inference && cd inference
|
2022-08-23 22:01:33 +08:00
|
|
|
|
# 下载基于PubTabNet数据集训练的文本检测模型并解压
|
2022-08-23 17:59:10 +08:00
|
|
|
|
wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/table/en_ppocr_mobile_v2.0_table_det_infer.tar && tar xf en_ppocr_mobile_v2.0_table_det_infer.tar
|
2022-08-23 22:01:33 +08:00
|
|
|
|
# 下载基于PubTabNet数据集训练的文本识别模型并解压
|
2022-08-23 17:59:10 +08:00
|
|
|
|
wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/table/en_ppocr_mobile_v2.0_table_rec_infer.tar && tar xf en_ppocr_mobile_v2.0_table_rec_infer.tar
|
2022-08-23 22:01:33 +08:00
|
|
|
|
# 下载基于PubTabNet数据集训练的表格识别模型并解压
|
2022-08-23 17:59:10 +08:00
|
|
|
|
wget https://paddleocr.bj.bcebos.com/ppstructure/models/slanet/en_ppstructure_mobile_v2.0_SLANet_infer.tar && tar xf en_ppstructure_mobile_v2.0_SLANet_infer.tar
|
|
|
|
|
cd ..
|
|
|
|
|
|
|
|
|
|
python3 table/eval_table.py \
|
|
|
|
|
--det_model_dir=inference/en_ppocr_mobile_v2.0_table_det_infer \
|
|
|
|
|
--rec_model_dir=inference/en_ppocr_mobile_v2.0_table_rec_infer \
|
|
|
|
|
--table_model_dir=inference/en_ppstructure_mobile_v2.0_SLANet_infer \
|
|
|
|
|
--image_dir=train_data/table/pubtabnet/val/ \
|
|
|
|
|
--rec_char_dict_path=../ppocr/utils/dict/table_dict.txt \
|
|
|
|
|
--table_char_dict_path=../ppocr/utils/dict/table_structure_dict.txt \
|
|
|
|
|
--det_limit_side_len=736 \
|
|
|
|
|
--det_limit_type=min \
|
2022-09-23 17:05:27 +08:00
|
|
|
|
--rec_image_shape=3,32,320 \
|
2022-08-23 17:59:10 +08:00
|
|
|
|
--gt_path=path/to/gt.txt
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
将会输出
|
2021-08-03 15:04:24 +08:00
|
|
|
|
```bash
|
2022-08-23 17:59:10 +08:00
|
|
|
|
teds: 95.89
|
2021-08-03 15:04:24 +08:00
|
|
|
|
```
|
2022-04-19 15:08:34 +08:00
|
|
|
|
|
2022-08-16 22:21:32 +08:00
|
|
|
|
## 5. Reference
|
2021-08-03 15:30:12 +08:00
|
|
|
|
1. https://github.com/ibm-aur-nlp/PubTabNet
|
2021-12-13 15:38:05 +08:00
|
|
|
|
2. https://arxiv.org/pdf/1911.10683
|