mirror of
https://github.com/PaddlePaddle/PaddleOCR.git
synced 2026-01-08 04:56:10 +00:00
update
This commit is contained in:
parent
13221eaea3
commit
6a8980e478
@ -1,4 +1,8 @@
|
||||
# 1 项目说明
|
||||
# 多模态表单识别
|
||||
|
||||
[TOC]
|
||||
|
||||
## 1 项目说明
|
||||
|
||||
计算机视觉在金融领域的应用覆盖文字识别、图像识别、视频识别等,其中文字识别(OCR)是金融领域中的核心AI能力,其应用覆盖客户服务、风险防控、运营管理等各项业务,针对的对象包括通用卡证票据识别(银行卡、身份证、营业执照等)、通用文本表格识别(印刷体、多语言、手写体等)以及一些金融特色票据凭证。通过因此如果能够在结构化信息提取时同时利用文字、页面布局等信息,便可增强不同版式下的泛化性。
|
||||
|
||||
@ -16,39 +20,37 @@
|
||||
<center><img src='https://ai-studio-static-online.cdn.bcebos.com/9bd844b970f94e5ba0bc0c5799bd819ea9b1861bb306471fabc2d628864d418e'></center>
|
||||
<center>图1 多模态表单识别流程图</center>
|
||||
|
||||
注:欢迎再AIStudio领取免费算力体验线上实训,项目链接: [多模态表单识别](https://aistudio.baidu.com/aistudio/projectdetail/3884375)(配备Tesla V100、A100等高级算力资源)
|
||||
注:欢迎再AIStudio领取免费算力体验线上实训,项目链接: [多模态表单识别](https://aistudio.baidu.com/aistudio/projectdetail/3884375?contributionType=1)
|
||||
|
||||
|
||||
|
||||
# 2 安装说明
|
||||
## 2 安装说明
|
||||
|
||||
|
||||
下载PaddleOCR源码,上述AIStudio项目中已经帮大家打包好的PaddleOCR(已经修改好配置文件),无需下载解压即可,只需安装依赖环境~
|
||||
|
||||
|
||||
```python
|
||||
! unzip -q PaddleOCR.zip
|
||||
unzip -q PaddleOCR.zip
|
||||
```
|
||||
|
||||
|
||||
```python
|
||||
# 如仍需安装or安装更新,可以执行以下步骤
|
||||
# ! git clone https://github.com/PaddlePaddle/PaddleOCR.git -b dygraph
|
||||
# ! git clone https://gitee.com/PaddlePaddle/PaddleOCR
|
||||
# git clone https://github.com/PaddlePaddle/PaddleOCR.git -b dygraph
|
||||
# git clone https://gitee.com/PaddlePaddle/PaddleOCR
|
||||
```
|
||||
|
||||
|
||||
```python
|
||||
# 安装依赖包
|
||||
! pip install -U pip
|
||||
! pip install -r /home/aistudio/PaddleOCR/requirements.txt
|
||||
! pip install paddleocr
|
||||
pip install -U pip
|
||||
pip install -r /home/aistudio/PaddleOCR/requirements.txt
|
||||
pip install paddleocr
|
||||
|
||||
! pip install yacs gnureadline paddlenlp==2.2.1
|
||||
! pip install xlsxwriter
|
||||
pip install yacs gnureadline paddlenlp==2.2.1
|
||||
pip install xlsxwriter
|
||||
```
|
||||
|
||||
# 3 数据准备
|
||||
## 3 数据准备
|
||||
|
||||
这里使用[XFUN数据集](https://github.com/doc-analysis/XFUND)做为实验数据集。 XFUN数据集是微软提出的一个用于KIE任务的多语言数据集,共包含七个数据集,每个数据集包含149张训练集和50张验证集
|
||||
|
||||
@ -59,7 +61,7 @@
|
||||
<center><img src="https://ai-studio-static-online.cdn.bcebos.com/0f84137778cd4ab6899c64109d452290e9c678ccf01744978bc9c0647adbba45" width="1000" ></center>
|
||||
<center>图2 数据集样例,左中文,右法语</center>
|
||||
|
||||
## 3.1 下载处理好的数据集
|
||||
### 3.1 下载处理好的数据集
|
||||
|
||||
|
||||
处理好的XFUND中文数据集下载地址:[https://paddleocr.bj.bcebos.com/dataset/XFUND.tar](https://paddleocr.bj.bcebos.com/dataset/XFUND.tar) ,可以运行如下指令完成中文数据集下载和解压。
|
||||
@ -69,13 +71,13 @@
|
||||
|
||||
|
||||
```python
|
||||
! wget https://paddleocr.bj.bcebos.com/dataset/XFUND.tar
|
||||
! tar -xf XFUND.tar
|
||||
wget https://paddleocr.bj.bcebos.com/dataset/XFUND.tar
|
||||
tar -xf XFUND.tar
|
||||
|
||||
# XFUN其他数据集使用下面的代码进行转换
|
||||
# 代码链接:https://github.com/PaddlePaddle/PaddleOCR/blob/release%2F2.4/ppstructure/vqa/helper/trans_xfun_data.py
|
||||
# %cd PaddleOCR
|
||||
# !python3 ppstructure/vqa/tools/trans_xfun_data.py --ori_gt_path=path/to/json_path --output_path=path/to/save_path
|
||||
# python3 ppstructure/vqa/tools/trans_xfun_data.py --ori_gt_path=path/to/json_path --output_path=path/to/save_path
|
||||
# %cd ../
|
||||
```
|
||||
|
||||
@ -119,7 +121,7 @@
|
||||
}
|
||||
```
|
||||
|
||||
## 3.2 转换为PaddleOCR检测和识别格式
|
||||
### 3.2 转换为PaddleOCR检测和识别格式
|
||||
|
||||
使用XFUND训练PaddleOCR检测和识别模型,需要将数据集格式改为训练需求的格式。
|
||||
|
||||
@ -147,7 +149,7 @@ train_data/rec/train/word_002.jpg 用科技让复杂的世界更简单
|
||||
|
||||
|
||||
```python
|
||||
! unzip -q /home/aistudio/data/data140302/XFUND_ori.zip -d /home/aistudio/data/data140302/
|
||||
unzip -q /home/aistudio/data/data140302/XFUND_ori.zip -d /home/aistudio/data/data140302/
|
||||
```
|
||||
|
||||
已经提供转换脚本,执行如下代码即可转换成功:
|
||||
@ -155,21 +157,20 @@ train_data/rec/train/word_002.jpg 用科技让复杂的世界更简单
|
||||
|
||||
```python
|
||||
%cd /home/aistudio/
|
||||
! python trans_xfund_data.py
|
||||
python trans_xfund_data.py
|
||||
```
|
||||
|
||||
# 4 OCR
|
||||
## 4 OCR
|
||||
|
||||
选用飞桨OCR开发套件[PaddleOCR](https://github.com/PaddlePaddle/PaddleOCR/blob/dygraph/README_ch.md)中的PP-OCRv2模型进行文本检测和识别。PP-OCRv2在PP-OCR的基础上,进一步在5个方面重点优化,检测模型采用CML协同互学习知识蒸馏策略和CopyPaste数据增广策略;识别模型采用LCNet轻量级骨干网络、UDML 改进知识蒸馏策略和[Enhanced CTC loss](https://github.com/PaddlePaddle/PaddleOCR/blob/dygraph/doc/doc_ch/enhanced_ctc_loss.md)损失函数改进,进一步在推理速度和预测效果上取得明显提升。更多细节请参考PP-OCRv2[技术报告](https://arxiv.org/abs/2109.03144)。
|
||||
|
||||
|
||||
## 4.1 文本检测
|
||||
### 4.1 文本检测
|
||||
|
||||
我们使用2种方案进行训练、评估:
|
||||
- **PP-OCRv2中英文超轻量检测预训练模型**
|
||||
- **XFUND数据集+fine-tune**
|
||||
|
||||
### **4.1.1 方案1:预训练模型**
|
||||
#### **4.1.1 方案1:预训练模型**
|
||||
|
||||
**1)下载预训练模型**
|
||||
|
||||
@ -195,8 +196,8 @@ PaddleOCR已经提供了PP-OCR系列模型,部分模型展示如下表所示
|
||||
|
||||
```python
|
||||
%cd /home/aistudio/PaddleOCR/pretrain/
|
||||
! wget https://paddleocr.bj.bcebos.com/PP-OCRv2/chinese/ch_PP-OCRv2_det_distill_train.tar
|
||||
! tar -xf ch_PP-OCRv2_det_distill_train.tar && rm -rf ch_PP-OCRv2_det_distill_train.tar
|
||||
wget https://paddleocr.bj.bcebos.com/PP-OCRv2/chinese/ch_PP-OCRv2_det_distill_train.tar
|
||||
tar -xf ch_PP-OCRv2_det_distill_train.tar && rm -rf ch_PP-OCRv2_det_distill_train.tar
|
||||
% cd ..
|
||||
```
|
||||
|
||||
@ -226,7 +227,7 @@ Eval.dataset.label_file_list:指向验证集标注文件
|
||||
|
||||
```python
|
||||
%cd /home/aistudio/PaddleOCR
|
||||
! python tools/eval.py \
|
||||
python tools/eval.py \
|
||||
-c configs/det/ch_PP-OCRv2/ch_PP-OCRv2_det_distill.yml \
|
||||
-o Global.checkpoints="./pretrain_models/ch_PP-OCRv2_det_distill_train/best_accuracy"
|
||||
```
|
||||
@ -237,9 +238,9 @@ Eval.dataset.label_file_list:指向验证集标注文件
|
||||
| -------- | -------- |
|
||||
| PP-OCRv2中英文超轻量检测预训练模型 | 77.26% |
|
||||
|
||||
使用文本检测预训练模型在XFUND验证集上评估,达到77%左右,充分说明ppocr提供的预训练模型有一定的泛化能力。
|
||||
使用文本检测预训练模型在XFUND验证集上评估,达到77%左右,充分说明ppocr提供的预训练模型具有泛化能力。
|
||||
|
||||
### **4.1.2 方案2:XFUND数据集+fine-tune**
|
||||
#### **4.1.2 方案2:XFUND数据集+fine-tune**
|
||||
|
||||
PaddleOCR提供的蒸馏预训练模型包含了多个模型的参数,我们提取Student模型的参数,在XFUND数据集上进行finetune,可以参考如下代码:
|
||||
|
||||
@ -281,7 +282,7 @@ Eval.dataset.transforms.DetResizeForTest:评估尺寸,添加如下参数
|
||||
|
||||
|
||||
```python
|
||||
! CUDA_VISIBLE_DEVICES=0 python tools/train.py \
|
||||
CUDA_VISIBLE_DEVICES=0 python tools/train.py \
|
||||
-c configs/det/ch_PP-OCRv2/ch_PP-OCRv2_det_student.yml
|
||||
```
|
||||
|
||||
@ -290,12 +291,12 @@ Eval.dataset.transforms.DetResizeForTest:评估尺寸,添加如下参数
|
||||
<center><img src="https://ai-studio-static-online.cdn.bcebos.com/5a75137c5f924dfeb6956b5818812298cc3dc7992ac84954b4175be9adf83c77"></center>
|
||||
<center>图8 文本检测方案2-模型评估</center>
|
||||
|
||||
使用训练好的模型进行评估,更新模型路径`Global.checkpoints`,这里为大家提供训练好的模型`./pretrain/ch_db_mv3-student1600-finetune/best_accuracy`,[模型下载地址](https://paddleocr.bj.bcebos.com/fanliku/sheet_recognition/ch_db_mv3-student1600-finetune.zip)
|
||||
使用训练好的模型进行评估,更新模型路径`Global.checkpoints`。
|
||||
|
||||
|
||||
```python
|
||||
%cd /home/aistudio/PaddleOCR/
|
||||
! python tools/eval.py \
|
||||
python tools/eval.py \
|
||||
-c configs/det/ch_PP-OCRv2/ch_PP-OCRv2_det_student.yml \
|
||||
-o Global.checkpoints="pretrain/ch_db_mv3-student1600-finetune/best_accuracy"
|
||||
```
|
||||
@ -305,7 +306,7 @@ Eval.dataset.transforms.DetResizeForTest:评估尺寸,添加如下参数
|
||||
|
||||
```python
|
||||
%cd /home/aistudio/PaddleOCR/
|
||||
! python tools/eval.py \
|
||||
python tools/eval.py \
|
||||
-c configs/det/ch_PP-OCRv2/ch_PP-OCRv2_det_student.yml \
|
||||
-o Global.checkpoints="pretrain/ch_db_mv3-student1600/best_accuracy"
|
||||
```
|
||||
@ -331,7 +332,7 @@ Eval.dataset.transforms.DetResizeForTest:评估尺寸,添加如下参数
|
||||
# 加载配置文件`ch_PP-OCRv2_det_student.yml`,从`pretrain/ch_db_mv3-student1600-finetune`目录下加载`best_accuracy`模型
|
||||
# inference模型保存在`./output/det_db_inference`目录下
|
||||
%cd /home/aistudio/PaddleOCR/
|
||||
! python tools/export_model.py \
|
||||
python tools/export_model.py \
|
||||
-c configs/det/ch_PP-OCRv2/ch_PP-OCRv2_det_student.yml \
|
||||
-o Global.pretrained_model="pretrain/ch_db_mv3-student1600-finetune/best_accuracy" \
|
||||
Global.save_inference_dir="./output/det_db_inference/"
|
||||
@ -374,12 +375,11 @@ use_gpu:是否使用GPU
|
||||
|
||||
| 方案 | hmeans | 结果分析 |
|
||||
| -------- | -------- | -------- |
|
||||
| PP-OCRv2中英文超轻量检测预训练模型 | 77.26% | ppocr提供的预训练模型有一定的泛化能力 |
|
||||
| PP-OCRv2中英文超轻量检测预训练模型 | 77.26% | ppocr提供的预训练模型有泛化能力 |
|
||||
| XFUND数据集 | 79.27% | |
|
||||
| XFUND数据集+finetune | 85.24% | finetune会提升垂类场景效果 |
|
||||
|
||||
|
||||
## 4.2 文本识别
|
||||
### 4.2 文本识别
|
||||
|
||||
我们分别使用如下3种方案进行训练、评估:
|
||||
|
||||
@ -387,8 +387,7 @@ use_gpu:是否使用GPU
|
||||
- XFUND数据集+fine-tune
|
||||
- XFUND数据集+fine-tune+真实通用识别数据
|
||||
|
||||
|
||||
### **4.2.1 方案1:预训练模型**
|
||||
#### **4.2.1 方案1:预训练模型**
|
||||
|
||||
**1)下载预训练模型**
|
||||
|
||||
@ -401,8 +400,8 @@ use_gpu:是否使用GPU
|
||||
|
||||
```python
|
||||
%cd /home/aistudio/PaddleOCR/pretrain/
|
||||
! wget https://paddleocr.bj.bcebos.com/PP-OCRv2/chinese/ch_PP-OCRv2_rec_train.tar
|
||||
! tar -xf ch_PP-OCRv2_rec_train.tar && rm -rf ch_PP-OCRv2_rec_train.tar
|
||||
wget https://paddleocr.bj.bcebos.com/PP-OCRv2/chinese/ch_PP-OCRv2_rec_train.tar
|
||||
tar -xf ch_PP-OCRv2_rec_train.tar && rm -rf ch_PP-OCRv2_rec_train.tar
|
||||
% cd ..
|
||||
```
|
||||
|
||||
@ -424,7 +423,7 @@ Eval.dataset.label_file_list:指向验证集标注文件
|
||||
|
||||
```python
|
||||
%cd /home/aistudio/PaddleOCR
|
||||
! CUDA_VISIBLE_DEVICES=0 python tools/eval.py \
|
||||
CUDA_VISIBLE_DEVICES=0 python tools/eval.py \
|
||||
-c configs/rec/ch_PP-OCRv2/ch_PP-OCRv2_rec_distillation.yml \
|
||||
-o Global.checkpoints=./pretrain/ch_PP-OCRv2_rec_train/best_accuracy
|
||||
```
|
||||
@ -435,9 +434,9 @@ Eval.dataset.label_file_list:指向验证集标注文件
|
||||
| -------- | -------- |
|
||||
| PP-OCRv2中英文超轻量识别预训练模型 | 67.48% |
|
||||
|
||||
使用文本预训练模型在XFUND验证集上评估,acc达到67%左右,充分说明ppocr提供的预训练模型有一定的泛化能力。
|
||||
使用文本预训练模型在XFUND验证集上评估,acc达到67%左右,充分说明ppocr提供的预训练模型具有泛化能力。
|
||||
|
||||
### **4.2.2 方案2:XFUND数据集+finetune**
|
||||
#### **4.2.2 方案2:XFUND数据集+finetune**
|
||||
|
||||
同检测模型,我们提取Student模型的参数,在XFUND数据集上进行finetune,可以参考如下代码:
|
||||
|
||||
@ -474,11 +473,9 @@ Eval.dataset.label_file_list:指向验证集标注文件
|
||||
```
|
||||
执行如下命令启动训练:
|
||||
|
||||
|
||||
|
||||
```python
|
||||
%cd /home/aistudio/PaddleOCR/
|
||||
! CUDA_VISIBLE_DEVICES=0 python tools/train.py \
|
||||
CUDA_VISIBLE_DEVICES=0 python tools/train.py \
|
||||
-c configs/rec/ch_PP-OCRv2/ch_PP-OCRv2_rec.yml
|
||||
```
|
||||
|
||||
@ -493,7 +490,7 @@ Eval.dataset.label_file_list:指向验证集标注文件
|
||||
|
||||
```python
|
||||
%cd /home/aistudio/PaddleOCR/
|
||||
! CUDA_VISIBLE_DEVICES=0 python tools/eval.py \
|
||||
CUDA_VISIBLE_DEVICES=0 python tools/eval.py \
|
||||
-c configs/rec/ch_PP-OCRv2/ch_PP-OCRv2_rec.yml \
|
||||
-o Global.checkpoints=./pretrain/rec_mobile_pp-OCRv2-student-finetune/best_accuracy
|
||||
```
|
||||
@ -506,7 +503,7 @@ Eval.dataset.label_file_list:指向验证集标注文件
|
||||
|
||||
使用XFUND数据集+finetune训练,在验证集上评估达到72%左右,说明 finetune会提升垂类场景效果。
|
||||
|
||||
### **4.2.3 方案3:XFUND数据集+finetune+真实通用识别数据**
|
||||
#### **4.2.3 方案3:XFUND数据集+finetune+真实通用识别数据**
|
||||
|
||||
接着我们在上述`XFUND数据集+finetune`实验的基础上,添加真实通用识别数据,进一步提升识别效果。首先准备真实通用识别数据,并上传到AIStudio:
|
||||
|
||||
@ -528,7 +525,7 @@ Train.dataset.ratio_list:动态采样
|
||||
|
||||
```python
|
||||
%cd /home/aistudio/PaddleOCR/
|
||||
! CUDA_VISIBLE_DEVICES=0 python tools/train.py \
|
||||
CUDA_VISIBLE_DEVICES=0 python tools/train.py \
|
||||
-c configs/rec/ch_PP-OCRv2/ch_PP-OCRv2_rec.yml
|
||||
```
|
||||
|
||||
@ -538,11 +535,11 @@ Train.dataset.ratio_list:动态采样
|
||||
|
||||
<center>图16 文本识别方案3-模型评估</center>
|
||||
|
||||
使用训练好的模型进行评估,更新模型路径`Global.checkpoints`,这里为大家提供训练好的模型`./pretrain/rec_mobile_pp-OCRv2-student-readldata/best_accuracy`,[模型下载地址](https://paddleocr.bj.bcebos.com/fanliku/sheet_recognition/rec_mobile_pp-OCRv2-student-realdata.zip)
|
||||
使用训练好的模型进行评估,更新模型路径`Global.checkpoints`。
|
||||
|
||||
|
||||
```python
|
||||
! CUDA_VISIBLE_DEVICES=0 python tools/eval.py \
|
||||
CUDA_VISIBLE_DEVICES=0 python tools/eval.py \
|
||||
-c configs/rec/ch_PP-OCRv2/ch_PP-OCRv2_rec.yml \
|
||||
-o Global.checkpoints=./pretrain/rec_mobile_pp-OCRv2-student-realdata/best_accuracy
|
||||
```
|
||||
@ -580,7 +577,7 @@ Train.dataset.ratio_list:动态采样
|
||||
|
||||
|
||||
```python
|
||||
! python tools/infer/predict_system.py \
|
||||
python tools/infer/predict_system.py \
|
||||
--image_dir="./doc/vqa/input/zh_val_21.jpg" \
|
||||
--det_model_dir="./output/det_db_inference/" \
|
||||
--rec_model_dir="./output/rec_crnn_inference/" \
|
||||
@ -592,11 +589,11 @@ Train.dataset.ratio_list:动态采样
|
||||
|
||||
| 方案 | acc | 结果分析 |
|
||||
| -------- | -------- | -------- |
|
||||
| PP-OCRv2中英文超轻量识别预训练模型 | 67.48% | ppocr提供的预训练模型有一定的泛化能力 |
|
||||
| PP-OCRv2中英文超轻量识别预训练模型 | 67.48% | ppocr提供的预训练模型具有泛化能力 |
|
||||
| XFUND数据集+fine-tune |72.33% | finetune会提升垂类场景效果 |
|
||||
| XFUND数据集+fine-tune+真实通用识别数据 | 85.29% | 真实通用识别数据对于性能提升很有帮助 |
|
||||
|
||||
# 5 文档视觉问答(DOC-VQA)
|
||||
## 5 文档视觉问答(DOC-VQA)
|
||||
|
||||
VQA指视觉问答,主要针对图像内容进行提问和回答,DOC-VQA是VQA任务中的一种,DOC-VQA主要针对文本图像的文字内容提出问题。
|
||||
|
||||
@ -608,14 +605,13 @@ PaddleOCR中DOC-VQA系列算法基于PaddleNLP自然语言处理算法库实现L
|
||||
```python
|
||||
%cd pretrain
|
||||
#下载SER模型
|
||||
! wget https://paddleocr.bj.bcebos.com/pplayout/ser_LayoutXLM_xfun_zh.tar && tar -xvf ser_LayoutXLM_xfun_zh.tar
|
||||
wget https://paddleocr.bj.bcebos.com/pplayout/ser_LayoutXLM_xfun_zh.tar && tar -xvf ser_LayoutXLM_xfun_zh.tar
|
||||
#下载RE模型
|
||||
! wget https://paddleocr.bj.bcebos.com/pplayout/re_LayoutXLM_xfun_zh.tar && tar -xvf re_LayoutXLM_xfun_zh.tar
|
||||
wget https://paddleocr.bj.bcebos.com/pplayout/re_LayoutXLM_xfun_zh.tar && tar -xvf re_LayoutXLM_xfun_zh.tar
|
||||
%cd ../
|
||||
```
|
||||
|
||||
|
||||
## 5.1 SER
|
||||
### 5.1 SER
|
||||
|
||||
SER: 语义实体识别 (Semantic Entity Recognition), 可以完成对图像中的文本识别与分类。
|
||||
|
||||
@ -647,7 +643,7 @@ SER: 语义实体识别 (Semantic Entity Recognition), 可以完成对图像
|
||||
|
||||
```python
|
||||
%cd /home/aistudio/PaddleOCR/
|
||||
! CUDA_VISIBLE_DEVICES=0 python tools/train.py -c configs/vqa/ser/layoutxlm.yml
|
||||
CUDA_VISIBLE_DEVICES=0 python tools/train.py -c configs/vqa/ser/layoutxlm.yml
|
||||
```
|
||||
|
||||
最终会打印出`precision`, `recall`, `hmean`等指标。 在`./output/ser_layoutxlm/`文件夹中会保存训练日志,最优的模型和最新epoch的模型。
|
||||
@ -664,7 +660,7 @@ SER: 语义实体识别 (Semantic Entity Recognition), 可以完成对图像
|
||||
|
||||
|
||||
```python
|
||||
! CUDA_VISIBLE_DEVICES=0 python tools/eval.py \
|
||||
CUDA_VISIBLE_DEVICES=0 python tools/eval.py \
|
||||
-c configs/vqa/ser/layoutxlm.yml \
|
||||
-o Architecture.Backbone.checkpoints=pretrain/ser_LayoutXLM_xfun_zh/
|
||||
```
|
||||
@ -684,7 +680,7 @@ SER: 语义实体识别 (Semantic Entity Recognition), 可以完成对图像
|
||||
|
||||
|
||||
```python
|
||||
! CUDA_VISIBLE_DEVICES=0 python tools/infer_vqa_token_ser.py \
|
||||
CUDA_VISIBLE_DEVICES=0 python tools/infer_vqa_token_ser.py \
|
||||
-c configs/vqa/ser/layoutxlm.yml \
|
||||
-o Architecture.Backbone.checkpoints=pretrain/ser_LayoutXLM_xfun_zh/ \
|
||||
Global.infer_img=doc/vqa/input/zh_val_42.jpg
|
||||
@ -704,7 +700,7 @@ plt.figure(figsize=(48,24))
|
||||
plt.imshow(img)
|
||||
```
|
||||
|
||||
## 5.2 RE
|
||||
### 5.2 RE
|
||||
|
||||
基于 RE 任务,可以完成对图象中的文本内容的关系提取,如判断问题对(pair)。
|
||||
|
||||
@ -729,7 +725,7 @@ plt.imshow(img)
|
||||
|
||||
|
||||
```python
|
||||
! CUDA_VISIBLE_DEVICES=0 python3 tools/train.py -c configs/vqa/re/layoutxlm.yml
|
||||
CUDA_VISIBLE_DEVICES=0 python3 tools/train.py -c configs/vqa/re/layoutxlm.yml
|
||||
```
|
||||
|
||||
最终会打印出`precision`, `recall`, `hmean`等指标。 在`./output/re_layoutxlm/`文件夹中会保存训练日志,最优的模型和最新epoch的模型
|
||||
@ -744,7 +740,7 @@ plt.imshow(img)
|
||||
|
||||
|
||||
```python
|
||||
! CUDA_VISIBLE_DEVICES=0 python3 tools/eval.py \
|
||||
CUDA_VISIBLE_DEVICES=0 python3 tools/eval.py \
|
||||
-c configs/vqa/re/layoutxlm.yml \
|
||||
-o Architecture.Backbone.checkpoints=pretrain/re_LayoutXLM_xfun_zh/
|
||||
```
|
||||
@ -760,20 +756,14 @@ plt.imshow(img)
|
||||
|
||||
<center>图26 RE-模型预测</center>
|
||||
|
||||
使用OCR引擎 + SER + RE串联预测
|
||||
|
||||
使用如下命令即可完成OCR引擎 + SER + RE的串联预测, 以预训练SER和RE模型为例:
|
||||
|
||||
|
||||
使用如下命令即可完成OCR引擎 + SER + RE的串联预测, 以预训练SER和RE模型为例,
|
||||
|
||||
最终会在config.Global.save_res_path字段所配置的目录下保存预测结果可视化图像以及预测结果文本文件,预测结果文本文件名为infer_results.txt。
|
||||
|
||||
|
||||
|
||||
|
||||
```python
|
||||
%cd /home/aistudio/PaddleOCR
|
||||
! CUDA_VISIBLE_DEVICES=0 python3 tools/infer_vqa_token_ser_re.py \
|
||||
cd /home/aistudio/PaddleOCR
|
||||
CUDA_VISIBLE_DEVICES=0 python3 tools/infer_vqa_token_ser_re.py \
|
||||
-c configs/vqa/re/layoutxlm.yml \
|
||||
-o Architecture.Backbone.checkpoints=pretrain/re_LayoutXLM_xfun_zh/ \
|
||||
Global.infer_img=test_imgs/ \
|
||||
@ -787,10 +777,9 @@ plt.imshow(img)
|
||||
test_imgs/t131.jpg {"政治面税": "群众", "性别": "男", "籍贯": "河北省邯郸市", "婚姻状况": "亏末婚口已婚口已娇", "通讯地址": "邯郸市阳光苑7号楼003", "民族": "汉族", "毕业院校": "河南工业大学", "户口性质": "口农村城镇", "户口地址": "河北省邯郸市", "联系电话": "13288888888", "健康状况": "健康", "姓名": "小六", "好高cm": "180", "出生年月": "1996年8月9日", "文化程度": "本科", "身份证号码": "458933777777777777"}
|
||||
````
|
||||
|
||||
|
||||
展示预测结果
|
||||
|
||||
```python
|
||||
# 展示预测结果
|
||||
import cv2
|
||||
from matplotlib import pyplot as plt
|
||||
%matplotlib inline
|
||||
@ -800,7 +789,7 @@ plt.figure(figsize=(48,24))
|
||||
plt.imshow(img)
|
||||
```
|
||||
|
||||
# 6 导出Excel
|
||||
## 6 导出Excel
|
||||
|
||||
<center><img src="https://ai-studio-static-online.cdn.bcebos.com/ab93d3d90d77437a81c9534b2dd1d3e39ef81e8473054fd3aeff6e837ebfb827"></center>
|
||||
<center>图27 导出Excel</center>
|
||||
@ -859,7 +848,15 @@ with open('output/re/infer_results.txt', 'r', encoding='utf-8') as fin:
|
||||
workbook.close()
|
||||
```
|
||||
|
||||
# 更多资源
|
||||
## 获得模型
|
||||
|
||||
如需获取已训练模型,请扫码填写问卷,加入PaddleOCR官方交流群获取全部OCR垂类模型下载链接、《动手学OCR》电子书等全套OCR学习资料🎁
|
||||
<div align="left">
|
||||
<img src="https://ai-studio-static-online.cdn.bcebos.com/dd721099bd50478f9d5fb13d8dd00fad69c22d6848244fd3a1d3980d7fefc63e" width = "150" height = "150" />
|
||||
</div>
|
||||
将下载或训练完成的模型放置在对应目录下即可完成模型推理
|
||||
|
||||
## 更多资源
|
||||
|
||||
- 更多深度学习知识、产业案例、面试宝典等,请参考:[awesome-DeepLearning](https://github.com/paddlepaddle/awesome-DeepLearning)
|
||||
|
||||
@ -869,7 +866,7 @@ workbook.close()
|
||||
|
||||
- 飞桨框架相关资料,请参考:[飞桨深度学习平台](https://www.paddlepaddle.org.cn/?fr=paddleEdu_aistudio)
|
||||
|
||||
# 参考链接
|
||||
## 参考链接
|
||||
|
||||
- LayoutXLM: Multimodal Pre-training for Multilingual Visually-rich Document Understanding, https://arxiv.org/pdf/2104.08836.pdf
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user