From d1b31bf85cd6e23c8a09758ea6ca03938209ed69 Mon Sep 17 00:00:00 2001 From: WenmuZhou <572459439@qq.com> Date: Mon, 4 Jul 2022 10:22:25 +0000 Subject: [PATCH] add ref --- configs/table/table_master.yml | 64 +++++----- doc/doc_ch/algorithm_det_fcenet.md | 22 ++-- doc/doc_ch/algorithm_overview.md | 16 ++- doc/doc_ch/algorithm_table_master.md | 114 ++++++++++++++++++ doc/doc_en/algorithm_overview_en.md | 13 ++ doc/doc_en/algorithm_table_master_en.md | 112 +++++++++++++++++ ppocr/data/imaug/label_ops.py | 9 ++ ppocr/losses/table_master_loss.py | 5 + .../modeling/backbones/table_master_resnet.py | 4 + ppocr/modeling/heads/table_master_head.py | 5 + ppocr/postprocess/__init__.py | 2 +- ppstructure/docs/models_list.md | 2 +- 12 files changed, 319 insertions(+), 49 deletions(-) create mode 100644 doc/doc_ch/algorithm_table_master.md create mode 100644 doc/doc_en/algorithm_table_master_en.md diff --git a/configs/table/table_master.yml b/configs/table/table_master.yml index 9dfc0e27..cfd98346 100755 --- a/configs/table/table_master.yml +++ b/configs/table/table_master.yml @@ -2,21 +2,19 @@ Global: use_gpu: true epoch_num: 17 log_smooth_window: 20 - print_batch_step: 5 + print_batch_step: 100 save_model_dir: ./output/table_master/ save_epoch_step: 17 - # evaluation is run every 400 iterations after the 0th iteration - eval_batch_step: [0, 400] - cal_metric_during_train: True - pretrained_model: - checkpoints: - save_inference_dir: - use_visualdl: False + eval_batch_step: [0, 6259] + cal_metric_during_train: true + pretrained_model: null + checkpoints: + save_inference_dir: output/table_master/infer + use_visualdl: false infer_img: ppstructure/docs/table/table.jpg - save_res_path: output/table_master - # for data or label process + save_res_path: ./output/table_master character_dict_path: ppocr/utils/dict/table_master_structure_dict.txt - infer_mode: False + infer_mode: false max_text_length: 500 process_total_num: 0 process_cut_num: 0 @@ -33,8 +31,8 @@ Optimizer: gamma: 0.1 warmup_epoch: 0.02 regularizer: - name: 'L2' - factor: 0.00000 + name: L2 + factor: 0.0 Architecture: model_type: table @@ -67,15 +65,15 @@ PostProcess: Metric: name: TableMetric main_indicator: acc - compute_bbox_metric: true # cost many time, set False for training + compute_bbox_metric: False Train: dataset: name: PubTabDataSet - data_dir: /home/zhoujun20/table/PubTabNe/pubtabnet/train/ - label_file_list: [/home/zhoujun20/table/PubTabNe/pubtabnet/PubTabNet_2.0.0_train.jsonl] + data_dir: train_data/table/pubtabnet/train/ + label_file_list: [train_data/table/pubtabnet/PubTabNet_2.0.0_train.jsonl] transforms: - - DecodeImage: # load image + - DecodeImage: img_mode: BGR channel_first: False - TableMasterLabelEncode: @@ -88,20 +86,20 @@ Train: - PaddingTableImage: size: [480, 480] - TableBoxEncode: - use_xywh: true + use_xywh: True - NormalizeImage: scale: 1./255. mean: [0.5, 0.5, 0.5] std: [0.5, 0.5, 0.5] - order: 'hwc' - - ToCHWImage: + order: hwc + - ToCHWImage: null - KeepKeys: - keep_keys: ['image', 'structure', 'bboxes', 'bbox_masks','shape'] + keep_keys: [image, structure, bboxes, bbox_masks, shape] loader: shuffle: True - batch_size_per_card: 8 + batch_size_per_card: 10 drop_last: True - num_workers: 1 + num_workers: 8 Eval: dataset: @@ -109,7 +107,7 @@ Eval: data_dir: /home/zhoujun20/table/PubTabNe/pubtabnet/val/ label_file_list: [/home/zhoujun20/table/PubTabNe/pubtabnet/val_500.jsonl] transforms: - - DecodeImage: # load image + - DecodeImage: img_mode: BGR channel_first: False - TableMasterLabelEncode: @@ -120,19 +118,19 @@ Eval: max_len: 480 resize_bboxes: True - PaddingTableImage: - size: [ 480, 480 ] + size: [480, 480] - TableBoxEncode: - use_xywh: true + use_xywh: True - NormalizeImage: scale: 1./255. - mean: [ 0.5, 0.5, 0.5 ] - std: [ 0.5, 0.5, 0.5 ] - order: 'hwc' - - ToCHWImage: + mean: [0.5, 0.5, 0.5] + std: [0.5, 0.5, 0.5] + order: hwc + - ToCHWImage: null - KeepKeys: - keep_keys: [ 'image', 'structure', 'bboxes', 'bbox_masks','shape' ] + keep_keys: [image, structure, bboxes, bbox_masks, shape] loader: shuffle: False drop_last: False - batch_size_per_card: 2 - num_workers: 8 + batch_size_per_card: 10 + num_workers: 8 \ No newline at end of file diff --git a/doc/doc_ch/algorithm_det_fcenet.md b/doc/doc_ch/algorithm_det_fcenet.md index bd2e7342..a70caa29 100644 --- a/doc/doc_ch/algorithm_det_fcenet.md +++ b/doc/doc_ch/algorithm_det_fcenet.md @@ -1,17 +1,15 @@ # FCENet -- [1. 算法简介](#1) -- [2. 环境é…ç½®](#2) -- [3. 模型è®ç»ƒã€è¯„ä¼°ã€é¢„测](#3) - - [3.1 è®ç»ƒ](#3-1) - - [3.2 评估](#3-2) - - [3.3 预测](#3-3) -- [4. 推ç†éƒ¨ç½²](#4) - - [4.1 Python推ç†](#4-1) - - [4.2 C++推ç†](#4-2) - - [4.3 ServingæœåŠ¡åŒ–部署](#4-3) - - [4.4 更多推ç†éƒ¨ç½²](#4-4) -- [5. FAQ](#5) +- [1. 算法简介](#1-算法简介) +- [2. 环境é…ç½®](#2-环境é…ç½®) +- [3. 模型è®ç»ƒã€è¯„ä¼°ã€é¢„测](#3-模型è®ç»ƒè¯„估预测) +- [4. 推ç†éƒ¨ç½²](#4-推ç†éƒ¨ç½²) + - [4.1 Python推ç†](#41-python推ç†) + - [4.2 C++推ç†](#42-c推ç†) + - [4.3 ServingæœåŠ¡åŒ–部署](#43-servingæœåŠ¡åŒ–部署) + - [4.4 更多推ç†éƒ¨ç½²](#44-更多推ç†éƒ¨ç½²) +- [5. FAQ](#5-faq) +- [引用](#引用) <a name="1"></a> ## 1. 算法简介 diff --git a/doc/doc_ch/algorithm_overview.md b/doc/doc_ch/algorithm_overview.md index ef96f6ec..84af5fdc 100755 --- a/doc/doc_ch/algorithm_overview.md +++ b/doc/doc_ch/algorithm_overview.md @@ -1,9 +1,10 @@ # OCR算法 - [1. 两阶段算法](#1-两阶段算法) - - [1.1 文本检测算法](#11-文本检测算法) - - [1.2 文本识别算法](#12-文本识别算法) + - [1.1 文本检测算法](#11-文本检测算法) + - [1.2 文本识别算法](#12-文本识别算法) - [2. 端到端算法](#2-端到端算法) +- [3. è¡¨æ ¼è¯†åˆ«ç®—æ³•](#3-è¡¨æ ¼è¯†åˆ«ç®—æ³•) 本文给出了PaddleOCR已支æŒçš„OCR算法列表,以åŠæ¯ä¸ªç®—法在**英文公开数æ®é›†**ä¸Šçš„æ¨¡åž‹å’ŒæŒ‡æ ‡ï¼Œä¸»è¦ç”¨äºŽç®—法简介和算法性能对比,更多包括ä¸æ–‡åœ¨å†…的其他数æ®é›†ä¸Šçš„模型请å‚考[PP-OCR v2.0 系列模型下载](./models_list.md)。 @@ -96,3 +97,14 @@ 已支æŒçš„端到端OCR算法列表(戳链接获å–使用教程): - [x] [PGNet](./algorithm_e2e_pgnet.md) + +## 3. è¡¨æ ¼è¯†åˆ«ç®—æ³• + +已支æŒçš„è¡¨æ ¼è¯†åˆ«ç®—æ³•åˆ—è¡¨ï¼ˆæˆ³é“¾æŽ¥èŽ·å–使用教程): +- [x] [TableMaster](./algorithm_table_master.md) + +在PubTabNetè¡¨æ ¼è¯†åˆ«å…¬å¼€æ•°æ®é›†ä¸Šï¼Œç®—法效果如下: + +|模型|骨干网络|é…置文件|acc|下载链接| +|---|---|---|---|---| +|TableMaster|TableResNetExtra|[configs/table/table_master.yml](../../configs/table/table_master.yml)|77.47%|[è®ç»ƒæ¨¡åž‹]|[è®ç»ƒæ¨¡åž‹](https://paddleocr.bj.bcebos.com/ppstructure/models/tablemaster/table_structure_tablemaster_train.tar)/[推ç†æ¨¡åž‹](https://paddleocr.bj.bcebos.com/ppstructure/models/tablemaster/table_structure_tablemaster_infer.tar)| diff --git a/doc/doc_ch/algorithm_table_master.md b/doc/doc_ch/algorithm_table_master.md new file mode 100644 index 00000000..6bfd0f36 --- /dev/null +++ b/doc/doc_ch/algorithm_table_master.md @@ -0,0 +1,114 @@ +# è¡¨æ ¼è¯†åˆ«ç®—æ³•-TableMASTER + +- [1. 算法简介](#1-算法简介) +- [2. 环境é…ç½®](#2-环境é…ç½®) +- [3. 模型è®ç»ƒã€è¯„ä¼°ã€é¢„测](#3-模型è®ç»ƒè¯„估预测) +- [4. 推ç†éƒ¨ç½²](#4-推ç†éƒ¨ç½²) + - [4.1 Python推ç†](#41-python推ç†) + - [4.2 C++推ç†éƒ¨ç½²](#42-c推ç†éƒ¨ç½²) + - [4.3 ServingæœåŠ¡åŒ–部署](#43-servingæœåŠ¡åŒ–部署) + - [4.4 更多推ç†éƒ¨ç½²](#44-更多推ç†éƒ¨ç½²) +- [5. FAQ](#5-faq) +- [引用](#引用) + +<a name="1"></a> +## 1. 算法简介 + +论文信æ¯ï¼š +> [TableMaster: PINGAN-VCGROUP’S SOLUTION FOR ICDAR 2021 COMPETITION ON SCIENTIFIC LITERATURE PARSING TASK B: TABLE RECOGNITION TO HTML](https://arxiv.org/pdf/2105.01848.pdf) +> Ye, Jiaquan and Qi, Xianbiao and He, Yelin and Chen, Yihao and Gu, Dengyi and Gao, Peng and Xiao, Rong +> 2021 + +在PubTabNetè¡¨æ ¼è¯†åˆ«å…¬å¼€æ•°æ®é›†ä¸Šï¼Œç®—法å¤çŽ°æ•ˆæžœå¦‚下: + +|模型|骨干网络|é…置文件|acc|下载链接| +| --- | --- | --- | --- | --- | +|TableMaster|TableResNetExtra|[configs/table/table_master.yml](../../configs/table/table_master.yml)|77.47%|[è®ç»ƒæ¨¡åž‹](https://paddleocr.bj.bcebos.com/ppstructure/models/tablemaster/table_structure_tablemaster_train.tar)/[推ç†æ¨¡åž‹](https://paddleocr.bj.bcebos.com/ppstructure/models/tablemaster/table_structure_tablemaster_infer.tar)| + + +<a name="2"></a> +## 2. 环境é…ç½® +请先å‚考[《è¿è¡ŒçŽ¯å¢ƒå‡†å¤‡ã€‹](./environment.md)é…ç½®PaddleOCRè¿è¡ŒçŽ¯å¢ƒï¼Œå‚考[《项目克隆》](./clone.md)克隆项目代ç 。 + + +<a name="3"></a> +## 3. 模型è®ç»ƒã€è¯„ä¼°ã€é¢„测 + +上述TableMaster模型使用PubTabNetè¡¨æ ¼è¯†åˆ«å…¬å¼€æ•°æ®é›†è®ç»ƒå¾—到,数æ®é›†ä¸‹è½½å¯å‚考 [table_datasets](./dataset/table_datasets.md)。 + +æ•°æ®ä¸‹è½½å®ŒæˆåŽï¼Œè¯·å‚考[文本识别教程](./recognition.md)进行è®ç»ƒã€‚PaddleOCR对代ç 进行了模å—化,è®ç»ƒä¸åŒçš„模型åªéœ€è¦**æ›´æ¢é…置文件**å³å¯ã€‚ + +<a name="4"></a> +## 4. 推ç†éƒ¨ç½² + +<a name="4-1"></a> +### 4.1 PythonæŽ¨ç† +首先将è®ç»ƒå¾—到best模型,转æ¢æˆinference model。以基于TableResNetExtra骨干网络,在PubTabNetæ•°æ®é›†è®ç»ƒçš„模型为例([模型下载地å€](https://paddleocr.bj.bcebos.com/contribution/table_master.tar)),å¯ä»¥ä½¿ç”¨å¦‚下命令进行转æ¢ï¼š + +```shell +# 注æ„å°†pretrained_model的路径设置为本地路径。 +python3 tools/export_model.py -c configs/table/table_master.yml -o Global.pretrained_model=output/table_master/best_accuracy Global.save_inference_dir=./inference/table_master +``` + +**注æ„:** +- 如果您是在自己的数æ®é›†ä¸Šè®ç»ƒçš„模型,并且调整了å—典文件,请注æ„修改é…置文件ä¸çš„`character_dict_path`是å¦ä¸ºæ‰€æ£ç¡®çš„å—典文件。 + +转æ¢æˆåŠŸåŽï¼Œåœ¨ç›®å½•ä¸‹æœ‰ä¸‰ä¸ªæ–‡ä»¶ï¼š +``` +/inference/table_master/ + ├── inference.pdiparams # 识别inference模型的å‚数文件 + ├── inference.pdiparams.info # 识别inference模型的å‚æ•°ä¿¡æ¯ï¼Œå¯å¿½ç•¥ + └── inference.pdmodel # 识别inference模型的program文件 +``` + + +执行如下命令进行模型推ç†ï¼š + +```shell +cd ppstructure/ +python3.7 table/predict_structure.py --table_model_dir=../output/table_master/table_structure_tablemaster_infer/ --table_algorithm=TableMaster --table_char_dict_path=../ppocr/utils/dict/table_master_structure_dict.txt --table_max_len=480 --image_dir=docs/table/table.jpg +# 预测文件夹下所有图åƒæ—¶ï¼Œå¯ä¿®æ”¹image_dir为文件夹,如 --image_dir='docs/table'。 +``` + +执行命令åŽï¼Œä¸Šé¢å›¾åƒçš„预测结果(结构信æ¯å’Œè¡¨æ ¼ä¸æ¯ä¸ªå•å…ƒæ ¼çš„åæ ‡ï¼‰ä¼šæ‰“å°åˆ°å±å¹•ä¸Šï¼ŒåŒæ—¶ä¼šä¿å˜å•å…ƒæ ¼åæ ‡çš„å¯è§†åŒ–结果。示例如下: +结果如下: +```shell +[2022/06/16 13:06:54] ppocr INFO: result: ['<html>', '<body>', '<table>', '<thead>', '<tr>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '</tr>', '</thead>', '<tbody>', '<tr>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '</tr>', '<tr>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '</tr>', '<tr>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '</tr>', '<tr>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '</tr>', '<tr>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '</tr>', '<tr>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '</tr>', '<tr>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '</tr>', '<tr>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '</tr>', '<tr>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '</tr>', '<tr>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '</tr>', '<tr>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '</tr>', '<tr>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '</tr>', '<tr>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '</tr>', '<tr>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '</tr>', '<tr>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '</tr>', '</tbody>', '</table>', '</body>', '</html>'], [[72.17591094970703, 10.759100914001465, 60.29658508300781, 16.6805362701416], [161.85562133789062, 10.884308815002441, 14.9495210647583, 16.727018356323242], [277.79876708984375, 29.54340362548828, 31.490320205688477, 18.143272399902344], +... +[336.11724853515625, 280.3601989746094, 39.456939697265625, 18.121286392211914]] +[2022/06/16 13:06:54] ppocr INFO: save vis result to ./output/table.jpg +[2022/06/16 13:06:54] ppocr INFO: Predict time of docs/table/table.jpg: 17.36806297302246 +``` + +**注æ„**: + +- TableMaster在推ç†æ—¶æ¯”较慢,建议使用GPU进行使用。 + +<a name="4-2"></a> +### 4.2 C++推ç†éƒ¨ç½² + +由于C++预处ç†åŽå¤„ç†è¿˜æœªæ”¯æŒTableMasterï¼Œæ‰€ä»¥æš‚æœªæ”¯æŒ + +<a name="4-3"></a> +### 4.3 ServingæœåŠ¡åŒ–部署 + +æš‚ä¸æ”¯æŒ + +<a name="4-4"></a> +### 4.4 更多推ç†éƒ¨ç½² + +æš‚ä¸æ”¯æŒ + +<a name="5"></a> +## 5. FAQ + +## 引用 + +```bibtex +@article{ye2021pingan, + title={PingAn-VCGroup's Solution for ICDAR 2021 Competition on Scientific Literature Parsing Task B: Table Recognition to HTML}, + author={Ye, Jiaquan and Qi, Xianbiao and He, Yelin and Chen, Yihao and Gu, Dengyi and Gao, Peng and Xiao, Rong}, + journal={arXiv preprint arXiv:2105.01848}, + year={2021} +} +``` diff --git a/doc/doc_en/algorithm_overview_en.md b/doc/doc_en/algorithm_overview_en.md index bc96cdf2..cd277c74 100755 --- a/doc/doc_en/algorithm_overview_en.md +++ b/doc/doc_en/algorithm_overview_en.md @@ -4,6 +4,7 @@ * [1.1 Text Detection Algorithms](#11) * [1.2 Text Recognition Algorithms](#12) - [2. End-to-end Algorithms](#2) +- [3. Table Recognition Algorithms](#3) This tutorial lists the OCR algorithms supported by PaddleOCR, as well as the models and metrics of each algorithm on **English public datasets**. It is mainly used for algorithm introduction and algorithm performance comparison. For more models on other datasets including Chinese, please refer to [PP-OCR v2.0 models list](./models_list_en.md). @@ -95,3 +96,15 @@ Refer to [DTRB](https://arxiv.org/abs/1904.01906), the training and evaluation r Supported end-to-end algorithms (Click the link to get the tutorial): - [x] [PGNet](./algorithm_e2e_pgnet_en.md) + +<a name="3"></a> +## 3. Table Recognition Algorithms + +Supported table recognition algorithms (Click the link to get the tutorial): +- [x] [TableMaster](./algorithm_table_master_en.md) + +On the PubTabNet dataset, the algorithm result is as follows: + +|Model|Backbone|Config|Acc|Download link| +|---|---|---|---|---| +|TableMaster|TableResNetExtra|[configs/table/table_master.yml](../../configs/table/table_master.yml)|77.47%|[è®ç»ƒæ¨¡åž‹]|[è®ç»ƒæ¨¡åž‹](https://paddleocr.bj.bcebos.com/ppstructure/models/tablemaster/table_structure_tablemaster_train.tar)/[推ç†æ¨¡åž‹](https://paddleocr.bj.bcebos.com/ppstructure/models/tablemaster/table_structure_tablemaster_infer.tar)| diff --git a/doc/doc_en/algorithm_table_master_en.md b/doc/doc_en/algorithm_table_master_en.md new file mode 100644 index 00000000..a557a609 --- /dev/null +++ b/doc/doc_en/algorithm_table_master_en.md @@ -0,0 +1,112 @@ +# Torm Recognition Algorithm-TableMASTER + +- [1. Introduction](#1-introduction) +- [2. Environment](#2-environment) +- [3. Model Training / Evaluation / Prediction](#3-model-training--evaluation--prediction) +- [4. Inference and Deployment](#4-inference-and-deployment) + - [4.1 Python Inference](#41-python-inference) + - [4.2 C++ Inference](#42-c-inference) + - [4.3 Serving](#43-serving) + - [4.4 More](#44-more) +- [5. FAQ](#5-faq) +- [Citation](#citation) + +<a name="1"></a> +## 1. Introduction + +Paper: +> [TableMaster: PINGAN-VCGROUP’S SOLUTION FOR ICDAR 2021 COMPETITION ON SCIENTIFIC LITERATURE PARSING TASK B: TABLE RECOGNITION TO HTML](https://arxiv.org/pdf/2105.01848.pdf) +> Ye, Jiaquan and Qi, Xianbiao and He, Yelin and Chen, Yihao and Gu, Dengyi and Gao, Peng and Xiao, Rong +> 2021 + + +On the PubTabNet table recognition public data set, the algorithm reproduction acc is as follows: + +|Model|Backbone|Cnnfig|Acc|Download link| +| --- | --- | --- | --- | --- | +|TableMaster|TableResNetExtra|[configs/table/table_master.yml](../../configs/table/table_master.yml)|77.47%|[train model](https://paddleocr.bj.bcebos.com/ppstructure/models/tablemaster/table_structure_tablemaster_train.tar)/[inference model](https://paddleocr.bj.bcebos.com/ppstructure/models/tablemaster/table_structure_tablemaster_infer.tar)| + + +<a name="2"></a> +## 2. Environment +Please refer to ["Environment Preparation"](./environment_en.md) to configure the PaddleOCR environment, and refer to ["Project Clone"](./clone_en.md) to clone the project code. + + +<a name="3"></a> +## 3. Model Training / Evaluation / Prediction + +The above TableMaster model is trained using the PubTabNet table recognition public dataset. For the download of the dataset, please refer to [table_datasets](./dataset/table_datasets_en.md). + +After the data download is complete, please refer to [Text Recognition Training Tutorial](./recognition_en.md) for training. PaddleOCR has modularized the code structure, so that you only need to **replace the configuration file** to train different models. + + +<a name="4"></a> +## 4. Inference and Deployment + +<a name="4-1"></a> +### 4.1 Python Inference + +First, convert the model saved in the TableMaster table recognition training process into an inference model. Taking the model based on the TableResNetExtra backbone network and trained on the PubTabNet dataset as example ([model download link](https://paddleocr.bj.bcebos.com/contribution/table_master.tar)), you can use the following command to convert: + + +```shell +python3 tools/export_model.py -c configs/table/table_master.yml -o Global.pretrained_model=output/table_master/best_accuracy Global.save_inference_dir=./inference/table_master +``` + +**Note: ** +- If you trained the model on your own dataset and adjusted the dictionary file, please pay attention to whether the `character_dict_path` in the modified configuration file is the correct dictionary file + + +Execute the following command for model inference: + +```shell +cd ppstructure/ +# When predicting all images in a folder, you can modify image_dir to a folder, such as --image_dir='docs/table'. +python3.7 table/predict_structure.py --table_model_dir=../output/table_master/table_structure_tablemaster_infer/ --table_algorithm=TableMaster --table_char_dict_path=../ppocr/utils/dict/table_master_structure_dict.txt --table_max_len=480 --image_dir=docs/table/table.jpg + +``` + +After executing the command, the prediction results of the above image (structural information and the coordinates of each cell in the table) are printed to the screen, and the visualization of the cell coordinates is also saved. An example is as follows: + +result: +```shell +[2022/06/16 13:06:54] ppocr INFO: result: ['<html>', '<body>', '<table>', '<thead>', '<tr>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '</tr>', '</thead>', '<tbody>', '<tr>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '</tr>', '<tr>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '</tr>', '<tr>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '</tr>', '<tr>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '</tr>', '<tr>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '</tr>', '<tr>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '</tr>', '<tr>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '</tr>', '<tr>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '</tr>', '<tr>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '</tr>', '<tr>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '</tr>', '<tr>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '</tr>', '<tr>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '</tr>', '<tr>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '</tr>', '<tr>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '</tr>', '<tr>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '</tr>', '</tbody>', '</table>', '</body>', '</html>'], [[72.17591094970703, 10.759100914001465, 60.29658508300781, 16.6805362701416], [161.85562133789062, 10.884308815002441, 14.9495210647583, 16.727018356323242], [277.79876708984375, 29.54340362548828, 31.490320205688477, 18.143272399902344], +... +[336.11724853515625, 280.3601989746094, 39.456939697265625, 18.121286392211914]] +[2022/06/16 13:06:54] ppocr INFO: save vis result to ./output/table.jpg +[2022/06/16 13:06:54] ppocr INFO: Predict time of docs/table/table.jpg: 17.36806297302246 +``` + +**Note**: + +- TableMaster is relatively slow during inference, and it is recommended to use GPU for use. + +<a name="4-2"></a> +### 4.2 C++ Inference + +Since the post-processing is not written in CPP, the TableMaster does not support CPP inference. + + +<a name="4-3"></a> +### 4.3 Serving + +Not supported + +<a name="4-4"></a> +### 4.4 More + +Not supported + +<a name="5"></a> +## 5. FAQ + +## Citation + +```bibtex +@article{ye2021pingan, + title={PingAn-VCGroup's Solution for ICDAR 2021 Competition on Scientific Literature Parsing Task B: Table Recognition to HTML}, + author={Ye, Jiaquan and Qi, Xianbiao and He, Yelin and Chen, Yihao and Gu, Dengyi and Gao, Peng and Xiao, Rong}, + journal={arXiv preprint arXiv:2105.01848}, + year={2021} +} +``` diff --git a/ppocr/data/imaug/label_ops.py b/ppocr/data/imaug/label_ops.py index 00792701..96f3c986 100644 --- a/ppocr/data/imaug/label_ops.py +++ b/ppocr/data/imaug/label_ops.py @@ -670,6 +670,10 @@ class TableLabelEncode(AttnLabelEncode): return data def _merge_no_span_structure(self, structure): + """ + This fun code is refer from: + https://github.com/JiaquanYe/TableMASTER-mmocr/blob/master/table_recognition/data_preprocess.py + """ new_structure = [] i = 0 while i < len(structure): @@ -682,6 +686,11 @@ class TableLabelEncode(AttnLabelEncode): return new_structure def _replace_empty_cell_token(self, token_list, cells): + """ + This fun code is refer from: + https://github.com/JiaquanYe/TableMASTER-mmocr/blob/master/table_recognition/data_preprocess.py + """ + bbox_idx = 0 add_empty_bbox_token_list = [] for token in token_list: diff --git a/ppocr/losses/table_master_loss.py b/ppocr/losses/table_master_loss.py index 50a773dd..216c4e52 100644 --- a/ppocr/losses/table_master_loss.py +++ b/ppocr/losses/table_master_loss.py @@ -11,6 +11,11 @@ # 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. +""" +This fun code is refer from: +https://github.com/JiaquanYe/TableMASTER-mmocr/tree/master/mmocr/models/textrecog/losses +""" + import paddle from paddle import nn diff --git a/ppocr/modeling/backbones/table_master_resnet.py b/ppocr/modeling/backbones/table_master_resnet.py index 82b4f37a..f1c506ca 100644 --- a/ppocr/modeling/backbones/table_master_resnet.py +++ b/ppocr/modeling/backbones/table_master_resnet.py @@ -11,6 +11,10 @@ # 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. +""" +This fun code is refer from: +https://github.com/JiaquanYe/TableMASTER-mmocr/blob/master/mmocr/models/textrecog/backbones/table_resnet_extra.py +""" import paddle import paddle.nn as nn diff --git a/ppocr/modeling/heads/table_master_head.py b/ppocr/modeling/heads/table_master_head.py index 4da6e9b5..887630a8 100644 --- a/ppocr/modeling/heads/table_master_head.py +++ b/ppocr/modeling/heads/table_master_head.py @@ -11,6 +11,11 @@ # 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. +""" +This fun code is refer from: +https://github.com/JiaquanYe/TableMASTER-mmocr/blob/master/mmocr/models/textrecog/decoders/master_decoder.py +""" + import copy import math import paddle diff --git a/ppocr/postprocess/__init__.py b/ppocr/postprocess/__init__.py index 26a23f1e..1d414eb2 100644 --- a/ppocr/postprocess/__init__.py +++ b/ppocr/postprocess/__init__.py @@ -26,7 +26,7 @@ from .east_postprocess import EASTPostProcess from .sast_postprocess import SASTPostProcess from .fce_postprocess import FCEPostProcess from .rec_postprocess import CTCLabelDecode, AttnLabelDecode, SRNLabelDecode, \ - DistillationCTCLabelDecode, TableLabelDecode, NRTRLabelDecode, SARLabelDecode, \ + DistillationCTCLabelDecode, NRTRLabelDecode, SARLabelDecode, \ SEEDLabelDecode, PRENLabelDecode, ViTSTRLabelDecode, ABINetLabelDecode from .cls_postprocess import ClsPostProcess from .pg_postprocess import PGPostProcess diff --git a/ppstructure/docs/models_list.md b/ppstructure/docs/models_list.md index dabce3a5..42d44009 100644 --- a/ppstructure/docs/models_list.md +++ b/ppstructure/docs/models_list.md @@ -35,7 +35,7 @@ |模型å称|模型简介|推ç†æ¨¡åž‹å¤§å°|下载地å€| | --- | --- | --- | --- | -|en_ppocr_mobile_v2.0_table_structure|PubLayNetæ•°æ®é›†è®ç»ƒçš„è‹±æ–‡è¡¨æ ¼åœºæ™¯çš„è¡¨æ ¼ç»“æž„é¢„æµ‹|18.6M|[推ç†æ¨¡åž‹](https://paddleocr.bj.bcebos.com/dygraph_v2.0/table/en_ppocr_mobile_v2.0_table_structure_infer.tar) / [è®ç»ƒæ¨¡åž‹](https://paddleocr.bj.bcebos.com/dygraph_v2.1/table/en_ppocr_mobile_v2.0_table_structure_train.tar) | +|en_ppocr_mobile_v2.0_table_structure|PubTabNetæ•°æ®é›†è®ç»ƒçš„è‹±æ–‡è¡¨æ ¼åœºæ™¯çš„è¡¨æ ¼ç»“æž„é¢„æµ‹|18.6M|[推ç†æ¨¡åž‹](https://paddleocr.bj.bcebos.com/dygraph_v2.0/table/en_ppocr_mobile_v2.0_table_structure_infer.tar) / [è®ç»ƒæ¨¡åž‹](https://paddleocr.bj.bcebos.com/dygraph_v2.1/table/en_ppocr_mobile_v2.0_table_structure_train.tar) | <a name="3"></a> ## 3. VQA模型 -- GitLab