chore: import upstream snapshot with attribution
Build/Publish Develop Docs / deploy (push) Failing after 1s
PaddleOCR Code Style Check / check-code-style (push) Failing after 1s
PaddleOCR PR Tests GPU / detect-changes (push) Failing after 1s
PaddleOCR PR Tests / detect-changes (push) Failing after 1s
PaddleOCR PR Tests GPU / test-pr-gpu (push) Has been cancelled
PaddleOCR PR Tests / test-pr (push) Has been cancelled
PaddleOCR PR Tests GPU / test-pr-gpu-impl (push) Has been cancelled
PaddleOCR PR Tests / test-pr-python (3.13) (push) Has been cancelled
PaddleOCR PR Tests / test-pr-python (3.8) (push) Has been cancelled
PaddleOCR PR Tests / test-pr-python (3.9) (push) Has been cancelled
@@ -0,0 +1,307 @@
|
||||
---
|
||||
comments: true
|
||||
---
|
||||
|
||||
# Add New Algorithm
|
||||
|
||||
PaddleOCR decomposes an algorithm into the following parts, and modularizes each part to make it more convenient to develop new algorithms.
|
||||
|
||||
* Data loading and processing
|
||||
* Network
|
||||
* Post-processing
|
||||
* Loss
|
||||
* Metric
|
||||
* Optimizer
|
||||
|
||||
The following will introduce each part separately, and introduce how to add the modules required for the new algorithm.
|
||||
|
||||
## Data loading and processing
|
||||
|
||||
Data loading and processing are composed of different modules, which complete the image reading, data augment and label production. This part is under [ppocr/data](../../../ppocr/data). The explanation of each file and folder are as follows:
|
||||
|
||||
```bash linenums="1"
|
||||
ppocr/data/
|
||||
├── imaug # Scripts for image reading, data augment and label production
|
||||
│ ├── label_ops.py # Modules that transform the label
|
||||
│ ├── operators.py # Modules that transform the image
|
||||
│ ├──.....
|
||||
├── __init__.py
|
||||
├── lmdb_dataset.py # The dataset that reads the lmdb
|
||||
└── simple_dataset.py # Read the dataset saved in the form of `image_path\tgt`
|
||||
```
|
||||
|
||||
PaddleOCR has a large number of built-in image operation related modules. For modules that are not built-in, you can add them through the following steps:
|
||||
|
||||
1. Create a new file under the [ppocr/data/imaug](../../../ppocr/data/imaug) folder, such as my_module.py.
|
||||
2. Add code in the my_module.py file, the sample code is as follows:
|
||||
|
||||
```python linenums="1"
|
||||
class MyModule:
|
||||
def __init__(self, *args, **kwargs):
|
||||
# your init code
|
||||
pass
|
||||
|
||||
def __call__(self, data):
|
||||
img = data['image']
|
||||
label = data['label']
|
||||
# your process code
|
||||
|
||||
data['image'] = img
|
||||
data['label'] = label
|
||||
return data
|
||||
```
|
||||
|
||||
3. Import the added module in the [ppocr/data/imaug/\__init\__.py](../../../ppocr/data/imaug/__init__.py) file.
|
||||
|
||||
All different modules of data processing are executed by sequence, combined and executed in the form of a list in the config file. Such as:
|
||||
|
||||
```yaml linenums="1"
|
||||
# angle class data process
|
||||
transforms:
|
||||
- DecodeImage: # load image
|
||||
img_mode: BGR
|
||||
channel_first: False
|
||||
- MyModule:
|
||||
args1: args1
|
||||
args2: args2
|
||||
- KeepKeys:
|
||||
keep_keys: [ 'image', 'label' ] # dataloader will return list in this order
|
||||
```
|
||||
|
||||
## Network
|
||||
|
||||
The network part completes the construction of the network, and PaddleOCR divides the network into four parts, which are under [ppocr/modeling](../../../ppocr/modeling). The data entering the network will pass through these four parts in sequence(transforms->backbones->
|
||||
necks->heads).
|
||||
|
||||
```bash linenums="1"
|
||||
├── architectures # Code for building network
|
||||
├── transforms # Image Transformation Module
|
||||
├── backbones # Feature extraction module
|
||||
├── necks # Feature enhancement module
|
||||
└── heads # Output module
|
||||
```
|
||||
|
||||
PaddleOCR has built-in commonly used modules related to algorithms such as DB, EAST, SAST, CRNN and Attention. For modules that do not have built-in, you can add them through the following steps, the four parts are added in the same steps, take backbones as an example:
|
||||
|
||||
1. Create a new file under the [ppocr/modeling/backbones](../../../ppocr/modeling/backbones) folder, such as my_backbone.py.
|
||||
2. Add code in the my_backbone.py file, the sample code is as follows:
|
||||
|
||||
```python linenums="1"
|
||||
import paddle
|
||||
import paddle.nn as nn
|
||||
import paddle.nn.functional as F
|
||||
|
||||
|
||||
class MyBackbone(nn.Layer):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(MyBackbone, self).__init__()
|
||||
# your init code
|
||||
self.conv = nn.xxxx
|
||||
|
||||
def forward(self, inputs):
|
||||
# your network forward
|
||||
y = self.conv(inputs)
|
||||
return y
|
||||
```
|
||||
|
||||
3. Import the added module in the [ppocr/modeling/backbones/\__init\__.py](../../../ppocr/modeling/backbones/__init__.py) file.
|
||||
|
||||
After adding the four-part modules of the network, you only need to configure them in the configuration file to use, such as:
|
||||
|
||||
```yaml linenums="1"
|
||||
Architecture:
|
||||
model_type: rec
|
||||
algorithm: CRNN
|
||||
Transform:
|
||||
name: MyTransform
|
||||
args1: args1
|
||||
args2: args2
|
||||
Backbone:
|
||||
name: MyBackbone
|
||||
args1: args1
|
||||
Neck:
|
||||
name: MyNeck
|
||||
args1: args1
|
||||
Head:
|
||||
name: MyHead
|
||||
args1: args1
|
||||
```
|
||||
|
||||
## Post-processing
|
||||
|
||||
Post-processing realizes decoding network output to obtain text box or recognized text. This part is under [ppocr/postprocess](../../../ppocr/postprocess).
|
||||
PaddleOCR has built-in post-processing modules related to algorithms such as DB, EAST, SAST, CRNN and Attention. For components that are not built-in, they can be added through the following steps:
|
||||
|
||||
1. Create a new file under the [ppocr/postprocess](../../../ppocr/postprocess) folder, such as my_postprocess.py.
|
||||
2. Add code in the my_postprocess.py file, the sample code is as follows:
|
||||
|
||||
```python linenums="1"
|
||||
import paddle
|
||||
|
||||
|
||||
class MyPostProcess:
|
||||
def __init__(self, *args, **kwargs):
|
||||
# your init code
|
||||
pass
|
||||
|
||||
def __call__(self, preds, label=None, *args, **kwargs):
|
||||
if isinstance(preds, paddle.Tensor):
|
||||
preds = preds.numpy()
|
||||
# you preds decode code
|
||||
preds = self.decode_preds(preds)
|
||||
if label is None:
|
||||
return preds
|
||||
# you label decode code
|
||||
label = self.decode_label(label)
|
||||
return preds, label
|
||||
|
||||
def decode_preds(self, preds):
|
||||
# you preds decode code
|
||||
pass
|
||||
|
||||
def decode_label(self, preds):
|
||||
# you label decode code
|
||||
pass
|
||||
```
|
||||
|
||||
3. Import the added module in the [ppocr/postprocess/\__init\__.py](../../../ppocr/postprocess/__init__.py) file.
|
||||
|
||||
After the post-processing module is added, you only need to configure it in the configuration file to use, such as:
|
||||
|
||||
```yaml linenums="1"
|
||||
PostProcess:
|
||||
name: MyPostProcess
|
||||
args1: args1
|
||||
args2: args2
|
||||
```
|
||||
|
||||
## Loss
|
||||
|
||||
The loss function is used to calculate the distance between the network output and the label. This part is under [ppocr/losses](../../../ppocr/losses).
|
||||
PaddleOCR has built-in loss function modules related to algorithms such as DB, EAST, SAST, CRNN and Attention. For modules that do not have built-in modules, you can add them through the following steps:
|
||||
|
||||
1. Create a new file in the [ppocr/losses](../../../ppocr/losses) folder, such as my_loss.py.
|
||||
2. Add code in the my_loss.py file, the sample code is as follows:
|
||||
|
||||
```python linenums="1"
|
||||
import paddle
|
||||
from paddle import nn
|
||||
|
||||
|
||||
class MyLoss(nn.Layer):
|
||||
def __init__(self, **kwargs):
|
||||
super(MyLoss, self).__init__()
|
||||
# you init code
|
||||
pass
|
||||
|
||||
def __call__(self, predicts, batch):
|
||||
label = batch[1]
|
||||
# your loss code
|
||||
loss = self.loss(input=predicts, label=label)
|
||||
return {'loss': loss}
|
||||
```
|
||||
|
||||
3. Import the added module in the [ppocr/losses/\__init\__.py](../../../ppocr/losses/__init__.py) file.
|
||||
|
||||
After the loss function module is added, you only need to configure it in the configuration file to use it, such as:
|
||||
|
||||
```yaml linenums="1"
|
||||
Loss:
|
||||
name: MyLoss
|
||||
args1: args1
|
||||
args2: args2
|
||||
```
|
||||
|
||||
## Metric
|
||||
|
||||
Metric is used to calculate the performance of the network on the current batch. This part is under [ppocr/metrics](../../../ppocr/metrics). PaddleOCR has built-in evaluation modules related to algorithms such as detection, classification and recognition. For modules that do not have built-in modules, you can add them through the following steps:
|
||||
|
||||
1. Create a new file under the [ppocr/metrics](../../../ppocr/metrics) folder, such as my_metric.py.
|
||||
2. Add code in the my_metric.py file, the sample code is as follows:
|
||||
|
||||
```python linenums="1"
|
||||
|
||||
class MyMetric(object):
|
||||
def __init__(self, main_indicator='acc', **kwargs):
|
||||
# main_indicator is used for select best model
|
||||
self.main_indicator = main_indicator
|
||||
self.reset()
|
||||
|
||||
def __call__(self, preds, batch, *args, **kwargs):
|
||||
# preds is out of postprocess
|
||||
# batch is out of dataloader
|
||||
labels = batch[1]
|
||||
cur_correct_num = 0
|
||||
cur_all_num = 0
|
||||
# you metric code
|
||||
self.correct_num += cur_correct_num
|
||||
self.all_num += cur_all_num
|
||||
return {'acc': cur_correct_num / cur_all_num, }
|
||||
|
||||
def get_metric(self):
|
||||
"""
|
||||
return metrics {
|
||||
'acc': 0,
|
||||
'norm_edit_dis': 0,
|
||||
}
|
||||
"""
|
||||
acc = self.correct_num / self.all_num
|
||||
self.reset()
|
||||
return {'acc': acc}
|
||||
|
||||
def reset(self):
|
||||
# reset metric
|
||||
self.correct_num = 0
|
||||
self.all_num = 0
|
||||
|
||||
```
|
||||
|
||||
3. Import the added module in the [ppocr/metrics/\__init\__.py](../../../ppocr/metrics/__init__.py) file.
|
||||
|
||||
After the metric module is added, you only need to configure it in the configuration file to use it, such as:
|
||||
|
||||
```yaml linenums="1"
|
||||
Metric:
|
||||
name: MyMetric
|
||||
main_indicator: acc
|
||||
```
|
||||
|
||||
## Optimizer
|
||||
|
||||
The optimizer is used to train the network. The optimizer also contains network regularization and learning rate decay modules. This part is under [ppocr/optimizer](../../../ppocr/optimizer). PaddleOCR has built-in
|
||||
Commonly used optimizer modules such as `Momentum`, `Adam` and `RMSProp`, common regularization modules such as `Linear`, `Cosine`, `Step` and `Piecewise`, and common learning rate decay modules such as `L1Decay` and `L2Decay`.
|
||||
Modules without built-in can be added through the following steps, take `optimizer` as an example:
|
||||
|
||||
1. Create your own optimizer in the [ppocr/optimizer/optimizer.py](../../../ppocr/optimizer/optimizer.py) file, the sample code is as follows:
|
||||
|
||||
```python linenums="1"
|
||||
from paddle import optimizer as optim
|
||||
|
||||
|
||||
class MyOptim(object):
|
||||
def __init__(self, learning_rate=0.001, *args, **kwargs):
|
||||
self.learning_rate = learning_rate
|
||||
|
||||
def __call__(self, parameters):
|
||||
# It is recommended to wrap the built-in optimizer of paddle
|
||||
opt = optim.XXX(
|
||||
learning_rate=self.learning_rate,
|
||||
parameters=parameters)
|
||||
return opt
|
||||
|
||||
```
|
||||
|
||||
After the optimizer module is added, you only need to configure it in the configuration file to use, such as:
|
||||
|
||||
```yaml linenums="1"
|
||||
Optimizer:
|
||||
name: MyOptim
|
||||
args1: args1
|
||||
args2: args2
|
||||
lr:
|
||||
name: Cosine
|
||||
learning_rate: 0.001
|
||||
regularizer:
|
||||
name: 'L2'
|
||||
factor: 0
|
||||
```
|
||||
@@ -0,0 +1,300 @@
|
||||
---
|
||||
comments: true
|
||||
---
|
||||
|
||||
# 添加新算法
|
||||
|
||||
PaddleOCR将一个算法分解为以下几个部分,并对各部分进行模块化处理,方便快速组合出新的算法。
|
||||
|
||||
下面将分别对每个部分进行介绍,并介绍如何在该部分里添加新算法所需模块。
|
||||
|
||||
## 1. 数据加载和处理
|
||||
|
||||
数据加载和处理由不同的模块(module)组成,其完成了图片的读取、数据增强和label的制作。这一部分在[ppocr/data](../../../ppocr/data)下。 各个文件及文件夹作用说明如下:
|
||||
|
||||
```bash linenums="1"
|
||||
ppocr/data/
|
||||
├── imaug # 图片的读取、数据增强和label制作相关的文件
|
||||
│ ├── label_ops.py # 对label进行变换的modules
|
||||
│ ├── operators.py # 对image进行变换的modules
|
||||
│ ├──.....
|
||||
├── __init__.py
|
||||
├── lmdb_dataset.py # 读取lmdb的数据集的dataset
|
||||
└── simple_dataset.py # 读取以`image_path\tgt`形式保存的数据集的dataset
|
||||
```
|
||||
|
||||
PaddleOCR内置了大量图像操作相关模块,对于没有没有内置的模块可通过如下步骤添加:
|
||||
|
||||
1. 在 [ppocr/data/imaug](../../../ppocr/data/imaug) 文件夹下新建文件,如my_module.py。
|
||||
2. 在 my_module.py 文件内添加相关代码,示例代码如下:
|
||||
|
||||
```python linenums="1"
|
||||
class MyModule:
|
||||
def __init__(self, *args, **kwargs):
|
||||
# your init code
|
||||
pass
|
||||
|
||||
def __call__(self, data):
|
||||
img = data['image']
|
||||
label = data['label']
|
||||
# your process code
|
||||
|
||||
data['image'] = img
|
||||
data['label'] = label
|
||||
return data
|
||||
```
|
||||
|
||||
3. 在 [ppocr/data/imaug/\__init\__.py](../../../ppocr/data/imaug/__init__.py) 文件内导入添加的模块。
|
||||
|
||||
数据处理的所有处理步骤由不同的模块顺序执行而成,在config文件中按照列表的形式组合并执行。如:
|
||||
|
||||
```yaml linenums="1"
|
||||
# angle class data process
|
||||
transforms:
|
||||
- DecodeImage: # load image
|
||||
img_mode: BGR
|
||||
channel_first: False
|
||||
- MyModule:
|
||||
args1: args1
|
||||
args2: args2
|
||||
- KeepKeys:
|
||||
keep_keys: [ 'image', 'label' ] # dataloader will return list in this order
|
||||
```
|
||||
|
||||
## 2. 网络
|
||||
|
||||
网络部分完成了网络的组网操作,PaddleOCR将网络划分为四部分,这一部分在[ppocr/modeling](../../../ppocr/modeling)下。 进入网络的数据将按照顺序(transforms->backbones->
|
||||
necks->heads)依次通过这四个部分。
|
||||
|
||||
```bash linenums="1"
|
||||
├── architectures # 网络的组网代码
|
||||
├── transforms # 网络的图像变换模块
|
||||
├── backbones # 网络的特征提取模块
|
||||
├── necks # 网络的特征增强模块
|
||||
└── heads # 网络的输出模块
|
||||
```
|
||||
|
||||
PaddleOCR内置了DB,EAST,SAST,CRNN和Attention等算法相关的常用模块,对于没有内置的模块可通过如下步骤添加,四个部分添加步骤一致,以backbones为例:
|
||||
|
||||
1. 在 [ppocr/modeling/backbones](../../../ppocr/modeling/backbones) 文件夹下新建文件,如my_backbone.py。
|
||||
2. 在 my_backbone.py 文件内添加相关代码,示例代码如下:
|
||||
|
||||
```python linenums="1"
|
||||
import paddle
|
||||
import paddle.nn as nn
|
||||
import paddle.nn.functional as F
|
||||
|
||||
|
||||
class MyBackbone(nn.Layer):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(MyBackbone, self).__init__()
|
||||
# your init code
|
||||
self.conv = nn.xxxx
|
||||
|
||||
def forward(self, inputs):
|
||||
# your network forward
|
||||
y = self.conv(inputs)
|
||||
return y
|
||||
```
|
||||
|
||||
3. 在 [ppocr/modeling/backbones/\__init\__.py](../../../ppocr/modeling/backbones/__init__.py)文件内导入添加的模块。
|
||||
|
||||
在完成网络的四部分模块添加之后,只需要配置文件中进行配置即可使用,如:
|
||||
|
||||
```yaml linenums="1"
|
||||
Architecture:
|
||||
model_type: rec
|
||||
algorithm: CRNN
|
||||
Transform:
|
||||
name: MyTransform
|
||||
args1: args1
|
||||
args2: args2
|
||||
Backbone:
|
||||
name: MyBackbone
|
||||
args1: args1
|
||||
Neck:
|
||||
name: MyNeck
|
||||
args1: args1
|
||||
Head:
|
||||
name: MyHead
|
||||
args1: args1
|
||||
```
|
||||
|
||||
## 3. 后处理
|
||||
|
||||
后处理实现解码网络输出获得文本框或者识别到的文字。这一部分在[ppocr/postprocess](../../../ppocr/postprocess)下。
|
||||
PaddleOCR内置了DB,EAST,SAST,CRNN和Attention等算法相关的后处理模块,对于没有内置的组件可通过如下步骤添加:
|
||||
|
||||
1. 在 [ppocr/postprocess](../../../ppocr/postprocess) 文件夹下新建文件,如 my_postprocess.py。
|
||||
2. 在 my_postprocess.py 文件内添加相关代码,示例代码如下:
|
||||
|
||||
```python linenums="1"
|
||||
import paddle
|
||||
|
||||
|
||||
class MyPostProcess:
|
||||
def __init__(self, *args, **kwargs):
|
||||
# your init code
|
||||
pass
|
||||
|
||||
def __call__(self, preds, label=None, *args, **kwargs):
|
||||
if isinstance(preds, paddle.Tensor):
|
||||
preds = preds.numpy()
|
||||
# you preds decode code
|
||||
preds = self.decode_preds(preds)
|
||||
if label is None:
|
||||
return preds
|
||||
# you label decode code
|
||||
label = self.decode_label(label)
|
||||
return preds, label
|
||||
|
||||
def decode_preds(self, preds):
|
||||
# you preds decode code
|
||||
pass
|
||||
|
||||
def decode_label(self, preds):
|
||||
# you label decode code
|
||||
pass
|
||||
```
|
||||
|
||||
3. 在 [ppocr/postprocess/\__init\__.py](../../../ppocr/postprocess/__init__.py)文件内导入添加的模块。
|
||||
|
||||
在后处理模块添加之后,只需要配置文件中进行配置即可使用,如:
|
||||
|
||||
```yaml linenums="1"
|
||||
PostProcess:
|
||||
name: MyPostProcess
|
||||
args1: args1
|
||||
args2: args2
|
||||
```
|
||||
|
||||
## 4. 损失函数
|
||||
|
||||
损失函数用于计算网络输出和label之间的距离。这一部分在[ppocr/losses](../../../ppocr/losses)下。
|
||||
PaddleOCR内置了DB,EAST,SAST,CRNN和Attention等算法相关的损失函数模块,对于没有内置的模块可通过如下步骤添加:
|
||||
|
||||
1. 在 [ppocr/losses](../../../ppocr/losses) 文件夹下新建文件,如 my_loss.py。
|
||||
2. 在 my_loss.py 文件内添加相关代码,示例代码如下:
|
||||
|
||||
```python linenums="1"
|
||||
import paddle
|
||||
from paddle import nn
|
||||
|
||||
|
||||
class MyLoss(nn.Layer):
|
||||
def __init__(self, **kwargs):
|
||||
super(MyLoss, self).__init__()
|
||||
# you init code
|
||||
pass
|
||||
|
||||
def __call__(self, predicts, batch):
|
||||
label = batch[1]
|
||||
# your loss code
|
||||
loss = self.loss(input=predicts, label=label)
|
||||
return {'loss': loss}
|
||||
```
|
||||
|
||||
3. 在 [ppocr/losses/\__init\__.py](../../../ppocr/losses/__init__.py)文件内导入添加的模块。
|
||||
|
||||
在损失函数添加之后,只需要配置文件中进行配置即可使用,如:
|
||||
|
||||
```yaml linenums="1"
|
||||
Loss:
|
||||
name: MyLoss
|
||||
args1: args1
|
||||
args2: args2
|
||||
```
|
||||
|
||||
## 5. 指标评估
|
||||
|
||||
指标评估用于计算网络在当前batch上的性能。这一部分在[ppocr/metrics](../../../ppocr/metrics)下。 PaddleOCR内置了检测,分类和识别等算法相关的指标评估模块,对于没有内置的模块可通过如下步骤添加:
|
||||
|
||||
1. 在 [ppocr/metrics](../../../ppocr/metrics) 文件夹下新建文件,如my_metric.py。
|
||||
2. 在 my_metric.py 文件内添加相关代码,示例代码如下:
|
||||
|
||||
```python linenums="1"
|
||||
|
||||
class MyMetric(object):
|
||||
def __init__(self, main_indicator='acc', **kwargs):
|
||||
# main_indicator is used for select best model
|
||||
self.main_indicator = main_indicator
|
||||
self.reset()
|
||||
|
||||
def __call__(self, preds, batch, *args, **kwargs):
|
||||
# preds is out of postprocess
|
||||
# batch is out of dataloader
|
||||
labels = batch[1]
|
||||
cur_correct_num = 0
|
||||
cur_all_num = 0
|
||||
# you metric code
|
||||
self.correct_num += cur_correct_num
|
||||
self.all_num += cur_all_num
|
||||
return {'acc': cur_correct_num / cur_all_num, }
|
||||
|
||||
def get_metric(self):
|
||||
"""
|
||||
return metrics {
|
||||
'acc': 0,
|
||||
'norm_edit_dis': 0,
|
||||
}
|
||||
"""
|
||||
acc = self.correct_num / self.all_num
|
||||
self.reset()
|
||||
return {'acc': acc}
|
||||
|
||||
def reset(self):
|
||||
# reset metric
|
||||
self.correct_num = 0
|
||||
self.all_num = 0
|
||||
|
||||
```
|
||||
|
||||
3. 在 [ppocr/metrics/\__init\__.py](../../../ppocr/metrics/__init__.py)文件内导入添加的模块。
|
||||
|
||||
在指标评估模块添加之后,只需要配置文件中进行配置即可使用,如:
|
||||
|
||||
```yaml linenums="1"
|
||||
Metric:
|
||||
name: MyMetric
|
||||
main_indicator: acc
|
||||
```
|
||||
|
||||
## 6. 优化器
|
||||
|
||||
优化器用于训练网络。优化器内部还包含了网络正则化和学习率衰减模块。 这一部分在[ppocr/optimizer](../../../ppocr/optimizer)下。 PaddleOCR内置了`Momentum`,`Adam`
|
||||
和`RMSProp`等常用的优化器模块,`Linear`,`Cosine`,`Step`和`Piecewise`等常用的正则化模块与`L1Decay`和`L2Decay`等常用的学习率衰减模块。
|
||||
对于没有内置的模块可通过如下步骤添加,以`optimizer`为例:
|
||||
|
||||
1. 在 [ppocr/optimizer/optimizer.py](../../../ppocr/optimizer/optimizer.py) 文件内创建自己的优化器,示例代码如下:
|
||||
|
||||
```python linenums="1"
|
||||
from paddle import optimizer as optim
|
||||
|
||||
|
||||
class MyOptim(object):
|
||||
def __init__(self, learning_rate=0.001, *args, **kwargs):
|
||||
self.learning_rate = learning_rate
|
||||
|
||||
def __call__(self, parameters):
|
||||
# It is recommended to wrap the built-in optimizer of paddle
|
||||
opt = optim.XXX(
|
||||
learning_rate=self.learning_rate,
|
||||
parameters=parameters)
|
||||
return opt
|
||||
|
||||
```
|
||||
|
||||
在优化器模块添加之后,只需要配置文件中进行配置即可使用,如:
|
||||
|
||||
```yaml linenums="1"
|
||||
Optimizer:
|
||||
name: MyOptim
|
||||
args1: args1
|
||||
args2: args2
|
||||
lr:
|
||||
name: Cosine
|
||||
learning_rate: 0.001
|
||||
regularizer:
|
||||
name: 'L2'
|
||||
factor: 0
|
||||
```
|
||||
@@ -0,0 +1,224 @@
|
||||
---
|
||||
comments: true
|
||||
---
|
||||
|
||||
## 1. Brief Introduction
|
||||
|
||||
OCR algorithms can be divided into two categories: two-stage algorithm and end-to-end algorithm. The two-stage OCR algorithm is generally divided into two parts, text detection and text recognition algorithm. The text detection algorithm locates the box of the text line from the image, and then the recognition algorithm identifies the content of the text box. The end-to-end OCR algorithm combines text detection and recognition in one algorithm. Its basic idea is to design a model with both detection unit and recognition module, share the CNN features of both and train them together. Because one algorithm can complete character recognition, the end-to-end model is smaller and faster.
|
||||
|
||||
### Introduction Of PGNet Algorithm
|
||||
|
||||
During the recent years, the end-to-end OCR algorithm has been well developed, including MaskTextSpotter series, TextSnake, TextDragon, PGNet series and so on. Among these algorithms, PGNet algorithm has some advantages over the other algorithms.
|
||||
|
||||
- PGNet loss is designed to guide training, and no character-level annotations is needed.
|
||||
- NMS and ROI related operations are not needed. It can accelerate the prediction
|
||||
- The reading order prediction module is proposed
|
||||
- A graph based modification module (GRM) is proposed to further improve the performance of model recognition
|
||||
- Higher accuracy and faster prediction speed
|
||||
|
||||
For details of PGNet algorithm, please refer to [paper](https://cdn.aaai.org/ojs/16383/16383-13-19877-1-2-20210518.pdf). The schematic diagram of the algorithm is as follows:
|
||||
|
||||

|
||||
|
||||
After feature extraction, the input image is sent to four branches: TBO module for text edge offset prediction, TCL module for text center-line prediction, TDO module for text direction offset prediction, and TCC module for text character classification graph prediction.
|
||||
The output of TBO and TCL can get text detection results after post-processing, and TCL, TDO and TCC are responsible for text recognition.
|
||||
|
||||
The results of detection and recognition are as follows:
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
### Performance
|
||||
|
||||
#### Test set: Total Text
|
||||
|
||||
#### Test environment: NVIDIA Tesla V100-SXM2-16GB
|
||||
|
||||
|PGNetA|det_precision|det_recall|det_f_score|e2e_precision|e2e_recall|e2e_f_score|FPS|download|
|
||||
| --- | --- | --- | --- | --- | --- | --- | --- | --- |
|
||||
|Paper|85.30|86.80|86.10|-|-|61.70|38.20 (size=640)|-|
|
||||
|Ours|87.03|82.48|84.69|61.71|58.43|60.03|48.73 (size=768)|[download link](https://paddleocr.bj.bcebos.com/dygraph_v2.0/pgnet/en_server_pgnetA.tar)|
|
||||
|
||||
*note:PGNet in PaddleOCR optimizes the prediction speed, and can significantly improve the end-to-end prediction speed within the acceptable range of accuracy reduction*
|
||||
|
||||
## 2. Environment Configuration
|
||||
|
||||
Please refer to [Operation Environment Preparation](../../ppocr/environment.en.md) to configure PaddleOCR operating environment first, refer to [Project Clone](../../ppocr/blog/clone.en.md) to clone the project
|
||||
|
||||
## 3. Quick Use
|
||||
|
||||
### Inference model download
|
||||
|
||||
This section takes the trained end-to-end model as an example to quickly use the model prediction. First, download the trained end-to-end inference model [download address](https://paddleocr.bj.bcebos.com/dygraph_v2.0/pgnet/e2e_server_pgnetA_infer.tar)
|
||||
|
||||
```bash linenums="1"
|
||||
mkdir inference && cd inference
|
||||
# Download the English end-to-end model and unzip it
|
||||
wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/pgnet/e2e_server_pgnetA_infer.tar && tar xf e2e_server_pgnetA_infer.tar
|
||||
```
|
||||
|
||||
- In Windows environment, if 'wget' is not installed, the link can be copied to the browser when downloading the model, and decompressed and placed in the corresponding directory
|
||||
|
||||
After decompression, there should be the following file structure:
|
||||
|
||||
```text linenums="1"
|
||||
├── e2e_server_pgnetA_infer
|
||||
│ ├── inference.pdiparams
|
||||
│ ├── inference.pdiparams.info
|
||||
│ └── inference.pdmodel
|
||||
```
|
||||
|
||||
### Single image or image set prediction
|
||||
|
||||
```bash linenums="1"
|
||||
# Prediction single image specified by image_dir
|
||||
python3 tools/infer/predict_e2e.py --e2e_algorithm="PGNet" --image_dir="./doc/imgs_en/img623.jpg" --e2e_model_dir="./inference/e2e_server_pgnetA_infer/" --e2e_pgnet_valid_set="totaltext"
|
||||
|
||||
# Prediction the collection of images specified by image_dir
|
||||
python3 tools/infer/predict_e2e.py --e2e_algorithm="PGNet" --image_dir="./doc/imgs_en/" --e2e_model_dir="./inference/e2e_server_pgnetA_infer/" --e2e_pgnet_valid_set="totaltext"
|
||||
|
||||
# If you want to use CPU for prediction, you need to set use_gpu parameter is false
|
||||
python3 tools/infer/predict_e2e.py --e2e_algorithm="PGNet" --image_dir="./doc/imgs_en/img623.jpg" --e2e_model_dir="./inference/e2e_server_pgnetA_infer/" --use_gpu=False --e2e_pgnet_valid_set="totaltext"
|
||||
```
|
||||
|
||||
### Visualization results
|
||||
|
||||
The visualized end-to-end results are saved to the `./inference_results` folder by default, and the name of the result file is prefixed with 'e2e_res'. Examples of results are as follows:
|
||||
|
||||

|
||||
|
||||
## 4. Model Training,Evaluation And Inference
|
||||
|
||||
This section takes the totaltext dataset as an example to introduce the training, evaluation and testing of the end-to-end model in PaddleOCR.
|
||||
|
||||
### Data Preparation
|
||||
|
||||
Download and unzip [totaltext](https://paddleocr.bj.bcebos.com/dataset/total_text.tar) dataset to PaddleOCR/train_data/, dataset organization structure is as follow:
|
||||
|
||||
```text linenums="1"
|
||||
/PaddleOCR/train_data/total_text/train/
|
||||
|- rgb/ # total_text training data of dataset
|
||||
|- img11.png
|
||||
| ...
|
||||
|- train.txt # total_text training annotation of dataset
|
||||
```
|
||||
|
||||
total_text.txt: the format of dimension file is as follows,the file name and annotation information are separated by "\t":
|
||||
|
||||
```text linenums="1"
|
||||
" Image file name Image annotation information encoded by json.dumps"
|
||||
rgb/img11.jpg [{"transcription": "ASRAMA", "points": [[214.0, 325.0], [235.0, 308.0], [259.0, 296.0], [286.0, 291.0], [313.0, 295.0], [338.0, 305.0], [362.0, 320.0], [349.0, 347.0], [330.0, 337.0], [310.0, 329.0], [290.0, 324.0], [269.0, 328.0], [249.0, 336.0], [231.0, 346.0]]}, {...}]
|
||||
```
|
||||
|
||||
The image annotation after **json.dumps()** encoding is a list containing multiple dictionaries.
|
||||
|
||||
The `points` in the dictionary represent the coordinates (x, y) of the four points of the text box, arranged clockwise from the point at the upper left corner.
|
||||
|
||||
`transcription` represents the text of the current text box. **When its content is "###" it means that the text box is invalid and will be skipped during training.**
|
||||
|
||||
If you want to train PaddleOCR on other datasets, please build the annotation file according to the above format.
|
||||
|
||||
### Start Training
|
||||
|
||||
PGNet training is divided into two steps: Step 1: training on the synthetic data to get the pretrain_model, and the accuracy of the model is still low; step 2: loading the pretrain_model and training on the totaltext data set; for fast training, we directly provide the pre training model of step 1[download link](https://paddleocr.bj.bcebos.com/dygraph_v2.0/pgnet/train_step1.tar).
|
||||
|
||||
```bash linenums="1"
|
||||
cd PaddleOCR/
|
||||
|
||||
# download step1 pretrain_models
|
||||
wget -P ./pretrain_models/ https://paddleocr.bj.bcebos.com/dygraph_v2.0/pgnet/train_step1.tar
|
||||
|
||||
# You can get the following file format
|
||||
./pretrain_models/train_step1/
|
||||
└─ best_accuracy.pdopt
|
||||
└─ best_accuracy.states
|
||||
└─ best_accuracy.pdparams
|
||||
```
|
||||
|
||||
*If CPU version installed, please set the parameter `use_gpu` to `false` in the configuration.*
|
||||
|
||||
```bash linenums="1"
|
||||
# single GPU training
|
||||
python3 tools/train.py -c configs/e2e/e2e_r50_vd_pg.yml -o Global.pretrained_model=./pretrain_models/train_step1/best_accuracy Global.load_static_weights=False
|
||||
# multi-GPU training
|
||||
# Set the GPU ID used by the '--gpus' parameter.
|
||||
python3 -m paddle.distributed.launch --gpus '0,1,2,3' tools/train.py -c configs/e2e/e2e_r50_vd_pg.yml -o Global.pretrained_model=./pretrain_models/train_step1/best_accuracy Global.load_static_weights=False
|
||||
```
|
||||
|
||||
In the above instruction, use `-c` to select the training to use the `configs/e2e/e2e_r50_vd_pg.yml` configuration file.
|
||||
For a detailed explanation of the configuration file, please refer to [config](../../ppocr/blog/config.en.md).
|
||||
|
||||
You can also use `-o` to change the training parameters without modifying the yml file. For example, adjust the training learning rate to 0.0001
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/train.py -c configs/e2e/e2e_r50_vd_pg.yml -o Optimizer.base_lr=0.0001
|
||||
```
|
||||
|
||||
#### Load trained model and continue training
|
||||
|
||||
If you would like to load trained model and continue the training again, you can specify the parameter `Global.checkpoints` as the model path to be loaded.
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/train.py -c configs/e2e/e2e_r50_vd_pg.yml -o Global.checkpoints=./your/trained/model
|
||||
```
|
||||
|
||||
**Note**: The priority of `Global.checkpoints` is higher than that of `Global.pretrain_weights`, that is, when two parameters are specified at the same time, the model specified by `Global.checkpoints` will be loaded first. If the model path specified by `Global.checkpoints` is wrong, the one specified by `Global.pretrain_weights` will be loaded.
|
||||
|
||||
PaddleOCR calculates three indicators for evaluating performance of OCR end-to-end task: Precision, Recall, and Hmean.
|
||||
|
||||
Run the following code to calculate the evaluation indicators. The result will be saved in the test result file specified by `save_res_path` in the configuration file `e2e_r50_vd_pg.yml`
|
||||
When evaluating, set post-processing parameters `max_side_len=768`. If you use different datasets, different models for training.
|
||||
The model parameters during training are saved in the `Global.save_model_dir` directory by default. When evaluating indicators, you need to set `Global.checkpoints` to point to the saved parameter file.
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/eval.py -c configs/e2e/e2e_r50_vd_pg.yml -o Global.checkpoints="{path/to/weights}/best_accuracy"
|
||||
```
|
||||
|
||||
### Model Test
|
||||
|
||||
Test the end-to-end result on a single image:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer_e2e.py -c configs/e2e/e2e_r50_vd_pg.yml -o Global.infer_img="./doc/imgs_en/img_10.jpg" Global.pretrained_model="./output/e2e_pgnet/best_accuracy" Global.load_static_weights=false
|
||||
```
|
||||
|
||||
Test the end-to-end result on all images in the folder:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer_e2e.py -c configs/e2e/e2e_r50_vd_pg.yml -o Global.infer_img="./doc/imgs_en/" Global.pretrained_model="./output/e2e_pgnet/best_accuracy" Global.load_static_weights=false
|
||||
```
|
||||
|
||||
### Model inference
|
||||
|
||||
#### (1).Quadrangle text detection model (ICDAR2015)
|
||||
|
||||
First, convert the model saved in the PGNet end-to-end training process into an inference model. In the first stage of training based on composite dataset, the model of English data set training is taken as an example[model download link](https://paddleocr.bj.bcebos.com/dygraph_v2.0/pgnet/en_server_pgnetA.tar), you can use the following command to convert:
|
||||
|
||||
```bash linenums="1"
|
||||
wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/pgnet/en_server_pgnetA.tar && tar xf en_server_pgnetA.tar
|
||||
python3 tools/export_model.py -c configs/e2e/e2e_r50_vd_pg.yml -o Global.pretrained_model=./en_server_pgnetA/best_accuracy Global.load_static_weights=False Global.save_inference_dir=./inference/e2e
|
||||
```
|
||||
|
||||
**For PGNet quadrangle end-to-end model inference, you need to set the parameter `--e2e_algorithm="PGNet"` and `--e2e_pgnet_valid_set="partvgg"`**, run the following command:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_e2e.py --e2e_algorithm="PGNet" --image_dir="./doc/imgs_en/img_10.jpg" --e2e_model_dir="./inference/e2e/" --e2e_pgnet_valid_set="partvgg"
|
||||
```
|
||||
|
||||
The visualized text detection results are saved to the `./inference_results` folder by default, and the name of the result file is prefixed with 'e2e_res'. Examples of results are as follows:
|
||||
|
||||

|
||||
|
||||
#### (2). Curved text detection model (Total-Text)
|
||||
|
||||
For the curved text example, we use the same model as the quadrilateral
|
||||
**For PGNet end-to-end curved text detection model inference, you need to set the parameter `--e2e_algorithm="PGNet"` and `--e2e_pgnet_valid_set="totaltext"`**, run the following command:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_e2e.py --e2e_algorithm="PGNet" --image_dir="./doc/imgs_en/img623.jpg" --e2e_model_dir="./inference/e2e/" --e2e_pgnet_valid_set="totaltext"
|
||||
```
|
||||
|
||||
The visualized text detection results are saved to the `./inference_results` folder by default, and the name of the result file is prefixed with 'e2e_res'. Examples of results are as follows:
|
||||
|
||||

|
||||
@@ -0,0 +1,220 @@
|
||||
---
|
||||
comments: true
|
||||
---
|
||||
|
||||
## 一、简介
|
||||
|
||||
OCR算法可以分为两阶段算法和端对端的算法。二阶段OCR算法一般分为两个部分,文本检测和文本识别算法,文件检测算法从图像中得到文本行的检测框,然后识别算法去识别文本框中的内容。而端对端OCR算法可以在一个算法中完成文字检测和文字识别,其基本思想是设计一个同时具有检测单元和识别模块的模型,共享其中两者的CNN特征,并联合训练。由于一个算法即可完成文字识别,端对端模型更小,速度更快。
|
||||
|
||||
### PGNet算法介绍
|
||||
|
||||
近些年来,端对端OCR算法得到了良好的发展,包括MaskTextSpotter系列、TextSnake、TextDragon、PGNet系列等算法。在这些算法中,PGNet算法具备其他算法不具备的优势,包括:
|
||||
|
||||
- 设计PGNet loss指导训练,不需要字符级别的标注
|
||||
- 不需要NMS和ROI相关操作,加速预测
|
||||
- 提出预测文本行内的阅读顺序模块;
|
||||
- 提出基于图的修正模块(GRM)来进一步提高模型识别性能
|
||||
- 精度更高,预测速度更快
|
||||
|
||||
PGNet算法细节详见[论文](https://cdn.aaai.org/ojs/16383/16383-13-19877-1-2-20210518.pdf) ,算法原理图如下所示:
|
||||
|
||||

|
||||
|
||||
输入图像经过特征提取送入四个分支,分别是:文本边缘偏移量预测TBO模块,文本中心线预测TCL模块,文本方向偏移量预测TDO模块,以及文本字符分类图预测TCC模块。
|
||||
其中TBO以及TCL的输出经过后处理后可以得到文本的检测结果,TCL、TDO、TCC负责文本识别。
|
||||
|
||||
其检测识别效果图如下:
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
### 性能指标
|
||||
|
||||
#### 测试集: Total Text
|
||||
|
||||
#### 测试环境: NVIDIA Tesla V100-SXM2-16GB
|
||||
|
||||
|PGNetA|det_precision|det_recall|det_f_score|e2e_precision|e2e_recall|e2e_f_score|FPS|下载|
|
||||
| --- | --- | --- | --- | --- | --- | --- | --- | --- |
|
||||
|Paper|85.30|86.80|86.10|-|-|61.70|38.20 (size=640)|-|
|
||||
|Ours|87.03|82.48|84.69|61.71|58.43|60.03|48.73 (size=768)|[下载链接](https://paddleocr.bj.bcebos.com/dygraph_v2.0/pgnet/en_server_pgnetA.tar)|
|
||||
|
||||
*note:PaddleOCR里的PGNet实现针对预测速度做了优化,在精度下降可接受范围内,可以显著提升端对端预测速度*
|
||||
|
||||
## 二、环境配置
|
||||
|
||||
请先参考[《运行环境准备》](../../ppocr/environment.md)配置PaddleOCR运行环境,参考[《项目克隆》](../../ppocr/blog/clone.md)克隆项目
|
||||
|
||||
## 三、快速使用
|
||||
|
||||
### inference模型下载
|
||||
|
||||
本节以训练好的端到端模型为例,快速使用模型预测,首先下载训练好的端到端inference模型[下载地址](https://paddleocr.bj.bcebos.com/dygraph_v2.0/pgnet/e2e_server_pgnetA_infer.tar)
|
||||
|
||||
```bash linenums="1"
|
||||
mkdir inference && cd inference
|
||||
# 下载英文端到端模型并解压
|
||||
wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/pgnet/e2e_server_pgnetA_infer.tar && tar xf e2e_server_pgnetA_infer.tar
|
||||
```
|
||||
|
||||
- windows 环境下如果没有安装wget,下载模型时可将链接复制到浏览器中下载,并解压放置在相应目录下
|
||||
|
||||
解压完毕后应有如下文件结构:
|
||||
|
||||
```text linenums="1"
|
||||
├── e2e_server_pgnetA_infer
|
||||
│ ├── inference.pdiparams
|
||||
│ ├── inference.pdiparams.info
|
||||
│ └── inference.pdmodel
|
||||
```
|
||||
|
||||
### 单张图像或者图像集合预测
|
||||
|
||||
```bash linenums="1"
|
||||
# 预测image_dir指定的单张图像
|
||||
python3 tools/infer/predict_e2e.py --e2e_algorithm="PGNet" --image_dir="./doc/imgs_en/img623.jpg" --e2e_model_dir="./inference/e2e_server_pgnetA_infer/" --e2e_pgnet_valid_set="totaltext"
|
||||
|
||||
# 预测image_dir指定的图像集合
|
||||
python3 tools/infer/predict_e2e.py --e2e_algorithm="PGNet" --image_dir="./doc/imgs_en/" --e2e_model_dir="./inference/e2e_server_pgnetA_infer/" --e2e_pgnet_valid_set="totaltext"
|
||||
|
||||
# 如果想使用CPU进行预测,需设置use_gpu参数为False
|
||||
python3 tools/infer/predict_e2e.py --e2e_algorithm="PGNet" --image_dir="./doc/imgs_en/img623.jpg" --e2e_model_dir="./inference/e2e_server_pgnetA_infer/" --e2e_pgnet_valid_set="totaltext" --use_gpu=False
|
||||
```
|
||||
|
||||
### 可视化结果
|
||||
|
||||
可视化文本检测结果默认保存到./inference_results文件夹里面,结果文件的名称前缀为'e2e_res'。结果示例如下:
|
||||
|
||||

|
||||
|
||||
## 四、模型训练、评估、推理
|
||||
|
||||
本节以totaltext数据集为例,介绍PaddleOCR中端到端模型的训练、评估与测试。
|
||||
|
||||
### 准备数据
|
||||
|
||||
下载解压[totaltext](https://paddleocr.bj.bcebos.com/dataset/total_text.tar) 数据集到PaddleOCR/train_data/目录,数据集组织结构:
|
||||
|
||||
```text linenums="1"
|
||||
/PaddleOCR/train_data/total_text/train/
|
||||
|- rgb/ # total_text数据集的训练数据
|
||||
|- img11.jpg
|
||||
| ...
|
||||
|- train.txt # total_text数据集的训练标注
|
||||
```
|
||||
|
||||
train.txt标注文件格式如下,文件名和标注信息中间用"\t"分隔:
|
||||
|
||||
```text linenums="1"
|
||||
" 图像文件名 json.dumps编码的图像标注信息"
|
||||
rgb/img11.jpg [{"transcription": "ASRAMA", "points": [[214.0, 325.0], [235.0, 308.0], [259.0, 296.0], [286.0, 291.0], [313.0, 295.0], [338.0, 305.0], [362.0, 320.0], [349.0, 347.0], [330.0, 337.0], [310.0, 329.0], [290.0, 324.0], [269.0, 328.0], [249.0, 336.0], [231.0, 346.0]]}, {...}]
|
||||
```
|
||||
|
||||
json.dumps编码前的图像标注信息是包含多个字典的list,字典中的 `points` 表示文本框的四个点的坐标(x, y),从左上角的点开始顺时针排列。
|
||||
`transcription` 表示当前文本框的文字,**当其内容为“###”时,表示该文本框无效,在训练时会跳过。**
|
||||
如果您想在其他数据集上训练,可以按照上述形式构建标注文件。
|
||||
|
||||
### 启动训练
|
||||
|
||||
PGNet训练分为两个步骤:step1: 在合成数据上训练,得到预训练模型,此时模型精度依然较低;step2: 加载预训练模型,在totaltext数据集上训练;为快速训练,我们直接提供了step1的预训练模型。
|
||||
|
||||
```bash linenums="1"
|
||||
cd PaddleOCR/
|
||||
# 下载step1 预训练模型
|
||||
wget -P ./pretrain_models/ https://paddleocr.bj.bcebos.com/dygraph_v2.0/pgnet/train_step1.tar
|
||||
|
||||
# 可以得到以下的文件格式
|
||||
./pretrain_models/train_step1/
|
||||
└─ best_accuracy.pdopt
|
||||
└─ best_accuracy.states
|
||||
└─ best_accuracy.pdparams
|
||||
```
|
||||
|
||||
*如果您安装的是cpu版本,请将配置文件中的 `use_gpu` 字段修改为false*
|
||||
|
||||
```bash linenums="1"
|
||||
# 单机单卡训练 e2e 模型
|
||||
python3 tools/train.py -c configs/e2e/e2e_r50_vd_pg.yml -o Global.pretrained_model=./pretrain_models/train_step1/best_accuracy Global.load_static_weights=False
|
||||
# 单机多卡训练,通过 --gpus 参数设置使用的GPU ID
|
||||
python3 -m paddle.distributed.launch --gpus '0,1,2,3' tools/train.py -c configs/e2e/e2e_r50_vd_pg.yml -o Global.pretrained_model=./pretrain_models/train_step1/best_accuracy Global.load_static_weights=False
|
||||
```
|
||||
|
||||
上述指令中,通过-c 选择训练使用configs/e2e/e2e_r50_vd_pg.yml配置文件。
|
||||
有关配置文件的详细解释,请参考[链接](../../ppocr/blog/config.md)。
|
||||
|
||||
您也可以通过-o参数在不需要修改yml文件的情况下,改变训练的参数,比如,调整训练的学习率为0.0001
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/train.py -c configs/e2e/e2e_r50_vd_pg.yml -o Optimizer.base_lr=0.0001
|
||||
```
|
||||
|
||||
#### 断点训练
|
||||
|
||||
如果训练程序中断,如果希望加载训练中断的模型从而恢复训练,可以通过指定Global.checkpoints指定要加载的模型路径:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/train.py -c configs/e2e/e2e_r50_vd_pg.yml -o Global.checkpoints=./your/trained/model
|
||||
```
|
||||
|
||||
**注意**:`Global.checkpoints`的优先级高于`Global.pretrain_weights`的优先级,即同时指定两个参数时,优先加载`Global.checkpoints`指定的模型,如果`Global.checkpoints`指定的模型路径有误,会加载`Global.pretrain_weights`指定的模型。
|
||||
|
||||
PaddleOCR计算三个OCR端到端相关的指标,分别是:Precision、Recall、Hmean。
|
||||
|
||||
运行如下代码,根据配置文件`e2e_r50_vd_pg.yml`中`save_res_path`指定的测试集检测结果文件,计算评估指标。
|
||||
|
||||
评估时设置后处理参数`max_side_len=768`,使用不同数据集、不同模型训练,可调整参数进行优化
|
||||
训练中模型参数默认保存在`Global.save_model_dir`目录下。在评估指标时,需要设置`Global.checkpoints`指向保存的参数文件。
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/eval.py -c configs/e2e/e2e_r50_vd_pg.yml -o Global.checkpoints="{path/to/weights}/best_accuracy"
|
||||
```
|
||||
|
||||
### 模型预测
|
||||
|
||||
测试单张图像的端到端识别效果
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer_e2e.py -c configs/e2e/e2e_r50_vd_pg.yml -o Global.infer_img="./doc/imgs_en/img_10.jpg" Global.pretrained_model="./output/e2e_pgnet/best_accuracy" Global.load_static_weights=false
|
||||
```
|
||||
|
||||
测试文件夹下所有图像的端到端识别效果
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer_e2e.py -c configs/e2e/e2e_r50_vd_pg.yml -o Global.infer_img="./doc/imgs_en/" Global.pretrained_model="./output/e2e_pgnet/best_accuracy" Global.load_static_weights=false
|
||||
```
|
||||
|
||||
### 预测推理
|
||||
|
||||
#### (1). 四边形文本检测模型(ICDAR2015)
|
||||
|
||||
首先将PGNet端到端训练过程中保存的模型,转换成inference model。以基于Resnet50_vd骨干网络,以英文数据集训练的模型为例[模型下载地址](https://paddleocr.bj.bcebos.com/dygraph_v2.0/pgnet/en_server_pgnetA.tar) ,可以使用如下命令进行转换:
|
||||
|
||||
```bash linenums="1"
|
||||
wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/pgnet/en_server_pgnetA.tar && tar xf en_server_pgnetA.tar
|
||||
python3 tools/export_model.py -c configs/e2e/e2e_r50_vd_pg.yml -o Global.pretrained_model=./en_server_pgnetA/best_accuracy Global.load_static_weights=False Global.save_inference_dir=./inference/e2e
|
||||
```
|
||||
|
||||
**PGNet端到端模型推理,需要设置参数`--e2e_algorithm="PGNet"` and `--e2e_pgnet_valid_set="partvgg"`**,可以执行如下命令:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_e2e.py --e2e_algorithm="PGNet" --image_dir="./doc/imgs_en/img_10.jpg" --e2e_model_dir="./inference/e2e/" --e2e_pgnet_valid_set="partvgg" --e2e_pgnet_valid_set="totaltext"
|
||||
```
|
||||
|
||||
可视化文本检测结果默认保存到`./inference_results`文件夹里面,结果文件的名称前缀为'e2e_res'。结果示例如下:
|
||||
|
||||

|
||||
|
||||
#### (2). 弯曲文本检测模型(Total-Text)
|
||||
|
||||
对于弯曲文本样例
|
||||
|
||||
**PGNet端到端模型推理,需要设置参数`--e2e_algorithm="PGNet"`,同时,还需要增加参数`--e2e_pgnet_valid_set="totaltext"`,**可以执行如下命令:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_e2e.py --e2e_algorithm="PGNet" --image_dir="./doc/imgs_en/img623.jpg" --e2e_model_dir="./inference/e2e/" --e2e_pgnet_valid_set="totaltext"
|
||||
```
|
||||
|
||||
可视化文本端到端结果默认保存到`./inference_results`文件夹里面,结果文件的名称前缀为'e2e_res'。结果示例如下:
|
||||
|
||||

|
||||
|
After Width: | Height: | Size: 663 KiB |
|
After Width: | Height: | Size: 467 KiB |
|
After Width: | Height: | Size: 134 KiB |
|
After Width: | Height: | Size: 337 KiB |
|
After Width: | Height: | Size: 242 KiB |
@@ -0,0 +1,99 @@
|
||||
---
|
||||
comments: true
|
||||
---
|
||||
|
||||
## 1. Introduction
|
||||
|
||||
Paper:
|
||||
> [When Counting Meets HMER: Counting-Aware Network for Handwritten Mathematical Expression Recognition](https://arxiv.org/abs/2207.11463)
|
||||
> Bohan Li, Ye Yuan, Dingkang Liang, Xiao Liu, Zhilong Ji, Jinfeng Bai, Wenyu Liu, Xiang Bai
|
||||
> ECCV, 2022
|
||||
|
||||
Using CROHME handwrittem mathematical expression recognition datasets for training, and evaluating on its test sets, the algorithm reproduction effect is as follows:
|
||||
|
||||
|Model|Backbone|config|exprate|Download link|
|
||||
| --- | --- | --- | --- | --- |
|
||||
|CAN|DenseNet|[rec_d28_can.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/rec/rec_d28_can.yml)|51.72%|[trained model](https://paddleocr.bj.bcebos.com/contribution/rec_d28_can_train.tar)|
|
||||
|
||||
## 2. Environment
|
||||
|
||||
Please refer to ["Environment Preparation"](../../ppocr/environment.en.md) to configure the PaddleOCR environment, and refer to ["Project Clone"](../../ppocr/blog/clone.en.md)to clone the project code.
|
||||
|
||||
## 3. Model Training / Evaluation / Prediction
|
||||
|
||||
Please refer to [Text Recognition Tutorial](../../ppocr/model_train/recognition.en.md). PaddleOCR modularizes the code, and training different recognition models only requires **changing the configuration file**.
|
||||
|
||||
### Training
|
||||
|
||||
Specifically, after the data preparation is completed, the training can be started. The training command is as follows:
|
||||
|
||||
```bash linenums="1"
|
||||
# Single GPU training (long training period, not recommended)
|
||||
python3 tools/train.py -c configs/rec/rec_d28_can.yml
|
||||
|
||||
# Multi GPU training, specify the gpu number through the --gpus parameter
|
||||
python3 -m paddle.distributed.launch --gpus '0,1,2,3' tools/train.py -c configs/rec/rec_d28_can.yml
|
||||
```
|
||||
|
||||
### Evaluation
|
||||
|
||||
```bash linenums="1"
|
||||
# GPU evaluation
|
||||
python3 -m paddle.distributed.launch --gpus '0' tools/eval.py -c configs/rec/rec_d28_can.yml -o Global.pretrained_model=./rec_d28_can_train/best_accuracy.pdparams
|
||||
```
|
||||
|
||||
Prediction:
|
||||
|
||||
```bash linenums="1"
|
||||
# The configuration file used for prediction must match the training
|
||||
python3 tools/infer_rec.py -c configs/rec/rec_d28_can.yml -o Architecture.Head.attdecoder.is_train=False Global.infer_img='./doc/crohme_demo/hme_00.jpg' Global.pretrained_model=./rec_d28_can_train/best_accuracy.pdparams
|
||||
```
|
||||
|
||||
## 4. Inference and Deployment
|
||||
|
||||
### 4.1 Python Inference
|
||||
|
||||
First, the model saved during the CAN handwritten mathematical expression recognition training process is converted into an inference model. you can use the following command to convert:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/export_model.py -c configs/rec/rec_d28_can.yml -o Global.pretrained_model=./rec_d28_can_train/best_accuracy.pdparams Global.save_inference_dir=./inference/rec_d28_can/ Architecture.Head.attdecoder.is_train=False
|
||||
|
||||
# The default output max length of the model is 36. If you need to predict a longer sequence, please specify its output sequence as an appropriate value when exporting the model, as: Architecture.Head.max_ text_ length=72
|
||||
```
|
||||
|
||||
For CAN handwritten mathematical expression recognition model inference, the following commands can be executed:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_rec.py --image_dir="./doc/datasets/crohme_demo/hme_00.jpg" --rec_algorithm="CAN" --rec_batch_num=1 --rec_model_dir="./inference/rec_d28_can/" --rec_char_dict_path="./ppocr/utils/dict/latex_symbol_dict.txt"
|
||||
|
||||
# If you need to predict on a picture with black characters on a white background, please set: -- rec_ image_ inverse=False
|
||||
```
|
||||
|
||||
### 4.2 C++ Inference
|
||||
|
||||
Not supported
|
||||
|
||||
### 4.3 Serving
|
||||
|
||||
Not supported
|
||||
|
||||
### 4.4 More
|
||||
|
||||
Not supported
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
## Citation
|
||||
|
||||
```bibtex
|
||||
@misc{https://doi.org/10.48550/arxiv.2207.11463,
|
||||
doi = {10.48550/ARXIV.2207.11463},
|
||||
url = {https://arxiv.org/abs/2207.11463},
|
||||
author = {Li, Bohan and Yuan, Ye and Liang, Dingkang and Liu, Xiao and Ji, Zhilong and Bai, Jinfeng and Liu, Wenyu and Bai, Xiang},
|
||||
keywords = {Computer Vision and Pattern Recognition (cs.CV), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
||||
title = {When Counting Meets HMER: Counting-Aware Network for Handwritten Mathematical Expression Recognition},
|
||||
publisher = {arXiv},
|
||||
year = {2022},
|
||||
copyright = {arXiv.org perpetual, non-exclusive license}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,155 @@
|
||||
---
|
||||
typora-copy-images-to: images
|
||||
comments: true
|
||||
---
|
||||
|
||||
# 手写数学公式识别算法-CAN
|
||||
|
||||
## 1. 算法简介
|
||||
|
||||
论文信息:
|
||||
> [When Counting Meets HMER: Counting-Aware Network for Handwritten Mathematical Expression Recognition](https://arxiv.org/abs/2207.11463)
|
||||
> Bohan Li, Ye Yuan, Dingkang Liang, Xiao Liu, Zhilong Ji, Jinfeng Bai, Wenyu Liu, Xiang Bai
|
||||
> ECCV, 2022
|
||||
|
||||
`CAN`使用CROHME手写公式数据集进行训练,在对应测试集上的精度如下:
|
||||
|
||||
|模型 |骨干网络|配置文件|ExpRate|下载链接|
|
||||
| ----- | ----- | ----- | ----- | ----- |
|
||||
|CAN|DenseNet|[rec_d28_can.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/rec/rec_d28_can.yml)|51.72%|[训练模型](https://paddleocr.bj.bcebos.com/contribution/rec_d28_can_train.tar)|
|
||||
|
||||
## 2. 环境配置
|
||||
|
||||
请先参考[《运行环境准备》](../../ppocr/environment.md)配置PaddleOCR运行环境,参考[《项目克隆》](../../ppocr/blog/clone.md)克隆项目代码。
|
||||
|
||||
## 3. 模型训练、评估、预测
|
||||
|
||||
### 3.1 模型训练
|
||||
|
||||
请参考[文本识别训练教程](../../ppocr/model_train/recognition.md)。PaddleOCR对代码进行了模块化,训练`CAN`识别模型时需要**更换配置文件**为`CAN`的[配置文件](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/rec/rec_d28_can.yml)。
|
||||
|
||||
#### 启动训练
|
||||
|
||||
具体地,在完成数据准备后,便可以启动训练,训练命令如下:
|
||||
|
||||
```bash linenums="1"
|
||||
#单卡训练(训练周期长,不建议)
|
||||
python3 tools/train.py -c configs/rec/rec_d28_can.yml
|
||||
|
||||
# 多卡训练,通过--gpus参数指定卡号
|
||||
python3 -m paddle.distributed.launch --gpus '0,1,2,3' tools/train.py -c configs/rec/rec_d28_can.yml
|
||||
```
|
||||
|
||||
**注意:**
|
||||
|
||||
- 我们提供的数据集,即[`CROHME数据集`](https://paddleocr.bj.bcebos.com/dataset/CROHME.tar)将手写公式存储为黑底白字的格式,若您自行准备的数据集与之相反,即以白底黑字模式存储,请在训练时做出如下修改
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/train.py -c configs/rec/rec_d28_can.yml -o Train.dataset.transforms.GrayImageChannelFormat.inverse=False
|
||||
```
|
||||
|
||||
- 默认每训练1个epoch(1105次iteration)进行1次评估,若您更改训练的batch_size,或更换数据集,请在训练时作出如下修改
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/train.py -c configs/rec/rec_d28_can.yml -o Global.eval_batch_step=[0, {length_of_dataset//batch_size}]
|
||||
```
|
||||
|
||||
### 3.2 评估
|
||||
|
||||
可下载已训练完成的[模型文件](https://paddleocr.bj.bcebos.com/contribution/rec_d28_can_train.tar),使用如下命令进行评估:
|
||||
|
||||
```bash linenums="1"
|
||||
# 注意将pretrained_model的路径设置为本地路径。若使用自行训练保存的模型,请注意修改路径和文件名为{path/to/weights}/{model_name}。
|
||||
python3 -m paddle.distributed.launch --gpus '0' tools/eval.py -c configs/rec/rec_d28_can.yml -o Global.pretrained_model=./rec_d28_can_train/best_accuracy.pdparams
|
||||
```
|
||||
|
||||
### 3.3 预测
|
||||
|
||||
使用如下命令进行单张图片预测:
|
||||
|
||||
```bash linenums="1"
|
||||
# 注意将pretrained_model的路径设置为本地路径。
|
||||
python3 tools/infer_rec.py -c configs/rec/rec_d28_can.yml -o Architecture.Head.attdecoder.is_train=False Global.infer_img='./doc/datasets/crohme_demo/hme_00.jpg' Global.pretrained_model=./rec_d28_can_train/best_accuracy.pdparams
|
||||
|
||||
# 预测文件夹下所有图像时,可修改infer_img为文件夹,如 Global.infer_img='./doc/datasets/crohme_demo/'。
|
||||
```
|
||||
|
||||
## 4. 推理部署
|
||||
|
||||
### 4.1 Python推理
|
||||
|
||||
首先将训练得到best模型,转换成inference model。这里以训练完成的模型为例([模型下载地址](https://paddleocr.bj.bcebos.com/contribution/rec_d28_can_train.tar) ),可以使用如下命令进行转换:
|
||||
|
||||
```bash linenums="1"
|
||||
# 注意将pretrained_model的路径设置为本地路径。
|
||||
python3 tools/export_model.py -c configs/rec/rec_d28_can.yml -o Global.pretrained_model=./rec_d28_can_train/best_accuracy.pdparams Global.save_inference_dir=./inference/rec_d28_can/ Architecture.Head.attdecoder.is_train=False
|
||||
|
||||
# 目前的静态图模型默认的输出长度最大为36,如果您需要预测更长的序列,请在导出模型时指定其输出序列为合适的值,例如 Architecture.Head.max_text_length=72
|
||||
```
|
||||
|
||||
**注意:**
|
||||
如果您是在自己的数据集上训练的模型,并且调整了字典文件,请注意修改配置文件中的`character_dict_path`是否是所需要的字典文件。
|
||||
|
||||
转换成功后,在目录下有三个文件:
|
||||
|
||||
```text linenums="1"
|
||||
/inference/rec_d28_can/
|
||||
├── inference.pdiparams # 识别inference模型的参数文件
|
||||
├── inference.pdiparams.info # 识别inference模型的参数信息,可忽略
|
||||
└── inference.pdmodel # 识别inference模型的program文件
|
||||
```
|
||||
|
||||
执行如下命令进行模型推理:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_rec.py --image_dir="./doc/datasets/crohme_demo/hme_00.jpg" --rec_algorithm="CAN" --rec_batch_num=1 --rec_model_dir="./inference/rec_d28_can/" --rec_char_dict_path="./ppocr/utils/dict/latex_symbol_dict.txt"
|
||||
|
||||
# 预测文件夹下所有图像时,可修改image_dir为文件夹,如 --image_dir='./doc/datasets/crohme_demo/'。
|
||||
|
||||
# 如果您需要在白底黑字的图片上进行预测,请设置 --rec_image_inverse=False
|
||||
```
|
||||
|
||||

|
||||
|
||||
执行命令后,上面图像的预测结果(识别的文本)会打印到屏幕上,示例如下:
|
||||
|
||||
```bash linenums="1"
|
||||
Predicts of ./doc/imgs_hme/hme_00.jpg:['x _ { k } x x _ { k } + y _ { k } y x _ { k }', []]
|
||||
```
|
||||
|
||||
**注意**:
|
||||
|
||||
- 需要注意预测图像为**黑底白字**,即手写公式部分为白色,背景为黑色的图片。
|
||||
- 在推理时需要设置参数`rec_char_dict_path`指定字典,如果您修改了字典,请修改该参数为您的字典文件。
|
||||
- 如果您修改了预处理方法,需修改`tools/infer/predict_rec.py`中CAN的预处理为您的预处理方法。
|
||||
|
||||
### 4.2 C++推理部署
|
||||
|
||||
由于C++预处理后处理还未支持CAN,所以暂未支持
|
||||
|
||||
### 4.3 Serving服务化部署
|
||||
|
||||
暂不支持
|
||||
|
||||
### 4.4 更多推理部署
|
||||
|
||||
暂不支持
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
1. CROHME数据集来自于[CAN源repo](https://github.com/LBH1024/CAN) 。
|
||||
|
||||
## 引用
|
||||
|
||||
```bibtex
|
||||
@misc{https://doi.org/10.48550/arxiv.2207.11463,
|
||||
doi = {10.48550/ARXIV.2207.11463},
|
||||
url = {https://arxiv.org/abs/2207.11463},
|
||||
author = {Li, Bohan and Yuan, Ye and Liang, Dingkang and Liu, Xiao and Ji, Zhilong and Bai, Jinfeng and Liu, Wenyu and Bai, Xiang},
|
||||
keywords = {Computer Vision and Pattern Recognition (cs.CV), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
||||
title = {When Counting Meets HMER: Counting-Aware Network for Handwritten Mathematical Expression Recognition},
|
||||
publisher = {arXiv},
|
||||
year = {2022},
|
||||
copyright = {arXiv.org perpetual, non-exclusive license}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,105 @@
|
||||
# LaTeX-OCR
|
||||
|
||||
## 1. Introduction
|
||||
|
||||
Original Project:
|
||||
> [https://github.com/lukas-blecher/LaTeX-OCR](https://github.com/lukas-blecher/LaTeX-OCR)
|
||||
|
||||
|
||||
Using LaTeX-OCR printed mathematical expression recognition datasets for training, and evaluating on its test sets, the algorithm reproduction effect is as follows:
|
||||
|
||||
| Model | Backbone |config| BLEU score | normed edit distance | ExpRate |Download link|
|
||||
|-----------|----------| ---- |:-----------:|:---------------------:|:---------:| ----- |
|
||||
| LaTeX-OCR | Hybrid ViT |[LaTeX_OCR_rec.yaml](https://github.com/PaddlePaddle/PaddleOCR/blob/{{PADDLEOCR_GITHUB_REF}}/configs/rec/LaTeX_OCR_rec.yaml)| 0.8821 | 0.0823 | 40.01% |[trained model](https://paddleocr.bj.bcebos.com/contribution/rec_latex_ocr_train.tar)|
|
||||
|
||||
## 2. Environment
|
||||
Please refer to ["Environment Preparation"](../../ppocr/environment.en.md) to configure the PaddleOCR environment, and refer to ["Project Clone"](../../ppocr/blog/clone.en.md) to clone the project code.
|
||||
|
||||
Furthermore, additional dependencies need to be installed:
|
||||
```shell
|
||||
pip install -r docs/algorithm/formula_recognition/requirements.txt
|
||||
```
|
||||
|
||||
## 3. Model Training / Evaluation / Prediction
|
||||
|
||||
Please refer to [Text Recognition Tutorial](../../ppocr/model_train/recognition.en.md). PaddleOCR modularizes the code, and training different recognition models only requires **changing the configuration file**.
|
||||
|
||||
Pickle File Generation:
|
||||
|
||||
Download formulae.zip and math.txt in [Google Drive](https://drive.google.com/drive/folders/13CA4vAmOmD_I_dSbvLp-Lf0s6KiaNfuO), and then use the following command to generate the pickle file.
|
||||
|
||||
```shell
|
||||
# Create a LaTeX-OCR dataset directory
|
||||
mkdir -p train_data/LaTeXOCR
|
||||
# Unzip formulae.zip and copy math.txt
|
||||
unzip -d train_data/LaTeXOCR path/formulae.zip
|
||||
cp path/math.txt train_data/LaTeXOCR
|
||||
# Convert the original .txt file to a .pkl file to group images of different scales
|
||||
# Training set conversion
|
||||
python ppocr/utils/formula_utils/math_txt2pkl.py --image_dir=train_data/LaTeXOCR/train --mathtxt_path=train_data/LaTeXOCR/math.txt --output_dir=train_data/LaTeXOCR/
|
||||
# Validation set conversion
|
||||
python ppocr/utils/formula_utils/math_txt2pkl.py --image_dir=train_data/LaTeXOCR/val --mathtxt_path=train_data/LaTeXOCR/math.txt --output_dir=train_data/LaTeXOCR/
|
||||
# Test set conversion
|
||||
python ppocr/utils/formula_utils/math_txt2pkl.py --image_dir=train_data/LaTeXOCR/test --mathtxt_path=train_data/LaTeXOCR/math.txt --output_dir=train_data/LaTeXOCR/
|
||||
```
|
||||
|
||||
|
||||
Training:
|
||||
|
||||
Specifically, after the data preparation is completed, the training can be started. The training command is as follows:
|
||||
|
||||
```
|
||||
#Single GPU training (Default training method)
|
||||
python3 tools/train.py -c configs/rec/LaTeX_OCR_rec.yaml
|
||||
|
||||
#Multi GPU training, specify the gpu number through the --gpus parameter
|
||||
python3 -m paddle.distributed.launch --gpus '0,1,2,3' tools/train.py -c configs/rec/LaTeX_OCR_rec.yaml
|
||||
```
|
||||
|
||||
Evaluation:
|
||||
|
||||
```
|
||||
# GPU evaluation
|
||||
# Validation set evaluation
|
||||
python3 tools/eval.py -c configs/rec/LaTeX_OCR_rec.yaml -o Global.pretrained_model=./rec_latex_ocr_train/best_accuracy.pdparams
|
||||
# Test set evaluation
|
||||
python3 tools/eval.py -c configs/rec/LaTeX_OCR_rec.yaml -o Global.pretrained_model=./rec_latex_ocr_train/best_accuracy.pdparams Eval.dataset.data_dir=./train_data/LaTeXOCR/test Eval.dataset.data=./train_data/LaTeXOCR/latexocr_test.pkl
|
||||
```
|
||||
|
||||
Prediction:
|
||||
|
||||
```
|
||||
# The configuration file used for prediction must match the training
|
||||
python3 tools/infer_rec.py -c configs/rec/LaTeX_OCR_rec.yaml -o Global.infer_img='./docs/datasets/images/pme_demo/0000013.png' Global.pretrained_model=./rec_latex_ocr_train/best_accuracy.pdparams
|
||||
```
|
||||
|
||||
## 4. Inference and Deployment
|
||||
|
||||
### 4.1 Python Inference
|
||||
First, the model saved during the LaTeX-OCR printed mathematical expression recognition training process is converted into an inference model. you can use the following command to convert:
|
||||
|
||||
```
|
||||
python3 tools/export_model.py -c configs/rec/LaTeX_OCR_rec.yaml -o Global.pretrained_model=./rec_latex_ocr_train/best_accuracy.pdparams Global.save_inference_dir=./inference/rec_latex_ocr_infer/
|
||||
|
||||
# The default output max length of the model is 512.
|
||||
```
|
||||
|
||||
For LaTeX-OCR printed mathematical expression recognition model inference, the following commands can be executed:
|
||||
|
||||
```
|
||||
python3 tools/infer/predict_rec.py --image_dir='./docs/datasets/images/pme_demo/0000295.png' --rec_algorithm="LaTeXOCR" --rec_batch_num=1 --rec_model_dir="./inference/rec_latex_ocr_infer/" --rec_char_dict_path="./ppocr/utils/dict/latex_ocr_tokenizer.json"
|
||||
```
|
||||
|
||||
### 4.2 C++ Inference
|
||||
|
||||
Not supported
|
||||
|
||||
### 4.3 Serving
|
||||
|
||||
Not supported
|
||||
|
||||
### 4.4 More
|
||||
|
||||
Not supported
|
||||
|
||||
## 5. FAQ
|
||||
@@ -0,0 +1,147 @@
|
||||
# 印刷数学公式识别算法-LaTeX-OCR
|
||||
|
||||
## 1. 算法简介
|
||||
|
||||
原始项目:
|
||||
> [https://github.com/lukas-blecher/LaTeX-OCR](https://github.com/lukas-blecher/LaTeX-OCR)
|
||||
|
||||
|
||||
`LaTeX-OCR`使用[`LaTeX-OCR印刷公式数据集`](https://drive.google.com/drive/folders/13CA4vAmOmD_I_dSbvLp-Lf0s6KiaNfuO)进行训练,在对应测试集上的精度如下:
|
||||
|
||||
| 模型 | 骨干网络 |配置文件 | BLEU score | normed edit distance | ExpRate |下载链接|
|
||||
|-----------|------------| ----- |:-----------:|:---------------------:|:---------:| ----- |
|
||||
| LaTeX-OCR | Hybrid ViT |[LaTeX_OCR_rec.yaml](https://github.com/PaddlePaddle/PaddleOCR/blob/{{PADDLEOCR_GITHUB_REF}}/configs/rec/LaTeX_OCR_rec.yaml)| 0.8821 | 0.0823 | 40.01% |[训练模型](https://paddleocr.bj.bcebos.com/contribution/rec_latex_ocr_train.tar)|
|
||||
|
||||
## 2. 环境配置
|
||||
请先参考[《运行环境准备》](../../ppocr/environment.md)配置PaddleOCR运行环境,参考[《项目克隆》](../../ppocr/blog/clone.md)克隆项目代码。
|
||||
|
||||
此外,需要安装额外的依赖:
|
||||
```shell
|
||||
pip install -r docs/algorithm/formula_recognition/requirements.txt
|
||||
```
|
||||
|
||||
## 3. 模型训练、评估、预测
|
||||
|
||||
### 3.1 pickle 标签文件生成
|
||||
从[谷歌云盘](https://drive.google.com/drive/folders/13CA4vAmOmD_I_dSbvLp-Lf0s6KiaNfuO)中下载 formulae.zip 和 math.txt,之后,使用如下命令,生成 pickle 标签文件。
|
||||
|
||||
```shell
|
||||
# 创建 LaTeX-OCR 数据集目录
|
||||
mkdir -p train_data/LaTeXOCR
|
||||
# 解压formulae.zip ,并拷贝math.txt
|
||||
unzip -d train_data/LaTeXOCR path/formulae.zip
|
||||
cp path/math.txt train_data/LaTeXOCR
|
||||
# 将原始的 .txt 文件转换为 .pkl 文件,从而对不同尺度的图像进行分组
|
||||
# 训练集转换
|
||||
python ppocr/utils/formula_utils/math_txt2pkl.py --image_dir=train_data/LaTeXOCR/train --mathtxt_path=train_data/LaTeXOCR/math.txt --output_dir=train_data/LaTeXOCR/
|
||||
# 验证集转换
|
||||
python ppocr/utils/formula_utils/math_txt2pkl.py --image_dir=train_data/LaTeXOCR/val --mathtxt_path=train_data/LaTeXOCR/math.txt --output_dir=train_data/LaTeXOCR/
|
||||
# 测试集转换
|
||||
python ppocr/utils/formula_utils/math_txt2pkl.py --image_dir=train_data/LaTeXOCR/test --mathtxt_path=train_data/LaTeXOCR/math.txt --output_dir=train_data/LaTeXOCR/
|
||||
```
|
||||
|
||||
### 3.2 模型训练
|
||||
|
||||
请参考[文本识别训练教程](../../ppocr/model_train/recognition.md)。PaddleOCR对代码进行了模块化,训练`LaTeX-OCR`识别模型时需要**更换配置文件**为`LaTeX-OCR`的[配置文件](https://github.com/PaddlePaddle/PaddleOCR/blob/{{PADDLEOCR_GITHUB_REF}}/configs/rec/LaTeX_OCR_rec.yaml)。
|
||||
|
||||
#### 启动训练
|
||||
|
||||
|
||||
具体地,在完成数据准备后,便可以启动训练,训练命令如下:
|
||||
```shell
|
||||
#单卡训练 (默认训练方式)
|
||||
python3 tools/train.py -c configs/rec/LaTeX_OCR_rec.yaml
|
||||
#多卡训练,通过--gpus参数指定卡号
|
||||
python3 -m paddle.distributed.launch --gpus '0,1,2,3' tools/train.py -c configs/rec/LaTeX_OCR_rec.yaml
|
||||
```
|
||||
|
||||
**注意:**
|
||||
|
||||
- 默认每训练22个epoch(60000次iteration)进行1次评估,若您更改训练的batch_size,或更换数据集,请在训练时作出如下修改
|
||||
```
|
||||
python3 tools/train.py -c configs/rec/LaTeX_OCR_rec.yaml -o Global.eval_batch_step=[0,{length_of_dataset//batch_size*22}]
|
||||
```
|
||||
|
||||
### 3.3 评估
|
||||
|
||||
可下载已训练完成的[模型文件](https://paddleocr.bj.bcebos.com/contribution/rec_latex_ocr_train.tar),使用如下命令进行评估:
|
||||
|
||||
```shell
|
||||
# 注意将pretrained_model的路径设置为本地路径。若使用自行训练保存的模型,请注意修改路径和文件名为{path/to/weights}/{model_name}。
|
||||
# 验证集评估
|
||||
python3 tools/eval.py -c configs/rec/LaTeX_OCR_rec.yaml -o Global.pretrained_model=./rec_latex_ocr_train/best_accuracy.pdparams
|
||||
# 测试集评估
|
||||
python3 tools/eval.py -c configs/rec/LaTeX_OCR_rec.yaml -o Global.pretrained_model=./rec_latex_ocr_train/best_accuracy.pdparams Eval.dataset.data_dir=./train_data/LaTeXOCR/test Eval.dataset.data=./train_data/LaTeXOCR/latexocr_test.pkl
|
||||
```
|
||||
|
||||
### 3.4 预测
|
||||
|
||||
使用如下命令进行单张图片预测:
|
||||
```shell
|
||||
# 注意将pretrained_model的路径设置为本地路径。
|
||||
python3 tools/infer_rec.py -c configs/rec/LaTeX_OCR_rec.yaml -o Global.infer_img='./docs/datasets/images/pme_demo/0000013.png' Global.pretrained_model=./rec_latex_ocr_train/best_accuracy.pdparams
|
||||
# 预测文件夹下所有图像时,可修改infer_img为文件夹,如 Global.infer_img='./doc/datasets/pme_demo/'。
|
||||
```
|
||||
|
||||
## 4. 推理部署
|
||||
|
||||
### 4.1 Python推理
|
||||
首先将训练得到best模型,转换成inference model。这里以训练完成的模型为例([模型下载地址](https://paddleocr.bj.bcebos.com/contribution/rec_latex_ocr_train.tar)),可以使用如下命令进行转换:
|
||||
|
||||
```shell
|
||||
# 注意将pretrained_model的路径设置为本地路径。
|
||||
python3 tools/export_model.py -c configs/rec/LaTeX_OCR_rec.yaml -o Global.pretrained_model=./rec_latex_ocr_train/best_accuracy.pdparams Global.save_inference_dir=./inference/rec_latex_ocr_infer/
|
||||
|
||||
# 目前的静态图模型支持的最大输出长度为512
|
||||
```
|
||||
**注意:**
|
||||
- 如果您是在自己的数据集上训练的模型,并且调整了字典文件,请检查配置文件中的`rec_char_dict_path`是否为所需要的字典文件。
|
||||
- [转换后模型下载地址](https://paddleocr.bj.bcebos.com/contribution/rec_latex_ocr_infer.tar)
|
||||
|
||||
转换成功后,在目录下有三个文件:
|
||||
```
|
||||
/inference/rec_latex_ocr_infer/
|
||||
├── inference.pdiparams # 识别inference模型的参数文件
|
||||
├── inference.pdiparams.info # 识别inference模型的参数信息,可忽略
|
||||
└── inference.pdmodel # 识别inference模型的program文件
|
||||
```
|
||||
|
||||
执行如下命令进行模型推理:
|
||||
|
||||
```shell
|
||||
python3 tools/infer/predict_rec.py --image_dir='./docs/datasets/images/pme_demo/0000295.png' --rec_algorithm="LaTeXOCR" --rec_batch_num=1 --rec_model_dir="./inference/rec_latex_ocr_infer/" --rec_char_dict_path="./ppocr/utils/dict/latex_ocr_tokenizer.json"
|
||||
|
||||
# 预测文件夹下所有图像时,可修改image_dir为文件夹,如 --image_dir='./doc/datasets/pme_demo/'。
|
||||
```
|
||||
|
||||
|
||||

|
||||
|
||||
执行命令后,上面图像的预测结果(识别的公式)会打印到屏幕上,示例如下:
|
||||
```shell
|
||||
Predicts of ./doc/datasets/pme_demo/0000295.png:\zeta_{0}(\nu)=-{\frac{\nu\varrho^{-2\nu}}{\pi}}\int_{\mu}^{\infty}d\omega\int_{C_{+}}d z{\frac{2z^{2}}{(z^{2}+\omega^{2})^{\nu+1}}}{\tilde{\Psi}}(\omega;z)e^{i\epsilon z}~~~,
|
||||
```
|
||||
|
||||
|
||||
**注意**:
|
||||
|
||||
- 需要注意预测图像为**白底黑字**,即手写公式部分为黑色,背景为白色的图片。
|
||||
- 在推理时需要设置参数`rec_char_dict_path`指定字典,如果您修改了字典,请修改该参数为您的字典文件。
|
||||
- 如果您修改了预处理方法,需修改`tools/infer/predict_rec.py`中 LaTeX-OCR 的预处理为您的预处理方法。
|
||||
|
||||
|
||||
### 4.2 C++推理部署
|
||||
|
||||
由于C++预处理后处理还未支持 LaTeX-OCR,所以暂未支持
|
||||
|
||||
### 4.3 Serving服务化部署
|
||||
|
||||
暂不支持
|
||||
|
||||
### 4.4 更多推理部署
|
||||
|
||||
暂不支持
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
1. LaTeX-OCR 数据集来自于[LaTeXOCR源repo](https://github.com/lukas-blecher/LaTeX-OCR) 。
|
||||
@@ -0,0 +1,95 @@
|
||||
# 印刷数学公式识别算法-PP-FormulaNet
|
||||
|
||||
## 1. 算法简介
|
||||
|
||||
`PP-FormulaNet` 是由百度飞桨视觉团队开发的一款先进的公式识别模型,支持识别 5 万个常见 LaTeX 源码词汇。其中,PP-FormulaNet-S 版本采用 PP-HGNetV2-B4 作为骨干网络,通过并行掩码和模型蒸馏等技术大幅提升推理速度并保持高识别精度,适用于简单印刷公式和跨行简单印刷公式等场景;而 PP-FormulaNet-L 版本基于 Vary_VIT_B 并经过大规模公式数据集的深入训练,在复杂公式识别方面表现显著提升,适用于简单印刷、复杂印刷和手写公式。
|
||||
|
||||
上述模型在对应测试集上的精度如下:
|
||||
|
||||
| 模型 | 骨干网络 | 配置文件 | En-BLEU↑ |GPU推理耗时(ms)| 下载链接 |
|
||||
|-----------|--------|----------------------------------------|:-----------------:|:--------------:|:--------------:|
|
||||
| UniMERNet | Donut Swin | [UniMERNet.yaml](../../../../configs/rec/UniMERNet.yaml) | 85.91 | 2266.96 | [训练模型](https://paddleocr.bj.bcebos.com/contribution/rec_unimernet_train.tar)|
|
||||
| PP-FormulaNet-S | PPHGNetV2_B4 | [PP-FormulaNet-S.yaml](../../../../configs/rec/PP-FormuaNet/PP-FormulaNet-S.yaml) | 87.00 | 202.25 |[训练模型](https://paddleocr.bj.bcebos.com/contribution/rec_ppformulanet_s_train.tar)|
|
||||
| PP-FormulaNet-L | Vary_VIT_B | [PP-FormulaNet-L.yaml](../../../../configs/rec/PP-FormuaNet/PP-FormulaNet-L.yaml) | 90.36 | 1976.52 |[训练模型](https://paddleocr.bj.bcebos.com/contribution/rec_ppformulanet_l_train.tar )|
|
||||
| LaTeX-OCR | Hybrid ViT |[LaTeX_OCR_rec.yaml](../../../../configs/rec/LaTeX_OCR_rec.yaml)| 74.55 | 1244.61 |[训练模型](https://paddleocr.bj.bcebos.com/contribution/rec_latex_ocr_train.tar)|
|
||||
|
||||
这里,英文公式评估集包含UniMERNet的简单和复杂公式,以及PaddleX内部自建的简单、中等和复杂公式。
|
||||
|
||||
## 2. 环境配置
|
||||
请先参考[《运行环境准备》](../../ppocr/environment.md)配置PaddleOCR运行环境,参考[《项目克隆》](../../ppocr/blog/clone.md)克隆项目代码。
|
||||
|
||||
此外,需要安装额外的依赖:
|
||||
```shell
|
||||
sudo apt-get update
|
||||
sudo apt-get install libmagickwand-dev
|
||||
pip install -r docs/algorithm/formula_recognition/requirements.txt
|
||||
```
|
||||
|
||||
## 3. 模型训练、评估、预测
|
||||
|
||||
### 3.1 准备数据集
|
||||
|
||||
```shell
|
||||
# 下载 PaddleX 官方示例数据集
|
||||
wget https://paddle-model-ecology.bj.bcebos.com/paddlex/data/ocr_rec_latexocr_dataset_example.tar
|
||||
tar -xf ocr_rec_latexocr_dataset_example.tar
|
||||
```
|
||||
|
||||
|
||||
### 3.2 下载预训练模型
|
||||
|
||||
```shell
|
||||
# 下载 PP-FormulaNet-S 预训练模型
|
||||
wget https://paddleocr.bj.bcebos.com/contribution/rec_ppformulanet_s_train.tar
|
||||
tar -xf rec_ppformulanet_s_train.tar
|
||||
```
|
||||
|
||||
|
||||
### 3.3 模型训练
|
||||
|
||||
请参考[文本识别训练教程](../../ppocr/model_train/recognition.md)。PaddleOCR对代码进行了模块化,训练 `PP-FormulaNet-S` 识别模型时需要**更换配置文件**为 `PP-FormulaNet-S` 的[配置文件](https://github.com/PaddlePaddle/PaddleOCR/blob/{{PADDLEOCR_GITHUB_REF}}/configs/rec/PP-FormuaNet/PP-FormulaNet-S.yaml)。
|
||||
|
||||
#### 启动训练
|
||||
|
||||
具体地,在完成数据准备后,便可以启动训练,训练命令如下:
|
||||
```shell
|
||||
#单卡训练 (默认训练方式)
|
||||
python3 tools/train.py -c configs/rec/PP-FormuaNet/PP-FormulaNet-S.yaml \
|
||||
-o Global.pretrained_model=./rec_ppformulanet_s_train/best_accuracy.pdparams
|
||||
#多卡训练,通过--gpus参数指定卡号
|
||||
python3 -m paddle.distributed.launch --gpus '0,1,2,3' --ips=127.0.0.1 tools/train.py -c configs/rec/PP-FormuaNet/PP-FormulaNet-S.yaml \
|
||||
-o Global.pretrained_model=./rec_ppformulanet_s_train/best_accuracy.pdparams
|
||||
```
|
||||
|
||||
**注意:**
|
||||
|
||||
- 默认每训练 1个epoch(179 次iteration)进行1次评估,若您更改训练的batch_size,或更换数据集,请在训练时作出如下修改
|
||||
```
|
||||
python3 -m paddle.distributed.launch --gpus '0,1,2,3' --ips=127.0.0.1 tools/train.py -c configs/rec/PP-FormuaNet/PP-FormulaNet-S.yaml \
|
||||
-o Global.eval_batch_step=[0,{length_of_dataset//batch_size//4}] \
|
||||
Global.pretrained_model=./rec_ppformulanet_s_train/best_accuracy.pdparams
|
||||
```
|
||||
|
||||
### 3.4 评估
|
||||
|
||||
可下载已训练完成的[模型文件](https://paddleocr.bj.bcebos.com/contribution/rec_ppformulanet_s_train.tar ),使用如下命令进行评估:
|
||||
|
||||
```shell
|
||||
# 注意将pretrained_model的路径设置为本地路径。若使用自行训练保存的模型,请注意修改路径和文件名为{path/to/weights}/{model_name}。
|
||||
# demo 测试集评估
|
||||
python3 tools/eval.py -c configs/rec/PP-FormuaNet/PP-FormulaNet-S.yaml -o \
|
||||
Global.pretrained_model=./rec_ppformulanet_s_train/best_accuracy.pdparams
|
||||
```
|
||||
|
||||
### 3.5 预测
|
||||
|
||||
使用如下命令进行单张图片预测:
|
||||
```shell
|
||||
# 注意将pretrained_model的路径设置为本地路径。
|
||||
python3 tools/infer_rec.py -c configs/rec/PP-FormuaNet/PP-FormulaNet-S.yaml \
|
||||
-o Global.infer_img='./docs/datasets/images/pme_demo/0000295.png'\
|
||||
Global.pretrained_model=./rec_ppformulanet_s_train/best_accuracy.pdparams
|
||||
# 预测文件夹下所有图像时,可修改infer_img为文件夹,如 Global.infer_img='./doc/datasets/pme_demo/'。
|
||||
```
|
||||
|
||||
## 4. FAQ
|
||||
@@ -0,0 +1,82 @@
|
||||
# PP-FormulaNet
|
||||
|
||||
## 1. Introduction
|
||||
|
||||
|
||||
`PP-FormulaNet` is an advanced formula recognition model developed by Baidu’s PaddlePaddle Vision Team, supporting the recognition of 50,000 common LaTeX source terms. The PP-FormulaNet-S version uses PP-HGNetV2-B4 as its backbone network, leveraging techniques like parallel masking and model distillation to significantly enhance inference speed while maintaining high recognition accuracy, making it suitable for scenarios involving simple printed formulas and cross-line simple printed formulas. On the other hand, the PP-FormulaNet-L version is based on Vary_VIT_B and has undergone extensive training on a large-scale formula dataset, showing significant improvement in recognizing complex formulas, and is applicable to simple printed, complex printed, and handwritten formulas.
|
||||
|
||||
The accuracy of the above models on the corresponding test sets is as follows:
|
||||
|
||||
| Model | Backbone | config | En-BLEU↑ | GPU Inference Time (ms)| Download link |
|
||||
|-----------|--------|----------------------------------------|:-----------------:|:--------------:|:--------------:|
|
||||
| UniMERNet | Donut Swin | [UniMERNet.yaml](../../../../configs/rec/UniMERNet.yaml) | 85.91 | 2266.96 | [trained model](https://paddleocr.bj.bcebos.com/contribution/rec_unimernet_train.tar)|
|
||||
| PP-FormulaNet-S | PPHGNetV2_B4 | [PP-FormulaNet-S.yaml](../../../../configs/rec/PP-FormuaNet/PP-FormulaNet-S.yaml) | 87.00 | 202.25 |[trained model](https://paddleocr.bj.bcebos.com/contribution/rec_ppformulanet_s_train.tar)|
|
||||
| PP-FormulaNet-L | Vary_VIT_B | [PP-FormulaNet-L.yaml](../../../../configs/rec/PP-FormuaNet/PP-FormulaNet-L.yaml) | 90.36 | 1976.52 |[trained model](https://paddleocr.bj.bcebos.com/contribution/rec_ppformulanet_l_train.tar )|
|
||||
| LaTeX-OCR | Hybrid ViT |[LaTeX_OCR_rec.yaml](../../../../configs/rec/LaTeX_OCR_rec.yaml)| 74.55 | 1244.61 |[trained model](https://paddleocr.bj.bcebos.com/contribution/rec_latex_ocr_train.tar)|
|
||||
|
||||
|
||||
The English formula evaluation set here contains both simple and complex formulas from UniMERNet, as well as simple, medium, and complex formulas independently created by PaddleX.
|
||||
|
||||
|
||||
## 2. Environment
|
||||
Please refer to ["Environment Preparation"](../../ppocr/environment.en.md) to configure the PaddleOCR environment, and refer to ["Project Clone"](../../ppocr/blog/clone.en.md) to clone the project code.
|
||||
|
||||
Furthermore, additional dependencies need to be installed:
|
||||
```shell
|
||||
sudo apt-get update
|
||||
sudo apt-get install libmagickwand-dev
|
||||
pip install -r docs/algorithm/formula_recognition/requirements.txt
|
||||
```
|
||||
|
||||
## 3. Model Training / Evaluation / Prediction
|
||||
|
||||
Please refer to [Text Recognition Tutorial](../../ppocr/model_train/recognition.en.md). PaddleOCR modularizes the code, and training different recognition models only requires **changing the configuration file**.
|
||||
|
||||
|
||||
Dataset Preparation:
|
||||
|
||||
```shell
|
||||
# download PaddleX official example dataset
|
||||
wget https://paddle-model-ecology.bj.bcebos.com/paddlex/data/ocr_rec_latexocr_dataset_example.tar
|
||||
tar -xf ocr_rec_latexocr_dataset_example.tar
|
||||
```
|
||||
|
||||
Download the Pre-trained Model:
|
||||
|
||||
```shell
|
||||
# download the PP-FormulaNet-S pretrained model
|
||||
wget https://paddleocr.bj.bcebos.com/contribution/rec_ppformulanet_s_train.tar
|
||||
tar -xf rec_ppformulanet_s_train.tar
|
||||
```
|
||||
|
||||
Training:
|
||||
|
||||
Specifically, after the data preparation is completed, the training can be started. The training command is as follows:
|
||||
|
||||
```shell
|
||||
#Single GPU training
|
||||
python3 tools/train.py -c configs/rec/PP-FormuaNet/PP-FormulaNet-S.yaml \
|
||||
-o Global.pretrained_model=./rec_ppformulanet_s_train/best_accuracy.pdparams
|
||||
#Multi GPU training, specify the gpu number through the --gpus parameter
|
||||
python3 -m paddle.distributed.launch --gpus '0,1,2,3' --ips=127.0.0.1 tools/train.py -c configs/rec/PP-FormuaNet/PP-FormulaNet-S.yaml \
|
||||
-o Global.pretrained_model=./rec_ppformulanet_s_train/best_accuracy.pdparams
|
||||
```
|
||||
|
||||
Evaluation:
|
||||
|
||||
```shell
|
||||
# GPU evaluation
|
||||
python3 tools/eval.py -c configs/rec/PP-FormuaNet/PP-FormulaNet-S.yaml -o \
|
||||
Global.pretrained_model=./rec_ppformulanet_s_train/best_accuracy.pdparams
|
||||
```
|
||||
|
||||
Prediction:
|
||||
|
||||
```shell
|
||||
# The configuration file used for prediction must match the training
|
||||
python3 tools/infer_rec.py -c configs/rec/PP-FormuaNet/PP-FormulaNet-S.yaml \
|
||||
-o Global.infer_img='./docs/datasets/images/pme_demo/0000295.png'\
|
||||
Global.pretrained_model=./rec_ppformulanet_s_train/best_accuracy.pdparams
|
||||
```
|
||||
|
||||
## 4. FAQ
|
||||
@@ -0,0 +1,154 @@
|
||||
# 通用数学公式识别算法-UniMERNet
|
||||
|
||||
## 1. 算法简介
|
||||
|
||||
原始项目:
|
||||
> [https://github.com/opendatalab/UniMERNet](https://github.com/opendatalab/UniMERNet)
|
||||
|
||||
|
||||
`UniMERNet`使用[`UniMERNet通用公式识别数据集`](https://opendatalab.com/OpenDataLab/UniMER-Dataset)进行训练,在对应测试集上的精度如下:
|
||||
|
||||
| 模型 | 骨干网络 | 配置文件 | SPE-<br/>BLEU↑ | SPE-<br/>EditDis↓ | CPE-<br/>BLEU↑ |CPE-<br/>EditDis↓ | SCE-<br/>BLEU↑ | SCE-<br/>EditDis↓ | HWE-<br/>BLEU↑ | HWE-<br/>EditDis↓ | 下载链接 |
|
||||
|-----------|------------|-------------------------------------------------------|:--------------:|:-----------------:|:----------:|:----------------:|:---------:|:-----------------:|:--------------:|:-----------------:|-------|
|
||||
| UniMERNet | Donut Swin | [UniMERNet.yaml](../../../../configs/rec/UniMERNet.yaml) | 0.9187 | 0.0584 | 0.9252 | 0.0596 | 0.6068 | 0.2297 | 0.9157| 0.0546 |[训练模型](https://paddleocr.bj.bcebos.com/contribution/rec_unimernet_train.tar)|
|
||||
|
||||
其中,SPE表示简单公式,CPE表示复杂公式,SCE表示扫描捕捉公式,HWE表示手写公式。每种类型的公式示例图如下:
|
||||

|
||||
|
||||
## 2. 环境配置
|
||||
请先参考[《运行环境准备》](../../ppocr/environment.md)配置PaddleOCR运行环境,参考[《项目克隆》](../../ppocr/blog/clone.md)克隆项目代码。
|
||||
|
||||
此外,需要安装额外的依赖:
|
||||
```shell
|
||||
sudo apt-get update
|
||||
sudo apt-get install libmagickwand-dev
|
||||
pip install -r docs/algorithm/formula_recognition/requirements.txt
|
||||
```
|
||||
|
||||
## 3. 模型训练、评估、预测
|
||||
|
||||
### 3.1 准备数据集
|
||||
|
||||
从 [OpenDataLab](https://opendatalab.com/OpenDataLab/UniMER-Dataset) 上下载 UniMER-1M.zip 和 UniMER-Test.zip。
|
||||
从 [好未来平台](https://ai.100tal.com/dataset) 下载 HME100K 数据集。之后, 使用如下命令创建数据集目录,并对数据集进行转换。
|
||||
|
||||
```shell
|
||||
# 创建 UniMERNet 数据集目录
|
||||
mkdir -p train_data/UniMERNet
|
||||
# 解压 UniMERNet 、 UniMER-Test.zip 和 HME100K.zip
|
||||
unzip -d train_data/UniMERNet path/UniMER-1M.zip
|
||||
unzip -d train_data/UniMERNet path/UniMER-Test.zip
|
||||
unzip -d train_data/UniMERNet/HME100K train_data/UniMERNet/HME100K/train.zip
|
||||
unzip -d train_data/UniMERNet/HME100K train_data/UniMERNet/HME100K/test.zip
|
||||
# 训练集转换
|
||||
python ppocr/utils/formula_utils/unimernet_data_convert.py \
|
||||
--image_dir=train_data/UniMERNet \
|
||||
--datatype=unimernet_train \
|
||||
--unimernet_txt_path=train_data/UniMERNet/UniMER-1M/train.txt \
|
||||
--hme100k_txt_path=train_data/UniMERNet/HME100K/train_labels.txt \
|
||||
--output_path=train_data/UniMERNet/train_unimernet_1M.txt
|
||||
# 测试集转换
|
||||
# SPE
|
||||
python ppocr/utils/formula_utils/unimernet_data_convert.py \
|
||||
--image_dir=train_data/UniMERNet/UniMER-Test/spe \
|
||||
--datatype=unimernet_test \
|
||||
--unimernet_txt_path=train_data/UniMERNet/UniMER-Test/spe.txt \
|
||||
--output_path=train_data/UniMERNet/test_unimernet_spe.txt
|
||||
# CPE
|
||||
python ppocr/utils/formula_utils/unimernet_data_convert.py \
|
||||
--image_dir=train_data/UniMERNet/UniMER-Test/cpe \
|
||||
--datatype=unimernet_test \
|
||||
--unimernet_txt_path=train_data/UniMERNet/UniMER-Test/cpe.txt \
|
||||
--output_path=train_data/UniMERNet/test_unimernet_cpe.txt
|
||||
# SCE
|
||||
python ppocr/utils/formula_utils/unimernet_data_convert.py \
|
||||
--image_dir=train_data/UniMERNet/UniMER-Test/sce \
|
||||
--datatype=unimernet_test \
|
||||
--unimernet_txt_path=train_data/UniMERNet/UniMER-Test/sce.txt \
|
||||
--output_path=train_data/UniMERNet/test_unimernet_sce.txt
|
||||
# HWE
|
||||
python ppocr/utils/formula_utils/unimernet_data_convert.py \
|
||||
--image_dir=train_data/UniMERNet/UniMER-Test/hwe \
|
||||
--datatype=unimernet_test \
|
||||
--unimernet_txt_path=train_data/UniMERNet/UniMER-Test/hwe.txt \
|
||||
--output_path=train_data/UniMERNet/test_unimernet_hwe.txt
|
||||
```
|
||||
|
||||
|
||||
### 3.2 下载预训练模型
|
||||
|
||||
```shell
|
||||
# 下载 Texify 预训练模型
|
||||
wget -P ./pretrain_models/ https://paddleocr.bj.bcebos.com/pretrained/texify.pdparams
|
||||
```
|
||||
|
||||
|
||||
### 3.3 模型训练
|
||||
|
||||
请参考[文本识别训练教程](../../ppocr/model_train/recognition.md)。PaddleOCR对代码进行了模块化,训练`UniMERNet`识别模型时需要**更换配置文件**为`UniMERNet`的[配置文件](https://github.com/PaddlePaddle/PaddleOCR/blob/{{PADDLEOCR_GITHUB_REF}}/configs/rec/UniMERNet.yaml)。
|
||||
|
||||
#### 启动训练
|
||||
|
||||
|
||||
具体地,在完成数据准备后,便可以启动训练,训练命令如下:
|
||||
```shell
|
||||
#单卡训练 (默认训练方式)
|
||||
python3 tools/train.py -c configs/rec/UniMERNet.yaml \
|
||||
-o Global.pretrained_model=./pretrain_models/texify.pdparams
|
||||
#多卡训练,通过--gpus参数指定卡号
|
||||
python3 -m paddle.distributed.launch --gpus '0,1,2,3' --ips=127.0.0.1 tools/train.py -c configs/rec/UniMERNet.yaml \
|
||||
-o Global.pretrained_model=./pretrain_models/texify.pdparams
|
||||
```
|
||||
|
||||
**注意:**
|
||||
|
||||
- 默认每训练 1个epoch(37880 次iteration)进行1次评估,若您更改训练的batch_size,或更换数据集,请在训练时作出如下修改
|
||||
```
|
||||
python3 -m paddle.distributed.launch --gpus '0,1,2,3' --ips=127.0.0.1 tools/train.py -c configs/rec/UniMERNet.yaml \
|
||||
-o Global.eval_batch_step=[0,{length_of_dataset//batch_size//4}] \
|
||||
Global.pretrained_model=./pretrain_models/texify.pdparams
|
||||
```
|
||||
|
||||
### 3.4 评估
|
||||
|
||||
可下载已训练完成的[模型文件](https://paddleocr.bj.bcebos.com/contribution/rec_unimernet_train.tar),使用如下命令进行评估:
|
||||
|
||||
```shell
|
||||
# 注意将pretrained_model的路径设置为本地路径。若使用自行训练保存的模型,请注意修改路径和文件名为{path/to/weights}/{model_name}。
|
||||
# SPE 测试集评估
|
||||
python3 tools/eval.py -c configs/rec/UniMERNet.yaml -o \
|
||||
Eval.dataset.data_dir=./train_data/UniMERNet/UniMER-Test/spe \
|
||||
Eval.dataset.label_file_list=["./train_data/UniMERNet/test_unimernet_spe.txt"] \
|
||||
Global.pretrained_model=./rec_unimernet_train/best_accuracy.pdparams
|
||||
# CPE 测试集评估
|
||||
python3 tools/eval.py -c configs/rec/UniMERNet.yaml -o \
|
||||
Eval.dataset.data_dir=./train_data/UniMERNet/UniMER-Test/cpe \
|
||||
Eval.dataset.label_file_list=["./train_data/UniMERNet/test_unimernet_cpe.txt"] \
|
||||
Global.pretrained_model=./rec_unimernet_train/best_accuracy.pdparams
|
||||
# SCE 测试集评估
|
||||
python3 tools/eval.py -c configs/rec/UniMERNet.yaml -o \
|
||||
Eval.dataset.data_dir=./train_data/UniMERNet/UniMER-Test/sce \
|
||||
Eval.dataset.label_file_list=["./train_data/UniMERNet/test_unimernet_sce.txt"] \
|
||||
Global.pretrained_model=./rec_unimernet_train/best_accuracy.pdparams
|
||||
# HWE 测试集评估
|
||||
python3 tools/eval.py -c configs/rec/UniMERNet.yaml -o \
|
||||
Eval.dataset.data_dir=./train_data/UniMERNet/UniMER-Test/hwe \
|
||||
Eval.dataset.label_file_list=["./train_data/UniMERNet/test_unimernet_hwe.txt"] \
|
||||
Global.pretrained_model=./rec_unimernet_train/best_accuracy.pdparams
|
||||
|
||||
```
|
||||
|
||||
### 3.5 预测
|
||||
|
||||
使用如下命令进行单张图片预测:
|
||||
```shell
|
||||
# 注意将pretrained_model的路径设置为本地路径。
|
||||
python3 tools/infer_rec.py -c configs/rec/UniMERNet.yaml \
|
||||
-o Global.infer_img='./docs/datasets/images/pme_demo/0000099.png'\
|
||||
Global.pretrained_model=./rec_unimernet_train/best_accuracy.pdparams
|
||||
# 预测文件夹下所有图像时,可修改infer_img为文件夹,如 Global.infer_img='./doc/datasets/pme_demo/'。
|
||||
```
|
||||
|
||||
## 4. FAQ
|
||||
|
||||
1. UniMERNet 数据集来自于[UniMERNet源repo](https://github.com/opendatalab/UniMERNet) 。
|
||||
@@ -0,0 +1,136 @@
|
||||
# UniMERNet
|
||||
|
||||
## 1. Introduction
|
||||
|
||||
Original Project:
|
||||
> [https://github.com/opendatalab/UniMERNet](https://github.com/opendatalab/UniMERNet)
|
||||
|
||||
|
||||
Using UniMERNet general mathematical expression recognition datasets for training, and evaluating on its test sets, the algorithm reproduction effect is as follows:
|
||||
|
||||
| Model | Backbone | config | SPE-<br/>BLEU↑ | SPE-<br/>EditDis↓ | CPE-<br/>BLEU↑ |CPE-<br/>EditDis↓ | SCE-<br/>BLEU↑ | SCE-<br/>EditDis↓ | HWE-<br/>BLEU↑ | HWE-<br/>EditDis↓ | Download link |
|
||||
|-----------|--------|---------------------------------------------------|:--------------:|:-----------------:|:----------:|:----------------:|:---------:|:-----------------:|:--------------:|:-----------------:|---|
|
||||
| UniMERNet | Donut Swin | [UniMERNet.yaml](../../../../configs/rec/UniMERNet.yaml) | 0.9187 | 0.0584 | 0.9252 | 0.0596 | 0.6068 | 0.2297 | 0.9157| 0.0546 |[trained model](https://paddleocr.bj.bcebos.com/contribution/rec_unimernet_train.tar)|
|
||||
|
||||
SPE represents simple formulas, CPE represents complex formulas, SCE represents scanned captured formulas, and HWE represents handwritten formulas. Example images of each type of formula are shown below:
|
||||
|
||||

|
||||
|
||||
## 2. Environment
|
||||
Please refer to ["Environment Preparation"](../../ppocr/environment.en.md) to configure the PaddleOCR environment, and refer to ["Project Clone"](../../ppocr/blog/clone.en.md) to clone the project code.
|
||||
|
||||
Furthermore, additional dependencies need to be installed:
|
||||
```shell
|
||||
sudo apt-get update
|
||||
sudo apt-get install libmagickwand-dev
|
||||
pip install -r docs/algorithm/formula_recognition/requirements.txt
|
||||
```
|
||||
|
||||
## 3. Model Training / Evaluation / Prediction
|
||||
|
||||
Please refer to [Text Recognition Tutorial](../../ppocr/model_train/recognition.en.md). PaddleOCR modularizes the code, and training different recognition models only requires **changing the configuration file**.
|
||||
|
||||
|
||||
Dataset Preparation:
|
||||
|
||||
Download UniMER-1M.zip and UniMER-Test.zip from [OpenDataLab](https://opendatalab.com/OpenDataLab/UniMER-Dataset). Download the HME100K dataset from the [TAL AI Platform](https://ai.100tal.com/dataset). After that, use the following command to create a dataset directory and convert the dataset.
|
||||
|
||||
```shell
|
||||
# create the UniMERNet dataset directory
|
||||
mkdir -p train_data/UniMERNet
|
||||
# unzip UniMERNet 、 UniMER-Test.zip and HME100K.zip
|
||||
unzip -d train_data/UniMERNet path/UniMER-1M.zip
|
||||
unzip -d train_data/UniMERNet path/UniMER-Test.zip
|
||||
unzip -d train_data/UniMERNet/HME100K train_data/UniMERNet/HME100K/train.zip
|
||||
unzip -d train_data/UniMERNet/HME100K train_data/UniMERNet/HME100K/test.zip
|
||||
# convert the training set
|
||||
python ppocr/utils/formula_utils/unimernet_data_convert.py \
|
||||
--image_dir=train_data/UniMERNet \
|
||||
--datatype=unimernet_train \
|
||||
--unimernet_txt_path=train_data/UniMERNet/UniMER-1M/train.txt \
|
||||
--hme100k_txt_path=train_data/UniMERNet/HME100K/train_labels.txt \
|
||||
--output_path=train_data/UniMERNet/train_unimernet_1M.txt
|
||||
# convert the test set
|
||||
# SPE
|
||||
python ppocr/utils/formula_utils/unimernet_data_convert.py \
|
||||
--image_dir=train_data/UniMERNet/UniMER-Test/spe \
|
||||
--datatype=unimernet_test \
|
||||
--unimernet_txt_path=train_data/UniMERNet/UniMER-Test/spe.txt \
|
||||
--output_path=train_data/UniMERNet/test_unimernet_spe.txt
|
||||
# CPE
|
||||
python ppocr/utils/formula_utils/unimernet_data_convert.py \
|
||||
--image_dir=train_data/UniMERNet/UniMER-Test/cpe \
|
||||
--datatype=unimernet_test \
|
||||
--unimernet_txt_path=train_data/UniMERNet/UniMER-Test/cpe.txt \
|
||||
--output_path=train_data/UniMERNet/test_unimernet_cpe.txt
|
||||
# SCE
|
||||
python ppocr/utils/formula_utils/unimernet_data_convert.py \
|
||||
--image_dir=train_data/UniMERNet/UniMER-Test/sce \
|
||||
--datatype=unimernet_test \
|
||||
--unimernet_txt_path=train_data/UniMERNet/UniMER-Test/sce.txt \
|
||||
--output_path=train_data/UniMERNet/test_unimernet_sce.txt
|
||||
# HWE
|
||||
python ppocr/utils/formula_utils/unimernet_data_convert.py \
|
||||
--image_dir=train_data/UniMERNet/UniMER-Test/hwe \
|
||||
--datatype=unimernet_test \
|
||||
--unimernet_txt_path=train_data/UniMERNet/UniMER-Test/hwe.txt \
|
||||
--output_path=train_data/UniMERNet/test_unimernet_hwe.txt
|
||||
```
|
||||
|
||||
Download the Pre-trained Model:
|
||||
|
||||
```shell
|
||||
# download the Texify pre-trained model
|
||||
wget -P ./pretrain_models/ https://paddleocr.bj.bcebos.com/pretrained/texify.pdparams
|
||||
```
|
||||
|
||||
Training:
|
||||
|
||||
Specifically, after the data preparation is completed, the training can be started. The training command is as follows:
|
||||
|
||||
```shell
|
||||
#Single GPU training
|
||||
python3 tools/train.py -c configs/rec/UniMERNet.yaml \
|
||||
-o Global.pretrained_model=./pretrain_models/texify.pdparams
|
||||
#Multi GPU training, specify the gpu number through the --gpus parameter
|
||||
python3 -m paddle.distributed.launch --gpus '0,1,2,3' --ips=127.0.0.1 tools/train.py -c configs/rec/UniMERNet.yaml \
|
||||
-o Global.pretrained_model=./pretrain_models/texify.pdparams
|
||||
```
|
||||
|
||||
Evaluation:
|
||||
|
||||
```shell
|
||||
# GPU evaluation
|
||||
# SPE test set evaluation
|
||||
python3 tools/eval.py -c configs/rec/UniMERNet.yaml -o \
|
||||
Eval.dataset.data_dir=./train_data/UniMERNet/UniMER-Test/spe \
|
||||
Eval.dataset.label_file_list=["./train_data/UniMERNet/test_unimernet_spe.txt"] \
|
||||
Global.pretrained_model=./rec_unimernet_train/best_accuracy.pdparams
|
||||
# CPE test set evaluation
|
||||
python3 tools/eval.py -c configs/rec/UniMERNet.yaml -o \
|
||||
Eval.dataset.data_dir=./train_data/UniMERNet/UniMER-Test/cpe \
|
||||
Eval.dataset.label_file_list=["./train_data/UniMERNet/test_unimernet_cpe.txt"] \
|
||||
Global.pretrained_model=./rec_unimernet_train/best_accuracy.pdparams
|
||||
# SCE test set evaluation
|
||||
python3 tools/eval.py -c configs/rec/UniMERNet.yaml -o \
|
||||
Eval.dataset.data_dir=./train_data/UniMERNet/UniMER-Test/sce \
|
||||
Eval.dataset.label_file_list=["./train_data/UniMERNet/test_unimernet_sce.txt"] \
|
||||
Global.pretrained_model=./rec_unimernet_train/best_accuracy.pdparams
|
||||
# HWE test set evaluation
|
||||
python3 tools/eval.py -c configs/rec/UniMERNet.yaml -o \
|
||||
Eval.dataset.data_dir=./train_data/UniMERNet/UniMER-Test/hwe \
|
||||
Eval.dataset.label_file_list=["./train_data/UniMERNet/test_unimernet_hwe.txt"] \
|
||||
Global.pretrained_model=./rec_unimernet_train/best_accuracy.pdparams
|
||||
|
||||
```
|
||||
|
||||
Prediction:
|
||||
|
||||
```shell
|
||||
# The configuration file used for prediction must match the training
|
||||
python3 tools/infer_rec.py -c configs/rec/UniMERNet.yaml \
|
||||
-o Global.infer_img='./docs/datasets/images/pme_demo/0000099.png'\
|
||||
Global.pretrained_model=./rec_unimernet_train/best_accuracy.pdparams
|
||||
```
|
||||
|
||||
## 4. FAQ
|
||||
|
After Width: | Height: | Size: 12 KiB |
@@ -0,0 +1,4 @@
|
||||
tokenizers==0.19.1
|
||||
imagesize
|
||||
ftfy
|
||||
Wand
|
||||
@@ -0,0 +1,171 @@
|
||||
---
|
||||
comments: true
|
||||
---
|
||||
|
||||
# KIE Algorithm - LayoutXLM
|
||||
|
||||
## 1. Introduction
|
||||
|
||||
Paper:
|
||||
|
||||
> [LayoutXLM: Multimodal Pre-training for Multilingual Visually-rich Document Understanding](https://arxiv.org/abs/2104.08836)
|
||||
>
|
||||
> Yiheng Xu, Tengchao Lv, Lei Cui, Guoxin Wang, Yijuan Lu, Dinei Florencio, Cha Zhang, Furu Wei
|
||||
>
|
||||
> 2021
|
||||
|
||||
On XFUND_zh dataset, the algorithm reproduction Hmean is as follows.
|
||||
|
||||
|Model|Backbone|Task |Cnnfig|Hmean|Download link|
|
||||
| --- | --- |--|--- | --- | --- |
|
||||
|LayoutXLM|LayoutXLM-base|SER |[ser_layoutxlm_xfund_zh.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/kie/layoutlm_series/ser_layoutxlm_xfund_zh.yml)|90.38%|[trained model](https://paddleocr.bj.bcebos.com/pplayout/ser_LayoutXLM_xfun_zh.tar)/[inference model](https://paddleocr.bj.bcebos.com/pplayout/ser_LayoutXLM_xfun_zh_infer.tar)|
|
||||
|LayoutXLM|LayoutXLM-base|RE | [re_layoutxlm_xfund_zh.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/kie/layoutlm_series/re_layoutxlm_xfund_zh.yml)|74.83%|[trained model](https://paddleocr.bj.bcebos.com/pplayout/re_LayoutXLM_xfun_zh.tar)/[inference model](https://paddleocr.bj.bcebos.com/pplayout/re_LayoutXLM_xfun_zh_infer.tar)|
|
||||
|
||||
## 2. Environment
|
||||
|
||||
Please refer to ["Environment Preparation"](../../ppocr/environment.en.md) to configure the PaddleOCR environment, and refer to ["Project Clone"](../../ppocr/blog/clone.en.md)to clone the project code.
|
||||
|
||||
## 3. Model Training / Evaluation / Prediction
|
||||
|
||||
Please refer to [KIE tutorial](../../ppocr/model_train/kie.en.md)。PaddleOCR has modularized the code structure, so that you only need to **replace the configuration file** to train different models.
|
||||
|
||||
## 4. Inference and Deployment
|
||||
|
||||
### 4.1 Python Inference
|
||||
|
||||
#### SER
|
||||
|
||||
First, we need to export the trained model into inference model. Take LayoutXLM model trained on XFUND_zh as an example ([trained model download link](https://paddleocr.bj.bcebos.com/pplayout/ser_LayoutXLM_xfun_zh.tar)). Use the following command to export.
|
||||
|
||||
``` bash
|
||||
wget https://paddleocr.bj.bcebos.com/pplayout/ser_LayoutXLM_xfun_zh.tar
|
||||
tar -xf ser_LayoutXLM_xfun_zh.tar
|
||||
python3 tools/export_model.py -c configs/kie/layoutlm_series/ser_layoutxlm_xfund_zh.yml -o Architecture.Backbone.checkpoints=./ser_LayoutXLM_xfun_zh Global.save_inference_dir=./inference/ser_layoutxlm_infer
|
||||
```
|
||||
|
||||
Use the following command to infer using LayoutXLM SER model:
|
||||
|
||||
```bash linenums="1"
|
||||
cd ppstructure
|
||||
python3 kie/predict_kie_token_ser.py \
|
||||
--kie_algorithm=LayoutXLM \
|
||||
--ser_model_dir=../inference/ser_layoutxlm_infer \
|
||||
--image_dir=./docs/kie/input/zh_val_42.jpg \
|
||||
--ser_dict_path=../train_data/XFUND/class_list_xfun.txt \
|
||||
--vis_font_path=../doc/fonts/simfang.ttf
|
||||
```
|
||||
|
||||
The SER visualization results are saved in the `./output` directory by default. The results are as follows.
|
||||
|
||||

|
||||
|
||||
#### RE
|
||||
|
||||
First, we need to export the trained model into inference model. Take LayoutXLM model trained on XFUND_zh as an example ([trained model download link](https://paddleocr.bj.bcebos.com/pplayout/re_LayoutXLM_xfun_zh.tar)). Use the following command to export.
|
||||
|
||||
``` bash
|
||||
wget https://paddleocr.bj.bcebos.com/pplayout/re_LayoutXLM_xfun_zh.tar
|
||||
tar -xf re_LayoutXLM_xfun_zh.tar
|
||||
python3 tools/export_model.py -c configs/kie/layoutlm_series/re_layoutxlm_xfund_zh.yml -o Architecture.Backbone.checkpoints=./re_LayoutXLM_xfun_zh Global.save_inference_dir=./inference/re_layoutxlm_infer
|
||||
```
|
||||
|
||||
Use the following command to infer using LayoutXLM RE model:
|
||||
|
||||
```bash linenums="1"
|
||||
cd ppstructure
|
||||
python3 kie/predict_kie_token_ser_re.py \
|
||||
--kie_algorithm=LayoutXLM \
|
||||
--re_model_dir=../inference/re_layoutxlm_infer \
|
||||
--ser_model_dir=../inference/ser_layoutxlm_infer \
|
||||
--image_dir=./docs/kie/input/zh_val_42.jpg \
|
||||
--ser_dict_path=../train_data/XFUND/class_list_xfun.txt \
|
||||
--vis_font_path=../doc/fonts/simfang.ttf
|
||||
```
|
||||
|
||||
The RE visualization results are saved in the `./output` directory by default. The results are as follows.
|
||||
|
||||

|
||||
|
||||
### 4.2 C++ Inference
|
||||
|
||||
Not supported
|
||||
|
||||
### 4.3 Serving
|
||||
|
||||
Not supported
|
||||
|
||||
### 4.4 More
|
||||
|
||||
Not supported
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
## Citation
|
||||
|
||||
```bibtex
|
||||
@article{DBLP:journals/corr/abs-2104-08836,
|
||||
author = {Yiheng Xu and
|
||||
Tengchao Lv and
|
||||
Lei Cui and
|
||||
Guoxin Wang and
|
||||
Yijuan Lu and
|
||||
Dinei Flor{\^{e}}ncio and
|
||||
Cha Zhang and
|
||||
Furu Wei},
|
||||
title = {LayoutXLM: Multimodal Pre-training for Multilingual Visually-rich
|
||||
Document Understanding},
|
||||
journal = {CoRR},
|
||||
volume = {abs/2104.08836},
|
||||
year = {2021},
|
||||
url = {https://arxiv.org/abs/2104.08836},
|
||||
eprinttype = {arXiv},
|
||||
eprint = {2104.08836},
|
||||
timestamp = {Thu, 14 Oct 2021 09:17:23 +0200},
|
||||
biburl = {https://dblp.org/rec/journals/corr/abs-2104-08836.bib},
|
||||
bibsource = {dblp computer science bibliography, https://dblp.org}
|
||||
}
|
||||
|
||||
@article{DBLP:journals/corr/abs-1912-13318,
|
||||
author = {Yiheng Xu and
|
||||
Minghao Li and
|
||||
Lei Cui and
|
||||
Shaohan Huang and
|
||||
Furu Wei and
|
||||
Ming Zhou},
|
||||
title = {LayoutLM: Pre-training of Text and Layout for Document Image Understanding},
|
||||
journal = {CoRR},
|
||||
volume = {abs/1912.13318},
|
||||
year = {2019},
|
||||
url = {http://arxiv.org/abs/1912.13318},
|
||||
eprinttype = {arXiv},
|
||||
eprint = {1912.13318},
|
||||
timestamp = {Mon, 01 Jun 2020 16:20:46 +0200},
|
||||
biburl = {https://dblp.org/rec/journals/corr/abs-1912-13318.bib},
|
||||
bibsource = {dblp computer science bibliography, https://dblp.org}
|
||||
}
|
||||
|
||||
@article{DBLP:journals/corr/abs-2012-14740,
|
||||
author = {Yang Xu and
|
||||
Yiheng Xu and
|
||||
Tengchao Lv and
|
||||
Lei Cui and
|
||||
Furu Wei and
|
||||
Guoxin Wang and
|
||||
Yijuan Lu and
|
||||
Dinei A. F. Flor{\^{e}}ncio and
|
||||
Cha Zhang and
|
||||
Wanxiang Che and
|
||||
Min Zhang and
|
||||
Lidong Zhou},
|
||||
title = {LayoutLMv2: Multi-modal Pre-training for Visually-Rich Document Understanding},
|
||||
journal = {CoRR},
|
||||
volume = {abs/2012.14740},
|
||||
year = {2020},
|
||||
url = {https://arxiv.org/abs/2012.14740},
|
||||
eprinttype = {arXiv},
|
||||
eprint = {2012.14740},
|
||||
timestamp = {Tue, 27 Jul 2021 09:53:52 +0200},
|
||||
biburl = {https://dblp.org/rec/journals/corr/abs-2012-14740.bib},
|
||||
bibsource = {dblp computer science bibliography, https://dblp.org}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,171 @@
|
||||
---
|
||||
comments: true
|
||||
---
|
||||
|
||||
# 关键信息抽取算法-LayoutXLM
|
||||
|
||||
## 1. 算法简介
|
||||
|
||||
论文信息:
|
||||
|
||||
> [LayoutXLM: Multimodal Pre-training for Multilingual Visually-rich Document Understanding](https://arxiv.org/abs/2104.08836)
|
||||
>
|
||||
> Yiheng Xu, Tengchao Lv, Lei Cui, Guoxin Wang, Yijuan Lu, Dinei Florencio, Cha Zhang, Furu Wei
|
||||
>
|
||||
> 2021
|
||||
|
||||
在XFUND_zh数据集上,算法复现效果如下:
|
||||
|
||||
|模型|骨干网络|任务|配置文件|hmean|下载链接|
|
||||
| --- | --- |--|--- | --- | --- |
|
||||
|LayoutXLM|LayoutXLM-base|SER |[ser_layoutxlm_xfund_zh.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/kie/layoutlm_series/ser_layoutxlm_xfund_zh.yml)|90.38%|[训练模型](https://paddleocr.bj.bcebos.com/pplayout/ser_LayoutXLM_xfun_zh.tar)/[推理模型](https://paddleocr.bj.bcebos.com/pplayout/ser_LayoutXLM_xfun_zh_infer.tar)|
|
||||
|LayoutXLM|LayoutXLM-base|RE | [re_layoutxlm_xfund_zh.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/kie/layoutlm_series/re_layoutxlm_xfund_zh.yml)|74.83%|[训练模型](https://paddleocr.bj.bcebos.com/pplayout/re_LayoutXLM_xfun_zh.tar)/[推理模型](https://paddleocr.bj.bcebos.com/pplayout/re_LayoutXLM_xfun_zh_infer.tar)|
|
||||
|
||||
## 2. 环境配置
|
||||
|
||||
请先参考[《运行环境准备》](../../ppocr/environment.md)配置PaddleOCR运行环境,参考[《项目克隆》](../../ppocr/blog/clone.md)克隆项目代码。
|
||||
|
||||
## 3. 模型训练、评估、预测
|
||||
|
||||
请参考[关键信息抽取教程](../../ppocr/model_train/kie.md)。PaddleOCR对代码进行了模块化,训练不同的关键信息抽取模型只需要**更换配置文件**即可。
|
||||
|
||||
## 4. 推理部署
|
||||
|
||||
### 4.1 Python推理
|
||||
|
||||
#### SER
|
||||
|
||||
首先将训练得到的模型转换成inference model。LayoutXLM模型在XFUND_zh数据集上训练的模型为例([模型下载地址](https://paddleocr.bj.bcebos.com/pplayout/ser_LayoutXLM_xfun_zh.tar)),可以使用下面的命令进行转换。
|
||||
|
||||
``` bash
|
||||
wget https://paddleocr.bj.bcebos.com/pplayout/ser_LayoutXLM_xfun_zh.tar
|
||||
tar -xf ser_LayoutXLM_xfun_zh.tar
|
||||
python3 tools/export_model.py -c configs/kie/layoutlm_series/ser_layoutxlm_xfund_zh.yml -o Architecture.Backbone.checkpoints=./ser_LayoutXLM_xfun_zh Global.save_inference_dir=./inference/ser_layoutxlm_infer
|
||||
```
|
||||
|
||||
LayoutXLM模型基于SER任务进行推理,可以执行如下命令:
|
||||
|
||||
```bash linenums="1"
|
||||
cd ppstructure
|
||||
python3 kie/predict_kie_token_ser.py \
|
||||
--kie_algorithm=LayoutXLM \
|
||||
--ser_model_dir=../inference/ser_layoutxlm_infer \
|
||||
--image_dir=./docs/kie/input/zh_val_42.jpg \
|
||||
--ser_dict_path=../train_data/XFUND/class_list_xfun.txt \
|
||||
--vis_font_path=../doc/fonts/simfang.ttf
|
||||
```
|
||||
|
||||
SER可视化结果默认保存到`./output`文件夹里面,结果示例如下:
|
||||
|
||||

|
||||
|
||||
#### RE
|
||||
|
||||
首先将训练得到的模型转换成inference model。LayoutXLM模型在XFUND_zh数据集上训练的模型为例([模型下载地址](https://paddleocr.bj.bcebos.com/pplayout/re_LayoutXLM_xfun_zh.tar)),可以使用下面的命令进行转换。
|
||||
|
||||
``` bash
|
||||
wget https://paddleocr.bj.bcebos.com/pplayout/re_LayoutXLM_xfun_zh.tar
|
||||
tar -xf re_LayoutXLM_xfun_zh.tar
|
||||
python3 tools/export_model.py -c configs/kie/layoutlm_series/re_layoutxlm_xfund_zh.yml -o Architecture.Backbone.checkpoints=./re_LayoutXLM_xfun_zh Global.save_inference_dir=./inference/ser_layoutxlm_infer
|
||||
```
|
||||
|
||||
LayoutXLM模型基于RE任务进行推理,可以执行如下命令:
|
||||
|
||||
```bash linenums="1"
|
||||
cd ppstructure
|
||||
python3 kie/predict_kie_token_ser_re.py \
|
||||
--kie_algorithm=LayoutXLM \
|
||||
--re_model_dir=../inference/re_layoutxlm_infer \
|
||||
--ser_model_dir=../inference/ser_layoutxlm_infer \
|
||||
--image_dir=./docs/kie/input/zh_val_42.jpg \
|
||||
--ser_dict_path=../train_data/XFUND/class_list_xfun.txt \
|
||||
--vis_font_path=../doc/fonts/simfang.ttf
|
||||
```
|
||||
|
||||
RE可视化结果默认保存到`./output`文件夹里面,结果示例如下:
|
||||
|
||||

|
||||
|
||||
### 4.2 C++推理部署
|
||||
|
||||
暂不支持
|
||||
|
||||
### 4.3 Serving服务化部署
|
||||
|
||||
暂不支持
|
||||
|
||||
### 4.4 更多推理部署
|
||||
|
||||
暂不支持
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
## 引用
|
||||
|
||||
```bibtex
|
||||
@article{DBLP:journals/corr/abs-2104-08836,
|
||||
author = {Yiheng Xu and
|
||||
Tengchao Lv and
|
||||
Lei Cui and
|
||||
Guoxin Wang and
|
||||
Yijuan Lu and
|
||||
Dinei Flor{\^{e}}ncio and
|
||||
Cha Zhang and
|
||||
Furu Wei},
|
||||
title = {LayoutXLM: Multimodal Pre-training for Multilingual Visually-rich
|
||||
Document Understanding},
|
||||
journal = {CoRR},
|
||||
volume = {abs/2104.08836},
|
||||
year = {2021},
|
||||
url = {https://arxiv.org/abs/2104.08836},
|
||||
eprinttype = {arXiv},
|
||||
eprint = {2104.08836},
|
||||
timestamp = {Thu, 14 Oct 2021 09:17:23 +0200},
|
||||
biburl = {https://dblp.org/rec/journals/corr/abs-2104-08836.bib},
|
||||
bibsource = {dblp computer science bibliography, https://dblp.org}
|
||||
}
|
||||
|
||||
@article{DBLP:journals/corr/abs-1912-13318,
|
||||
author = {Yiheng Xu and
|
||||
Minghao Li and
|
||||
Lei Cui and
|
||||
Shaohan Huang and
|
||||
Furu Wei and
|
||||
Ming Zhou},
|
||||
title = {LayoutLM: Pre-training of Text and Layout for Document Image Understanding},
|
||||
journal = {CoRR},
|
||||
volume = {abs/1912.13318},
|
||||
year = {2019},
|
||||
url = {http://arxiv.org/abs/1912.13318},
|
||||
eprinttype = {arXiv},
|
||||
eprint = {1912.13318},
|
||||
timestamp = {Mon, 01 Jun 2020 16:20:46 +0200},
|
||||
biburl = {https://dblp.org/rec/journals/corr/abs-1912-13318.bib},
|
||||
bibsource = {dblp computer science bibliography, https://dblp.org}
|
||||
}
|
||||
|
||||
@article{DBLP:journals/corr/abs-2012-14740,
|
||||
author = {Yang Xu and
|
||||
Yiheng Xu and
|
||||
Tengchao Lv and
|
||||
Lei Cui and
|
||||
Furu Wei and
|
||||
Guoxin Wang and
|
||||
Yijuan Lu and
|
||||
Dinei A. F. Flor{\^{e}}ncio and
|
||||
Cha Zhang and
|
||||
Wanxiang Che and
|
||||
Min Zhang and
|
||||
Lidong Zhou},
|
||||
title = {LayoutLMv2: Multi-modal Pre-training for Visually-Rich Document Understanding},
|
||||
journal = {CoRR},
|
||||
volume = {abs/2012.14740},
|
||||
year = {2020},
|
||||
url = {https://arxiv.org/abs/2012.14740},
|
||||
eprinttype = {arXiv},
|
||||
eprint = {2012.14740},
|
||||
timestamp = {Tue, 27 Jul 2021 09:53:52 +0200},
|
||||
biburl = {https://dblp.org/rec/journals/corr/abs-2012-14740.bib},
|
||||
bibsource = {dblp computer science bibliography, https://dblp.org}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,113 @@
|
||||
---
|
||||
comments: true
|
||||
---
|
||||
|
||||
# KIE Algorithm - SDMGR
|
||||
|
||||
## 1. Introduction
|
||||
|
||||
Paper:
|
||||
|
||||
> [Spatial Dual-Modality Graph Reasoning for Key Information Extraction](https://arxiv.org/abs/2103.14470)
|
||||
>
|
||||
> Hongbin Sun and Zhanghui Kuang and Xiaoyu Yue and Chenhao Lin and Wayne Zhang
|
||||
>
|
||||
> 2021
|
||||
|
||||
On wildreceipt dataset, the algorithm reproduction Hmean is as follows.
|
||||
|
||||
|Model|Backbone |Cnnfig|Hmean|Download link|
|
||||
| --- | --- | --- | --- | --- |
|
||||
|SDMGR|VGG6|[configs/kie/sdmgr/kie_unet_sdmgr.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/kie/sdmgr/kie_unet_sdmgr.yml)|86.70%|[trained model]( https://paddleocr.bj.bcebos.com/dygraph_v2.1/kie/kie_vgg16.tar)/[inference model(coming soon)]()|
|
||||
|
||||
## 2. 环境配置
|
||||
|
||||
Please refer to ["Environment Preparation"](../../ppocr/environment.en.md) to configure the PaddleOCR environment, and refer to ["Project Clone"](../../ppocr/blog/clone.en.md)to clone the project code.
|
||||
|
||||
## 3. Model Training / Evaluation / Prediction
|
||||
|
||||
SDMGR is a key information extraction algorithm that classifies each detected textline into predefined categories, such as order ID, invoice number, amount, etc.
|
||||
|
||||
The training and test data are collected in the wildreceipt dataset, use following command to downloaded the dataset.
|
||||
|
||||
```bash linenums="1"
|
||||
wget https://paddleocr.bj.bcebos.com/ppstructure/dataset/wildreceipt.tar && tar xf wildreceipt.tar
|
||||
```
|
||||
|
||||
Create dataset soft link to `PaddleOCR/train_data` directory.
|
||||
|
||||
```bash linenums="1"
|
||||
cd PaddleOCR/ && mkdir train_data && cd train_data
|
||||
ln -s ../../wildreceipt ./
|
||||
```
|
||||
|
||||
### 3.1 Model training
|
||||
|
||||
The config file is `configs/kie/sdmgr/kie_unet_sdmgr.yml`, the default dataset path is `train_data/wildreceipt`.
|
||||
|
||||
Use the following command to train the model.
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/train.py -c configs/kie/sdmgr/kie_unet_sdmgr.yml -o Global.save_model_dir=./output/kie/
|
||||
```
|
||||
|
||||
### 3.2 Model evaluation
|
||||
|
||||
Use the following command to evaluate the model:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/eval.py -c configs/kie/sdmgr/kie_unet_sdmgr.yml -o Global.checkpoints=./output/kie/best_accuracy
|
||||
```
|
||||
|
||||
An example of output information is shown below.
|
||||
|
||||
```bash linenums="1"
|
||||
[2022/08/10 05:22:23] ppocr INFO: metric eval ***************
|
||||
[2022/08/10 05:22:23] ppocr INFO: hmean:0.8670120239257812
|
||||
[2022/08/10 05:22:23] ppocr INFO: fps:10.18816520530961
|
||||
```
|
||||
|
||||
### 3.3 Model prediction
|
||||
|
||||
Use the following command to load the model and predict. During the prediction, the text file storing the image path and OCR information needs to be loaded in advance. Use `Global.infer_img` to assign.
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer_kie.py -c configs/kie/kie_unet_sdmgr.yml -o Global.checkpoints=kie_vgg16/best_accuracy Global.infer_img=./train_data/wildreceipt/1.txt
|
||||
```
|
||||
|
||||
The visualization results and texts are saved in the `./output/sdmgr_kie/` directory by default. The results are as follows.
|
||||
|
||||

|
||||
|
||||
## 4. Inference and Deployment
|
||||
|
||||
### 4.1 Python Inference
|
||||
|
||||
Not supported
|
||||
|
||||
### 4.2 C++ Inference
|
||||
|
||||
Not supported
|
||||
|
||||
### 4.3 Serving
|
||||
|
||||
Not supported
|
||||
|
||||
### 4.4 More
|
||||
|
||||
Not supported
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
## Citation
|
||||
|
||||
```bibtex
|
||||
@misc{sun2021spatial,
|
||||
title={Spatial Dual-Modality Graph Reasoning for Key Information Extraction},
|
||||
author={Hongbin Sun and Zhanghui Kuang and Xiaoyu Yue and Chenhao Lin and Wayne Zhang},
|
||||
year={2021},
|
||||
eprint={2103.14470},
|
||||
archivePrefix={arXiv},
|
||||
primaryClass={cs.CV}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,114 @@
|
||||
---
|
||||
typora-copy-images-to: images
|
||||
comments: true
|
||||
---
|
||||
|
||||
# 关键信息抽取算法-SDMGR
|
||||
|
||||
## 1. 算法简介
|
||||
|
||||
论文信息:
|
||||
|
||||
> [Spatial Dual-Modality Graph Reasoning for Key Information Extraction](https://arxiv.org/abs/2103.14470)
|
||||
>
|
||||
> Hongbin Sun and Zhanghui Kuang and Xiaoyu Yue and Chenhao Lin and Wayne Zhang
|
||||
>
|
||||
> 2021
|
||||
|
||||
在wildreceipt发票公开数据集上,算法复现效果如下:
|
||||
|
||||
|模型|骨干网络|配置文件|hmean|下载链接|
|
||||
| --- | --- | --- | --- | --- |
|
||||
|SDMGR|VGG6|[configs/kie/sdmgr/kie_unet_sdmgr.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/kie/sdmgr/kie_unet_sdmgr.yml)|86.70%|[训练模型]( https://paddleocr.bj.bcebos.com/dygraph_v2.1/kie/kie_vgg16.tar)/[推理模型(coming soon)]()|
|
||||
|
||||
## 2. 环境配置
|
||||
|
||||
请先参考[《运行环境准备》](../../ppocr/environment.md)配置PaddleOCR运行环境,参考[《项目克隆》](../../ppocr/blog/clone.md)克隆项目代码。
|
||||
|
||||
## 3. 模型训练、评估、预测
|
||||
|
||||
SDMGR是一个关键信息提取算法,将每个检测到的文本区域分类为预定义的类别,如订单ID、发票号码,金额等。
|
||||
|
||||
训练和测试的数据采用wildreceipt数据集,通过如下指令下载数据集:
|
||||
|
||||
```bash linenums="1"
|
||||
wget https://paddleocr.bj.bcebos.com/ppstructure/dataset/wildreceipt.tar && tar xf wildreceipt.tar
|
||||
```
|
||||
|
||||
创建数据集软链到PaddleOCR/train_data目录下:
|
||||
|
||||
```bash linenums="1"
|
||||
cd PaddleOCR/ && mkdir train_data && cd train_data
|
||||
ln -s ../../wildreceipt ./
|
||||
```
|
||||
|
||||
### 3.1 模型训练
|
||||
|
||||
训练采用的配置文件是`configs/kie/sdmgr/kie_unet_sdmgr.yml`,配置文件中默认训练数据路径是`train_data/wildreceipt`,准备好数据后,可以通过如下指令执行训练:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/train.py -c configs/kie/sdmgr/kie_unet_sdmgr.yml -o Global.save_model_dir=./output/kie/
|
||||
```
|
||||
|
||||
### 3.2 模型评估
|
||||
|
||||
执行下面的命令进行模型评估
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/eval.py -c configs/kie/sdmgr/kie_unet_sdmgr.yml -o Global.checkpoints=./output/kie/best_accuracy
|
||||
```
|
||||
|
||||
输出信息示例如下所示:
|
||||
|
||||
```bash linenums="1"
|
||||
[2022/08/10 05:22:23] ppocr INFO: metric eval ***************
|
||||
[2022/08/10 05:22:23] ppocr INFO: hmean:0.8670120239257812
|
||||
[2022/08/10 05:22:23] ppocr INFO: fps:10.18816520530961
|
||||
```
|
||||
|
||||
### 3.3 模型预测
|
||||
|
||||
执行下面的命令进行模型预测,预测的时候需要预先加载存储图片路径以及OCR信息的文本文件,使用`Global.infer_img`进行指定。
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer_kie.py -c configs/kie/kie_unet_sdmgr.yml -o Global.checkpoints=kie_vgg16/best_accuracy Global.infer_img=./train_data/wildreceipt/1.txt
|
||||
```
|
||||
|
||||
执行预测后的结果保存在`./output/sdmgr_kie/predicts_kie.txt`文件中,可视化结果保存在`/output/sdmgr_kie/kie_results/`目录下。
|
||||
|
||||
可视化结果如下图所示:
|
||||
|
||||

|
||||
|
||||
## 4. 推理部署
|
||||
|
||||
### 4.1 Python推理
|
||||
|
||||
暂不支持
|
||||
|
||||
### 4.2 C++推理部署
|
||||
|
||||
暂不支持
|
||||
|
||||
### 4.3 Serving服务化部署
|
||||
|
||||
暂不支持
|
||||
|
||||
### 4.4 更多推理部署
|
||||
|
||||
暂不支持
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
## 引用
|
||||
|
||||
```bibtex
|
||||
@misc{sun2021spatial,
|
||||
title={Spatial Dual-Modality Graph Reasoning for Key Information Extraction},
|
||||
author={Hongbin Sun and Zhanghui Kuang and Xiaoyu Yue and Chenhao Lin and Wayne Zhang},
|
||||
year={2021},
|
||||
eprint={2103.14470},
|
||||
archivePrefix={arXiv},
|
||||
primaryClass={cs.CV}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,168 @@
|
||||
---
|
||||
comments: true
|
||||
---
|
||||
|
||||
# KIE Algorithm - VI-LayoutXLM
|
||||
|
||||
## 1. Introduction
|
||||
|
||||
VI-LayoutXLM is improved based on LayoutXLM. In the process of downstream finetuning, the visual backbone network module is removed, and the model infernce speed is further improved on the basis of almost lossless accuracy.
|
||||
|
||||
On XFUND_zh dataset, the algorithm reproduction Hmean is as follows.
|
||||
|
||||
|Model|Backbone|Task |Config|Hmean|Download link|
|
||||
| --- | --- |---| --- | --- | --- |
|
||||
|VI-LayoutXLM |VI-LayoutXLM-base | SER |[ser_vi_layoutxlm_xfund_zh_udml.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/kie/vi_layoutxlm/ser_vi_layoutxlm_xfund_zh_udml.yml)|93.19%|[trained model](https://paddleocr.bj.bcebos.com/ppstructure/models/vi_layoutxlm/ser_vi_layoutxlm_xfund_pretrained.tar)/[inference model](https://paddleocr.bj.bcebos.com/ppstructure/models/vi_layoutxlm/ser_vi_layoutxlm_xfund_infer.tar)|
|
||||
|VI-LayoutXLM |VI-LayoutXLM-base |RE | [re_vi_layoutxlm_xfund_zh_udml.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/kie/vi_layoutxlm/re_vi_layoutxlm_xfund_zh_udml.yml)|83.92%|[trained model](https://paddleocr.bj.bcebos.com/ppstructure/models/vi_layoutxlm/re_vi_layoutxlm_xfund_pretrained.tar)/[inference model](https://paddleocr.bj.bcebos.com/ppstructure/models/vi_layoutxlm/re_vi_layoutxlm_xfund_infer.tar)|
|
||||
|
||||
## 2. Environment
|
||||
|
||||
Please refer to ["Environment Preparation"](../../ppocr/environment.en.md) to configure the PaddleOCR environment, and refer to ["Project Clone"](../../ppocr/blog/clone.en.md)to clone the project code.
|
||||
|
||||
## 3. Model Training / Evaluation / Prediction
|
||||
|
||||
Please refer to [KIE tutorial](../../ppocr/model_train/kie.en.md). PaddleOCR has modularized the code structure, so that you only need to **replace the configuration file** to train different models.
|
||||
|
||||
## 4. Inference and Deployment
|
||||
|
||||
### 4.1 Python Inference
|
||||
|
||||
#### SER
|
||||
|
||||
First, we need to export the trained model into inference model. Take VI-LayoutXLM model trained on XFUND_zh as an example ([trained model download link](https://paddleocr.bj.bcebos.com/ppstructure/models/vi_layoutxlm/ser_vi_layoutxlm_xfund_pretrained.tar)). Use the following command to export.
|
||||
|
||||
``` bash
|
||||
wget https://paddleocr.bj.bcebos.com/ppstructure/models/vi_layoutxlm/ser_vi_layoutxlm_xfund_pretrained.tar
|
||||
tar -xf ser_vi_layoutxlm_xfund_pretrained.tar
|
||||
python3 tools/export_model.py -c configs/kie/vi_layoutxlm/ser_vi_layoutxlm_xfund_zh.yml -o Architecture.Backbone.checkpoints=./ser_vi_layoutxlm_xfund_pretrained/best_accuracy Global.save_inference_dir=./inference/ser_vi_layoutxlm_infer
|
||||
```
|
||||
|
||||
Use the following command to infer using VI-LayoutXLM SER model.
|
||||
|
||||
```bash linenums="1"
|
||||
cd ppstructure
|
||||
python3 kie/predict_kie_token_ser.py \
|
||||
--kie_algorithm=LayoutXLM \
|
||||
--ser_model_dir=../inference/ser_vi_layoutxlm_infer \
|
||||
--image_dir=./docs/kie/input/zh_val_42.jpg \
|
||||
--ser_dict_path=../train_data/XFUND/class_list_xfun.txt \
|
||||
--vis_font_path=../doc/fonts/simfang.ttf \
|
||||
--ocr_order_method="tb-yx"
|
||||
```
|
||||
|
||||
The SER visualization results are saved in the `./output` folder by default. The results are as follows.
|
||||
|
||||

|
||||
|
||||
#### RE
|
||||
|
||||
First, we need to export the trained model into inference model. Take VI-LayoutXLM model trained on XFUND_zh as an example ([trained model download link](https://paddleocr.bj.bcebos.com/ppstructure/models/vi_layoutxlm/re_vi_layoutxlm_xfund_pretrained.tar)). Use the following command to export.
|
||||
|
||||
``` bash
|
||||
wget https://paddleocr.bj.bcebos.com/ppstructure/models/vi_layoutxlm/re_vi_layoutxlm_xfund_pretrained.tar
|
||||
tar -xf re_vi_layoutxlm_xfund_pretrained.tar
|
||||
python3 tools/export_model.py -c configs/kie/vi_layoutxlm/re_vi_layoutxlm_xfund_zh.yml -o Architecture.Backbone.checkpoints=./re_vi_layoutxlm_xfund_pretrained/best_accuracy Global.save_inference_dir=./inference/re_vi_layoutxlm_infer
|
||||
```
|
||||
|
||||
Use the following command to infer using VI-LayoutXLM RE model.
|
||||
|
||||
```bash linenums="1"
|
||||
cd ppstructure
|
||||
python3 kie/predict_kie_token_ser_re.py \
|
||||
--kie_algorithm=LayoutXLM \
|
||||
--re_model_dir=../inference/re_vi_layoutxlm_infer \
|
||||
--ser_model_dir=../inference/ser_vi_layoutxlm_infer \
|
||||
--use_visual_backbone=False \
|
||||
--image_dir=./docs/kie/input/zh_val_42.jpg \
|
||||
--ser_dict_path=../train_data/XFUND/class_list_xfun.txt \
|
||||
--vis_font_path=../doc/fonts/simfang.ttf \
|
||||
--ocr_order_method="tb-yx"
|
||||
```
|
||||
|
||||
The RE visualization results are saved in the `./output` folder by default. The results are as follows.
|
||||
|
||||

|
||||
|
||||
### 4.2 C++ Inference
|
||||
|
||||
Not supported
|
||||
|
||||
### 4.3 Serving
|
||||
|
||||
Not supported
|
||||
|
||||
### 4.4 More
|
||||
|
||||
Not supported
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
## Citation
|
||||
|
||||
```bibtex
|
||||
@article{DBLP:journals/corr/abs-2104-08836,
|
||||
author = {Yiheng Xu and
|
||||
Tengchao Lv and
|
||||
Lei Cui and
|
||||
Guoxin Wang and
|
||||
Yijuan Lu and
|
||||
Dinei Flor{\^{e}}ncio and
|
||||
Cha Zhang and
|
||||
Furu Wei},
|
||||
title = {LayoutXLM: Multimodal Pre-training for Multilingual Visually-rich
|
||||
Document Understanding},
|
||||
journal = {CoRR},
|
||||
volume = {abs/2104.08836},
|
||||
year = {2021},
|
||||
url = {https://arxiv.org/abs/2104.08836},
|
||||
eprinttype = {arXiv},
|
||||
eprint = {2104.08836},
|
||||
timestamp = {Thu, 14 Oct 2021 09:17:23 +0200},
|
||||
biburl = {https://dblp.org/rec/journals/corr/abs-2104-08836.bib},
|
||||
bibsource = {dblp computer science bibliography, https://dblp.org}
|
||||
}
|
||||
|
||||
@article{DBLP:journals/corr/abs-1912-13318,
|
||||
author = {Yiheng Xu and
|
||||
Minghao Li and
|
||||
Lei Cui and
|
||||
Shaohan Huang and
|
||||
Furu Wei and
|
||||
Ming Zhou},
|
||||
title = {LayoutLM: Pre-training of Text and Layout for Document Image Understanding},
|
||||
journal = {CoRR},
|
||||
volume = {abs/1912.13318},
|
||||
year = {2019},
|
||||
url = {http://arxiv.org/abs/1912.13318},
|
||||
eprinttype = {arXiv},
|
||||
eprint = {1912.13318},
|
||||
timestamp = {Mon, 01 Jun 2020 16:20:46 +0200},
|
||||
biburl = {https://dblp.org/rec/journals/corr/abs-1912-13318.bib},
|
||||
bibsource = {dblp computer science bibliography, https://dblp.org}
|
||||
}
|
||||
|
||||
@article{DBLP:journals/corr/abs-2012-14740,
|
||||
author = {Yang Xu and
|
||||
Yiheng Xu and
|
||||
Tengchao Lv and
|
||||
Lei Cui and
|
||||
Furu Wei and
|
||||
Guoxin Wang and
|
||||
Yijuan Lu and
|
||||
Dinei A. F. Flor{\^{e}}ncio and
|
||||
Cha Zhang and
|
||||
Wanxiang Che and
|
||||
Min Zhang and
|
||||
Lidong Zhou},
|
||||
title = {LayoutLMv2: Multi-modal Pre-training for Visually-Rich Document Understanding},
|
||||
journal = {CoRR},
|
||||
volume = {abs/2012.14740},
|
||||
year = {2020},
|
||||
url = {https://arxiv.org/abs/2012.14740},
|
||||
eprinttype = {arXiv},
|
||||
eprint = {2012.14740},
|
||||
timestamp = {Tue, 27 Jul 2021 09:53:52 +0200},
|
||||
biburl = {https://dblp.org/rec/journals/corr/abs-2012-14740.bib},
|
||||
bibsource = {dblp computer science bibliography, https://dblp.org}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,169 @@
|
||||
---
|
||||
comments: true
|
||||
---
|
||||
|
||||
|
||||
# 关键信息抽取算法-VI-LayoutXLM
|
||||
|
||||
## 1. 算法简介
|
||||
|
||||
VI-LayoutXLM基于LayoutXLM进行改进,在下游任务训练过程中,去除视觉骨干网络模块,最终精度基本无损的情况下,模型推理速度进一步提升。
|
||||
|
||||
在XFUND_zh数据集上,算法复现效果如下:
|
||||
|
||||
|模型|骨干网络|任务|配置文件|hmean|下载链接|
|
||||
| --- | --- |---| --- | --- | --- |
|
||||
|VI-LayoutXLM |VI-LayoutXLM-base | SER |[ser_vi_layoutxlm_xfund_zh_udml.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/kie/vi_layoutxlm/ser_vi_layoutxlm_xfund_zh_udml.yml)|93.19%|[训练模型](https://paddleocr.bj.bcebos.com/ppstructure/models/vi_layoutxlm/ser_vi_layoutxlm_xfund_pretrained.tar)/[推理模型](https://paddleocr.bj.bcebos.com/ppstructure/models/vi_layoutxlm/ser_vi_layoutxlm_xfund_infer.tar)|
|
||||
|VI-LayoutXLM |VI-LayoutXLM-base |RE | [re_vi_layoutxlm_xfund_zh_udml.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/kie/vi_layoutxlm/re_vi_layoutxlm_xfund_zh_udml.yml)|83.92%|[训练模型](https://paddleocr.bj.bcebos.com/ppstructure/models/vi_layoutxlm/re_vi_layoutxlm_xfund_pretrained.tar)/[推理模型](https://paddleocr.bj.bcebos.com/ppstructure/models/vi_layoutxlm/re_vi_layoutxlm_xfund_infer.tar)|
|
||||
|
||||
## 2. 环境配置
|
||||
|
||||
请先参考[《运行环境准备》](../../ppocr/environment.md)配置PaddleOCR运行环境,参考[《项目克隆》](../../ppocr/blog/clone.md)克隆项目代码。
|
||||
|
||||
## 3. 模型训练、评估、预测
|
||||
|
||||
请参考[关键信息抽取教程](../../ppocr/model_train/kie.md)。PaddleOCR对代码进行了模块化,训练不同的关键信息抽取模型只需要**更换配置文件**即可。
|
||||
|
||||
## 4. 推理部署
|
||||
|
||||
### 4.1 Python推理
|
||||
|
||||
#### SER
|
||||
|
||||
首先将训练得到的模型转换成inference model。以VI-LayoutXLM模型在XFUND_zh数据集上训练的模型为例([模型下载地址](https://paddleocr.bj.bcebos.com/ppstructure/models/vi_layoutxlm/ser_vi_layoutxlm_xfund_pretrained.tar)),可以使用下面的命令进行转换。
|
||||
|
||||
``` bash
|
||||
wget https://paddleocr.bj.bcebos.com/ppstructure/models/vi_layoutxlm/ser_vi_layoutxlm_xfund_pretrained.tar
|
||||
tar -xf ser_vi_layoutxlm_xfund_pretrained.tar
|
||||
python3 tools/export_model.py -c configs/kie/vi_layoutxlm/ser_vi_layoutxlm_xfund_zh.yml -o Architecture.Backbone.checkpoints=./ser_vi_layoutxlm_xfund_pretrained/best_accuracy Global.save_inference_dir=./inference/ser_vi_layoutxlm_infer
|
||||
```
|
||||
|
||||
VI-LayoutXLM模型基于SER任务进行推理,可以执行如下命令:
|
||||
|
||||
```bash linenums="1"
|
||||
cd ppstructure
|
||||
python3 kie/predict_kie_token_ser.py \
|
||||
--kie_algorithm=LayoutXLM \
|
||||
--ser_model_dir=../inference/ser_vi_layoutxlm_infer \
|
||||
--image_dir=./docs/kie/input/zh_val_42.jpg \
|
||||
--ser_dict_path=../train_data/XFUND/class_list_xfun.txt \
|
||||
--vis_font_path=../doc/fonts/simfang.ttf \
|
||||
--ocr_order_method="tb-yx"
|
||||
```
|
||||
|
||||
SER可视化结果默认保存到`./output`文件夹里面,结果示例如下:
|
||||
|
||||

|
||||
|
||||
#### RE
|
||||
|
||||
首先将训练得到的模型转换成inference model。以VI-LayoutXLM模型在XFUND_zh数据集上训练的模型为例([模型下载地址](https://paddleocr.bj.bcebos.com/ppstructure/models/vi_layoutxlm/re_vi_layoutxlm_xfund_pretrained.tar)),可以使用下面的命令进行转换。
|
||||
|
||||
``` bash
|
||||
wget https://paddleocr.bj.bcebos.com/ppstructure/models/vi_layoutxlm/re_vi_layoutxlm_xfund_pretrained.tar
|
||||
tar -xf re_vi_layoutxlm_xfund_pretrained.tar
|
||||
python3 tools/export_model.py -c configs/kie/vi_layoutxlm/re_vi_layoutxlm_xfund_zh.yml -o Architecture.Backbone.checkpoints=./re_vi_layoutxlm_xfund_pretrained/best_accuracy Global.save_inference_dir=./inference/re_vi_layoutxlm_infer
|
||||
```
|
||||
|
||||
VI-LayoutXLM模型基于RE任务进行推理,可以执行如下命令:
|
||||
|
||||
```bash linenums="1"
|
||||
cd ppstructure
|
||||
python3 kie/predict_kie_token_ser_re.py \
|
||||
--kie_algorithm=LayoutXLM \
|
||||
--re_model_dir=../inference/re_vi_layoutxlm_infer \
|
||||
--ser_model_dir=../inference/ser_vi_layoutxlm_infer \
|
||||
--use_visual_backbone=False \
|
||||
--image_dir=./docs/kie/input/zh_val_42.jpg \
|
||||
--ser_dict_path=../train_data/XFUND/class_list_xfun.txt \
|
||||
--vis_font_path=../doc/fonts/simfang.ttf \
|
||||
--ocr_order_method="tb-yx"
|
||||
```
|
||||
|
||||
RE可视化结果默认保存到`./output`文件夹里面,结果示例如下:
|
||||
|
||||

|
||||
|
||||
### 4.2 C++推理部署
|
||||
|
||||
暂不支持
|
||||
|
||||
### 4.3 Serving服务化部署
|
||||
|
||||
暂不支持
|
||||
|
||||
### 4.4 更多推理部署
|
||||
|
||||
暂不支持
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
## 引用
|
||||
|
||||
```bibtex
|
||||
@article{DBLP:journals/corr/abs-2104-08836,
|
||||
author = {Yiheng Xu and
|
||||
Tengchao Lv and
|
||||
Lei Cui and
|
||||
Guoxin Wang and
|
||||
Yijuan Lu and
|
||||
Dinei Flor{\^{e}}ncio and
|
||||
Cha Zhang and
|
||||
Furu Wei},
|
||||
title = {LayoutXLM: Multimodal Pre-training for Multilingual Visually-rich
|
||||
Document Understanding},
|
||||
journal = {CoRR},
|
||||
volume = {abs/2104.08836},
|
||||
year = {2021},
|
||||
url = {https://arxiv.org/abs/2104.08836},
|
||||
eprinttype = {arXiv},
|
||||
eprint = {2104.08836},
|
||||
timestamp = {Thu, 14 Oct 2021 09:17:23 +0200},
|
||||
biburl = {https://dblp.org/rec/journals/corr/abs-2104-08836.bib},
|
||||
bibsource = {dblp computer science bibliography, https://dblp.org}
|
||||
}
|
||||
|
||||
@article{DBLP:journals/corr/abs-1912-13318,
|
||||
author = {Yiheng Xu and
|
||||
Minghao Li and
|
||||
Lei Cui and
|
||||
Shaohan Huang and
|
||||
Furu Wei and
|
||||
Ming Zhou},
|
||||
title = {LayoutLM: Pre-training of Text and Layout for Document Image Understanding},
|
||||
journal = {CoRR},
|
||||
volume = {abs/1912.13318},
|
||||
year = {2019},
|
||||
url = {http://arxiv.org/abs/1912.13318},
|
||||
eprinttype = {arXiv},
|
||||
eprint = {1912.13318},
|
||||
timestamp = {Mon, 01 Jun 2020 16:20:46 +0200},
|
||||
biburl = {https://dblp.org/rec/journals/corr/abs-1912-13318.bib},
|
||||
bibsource = {dblp computer science bibliography, https://dblp.org}
|
||||
}
|
||||
|
||||
@article{DBLP:journals/corr/abs-2012-14740,
|
||||
author = {Yang Xu and
|
||||
Yiheng Xu and
|
||||
Tengchao Lv and
|
||||
Lei Cui and
|
||||
Furu Wei and
|
||||
Guoxin Wang and
|
||||
Yijuan Lu and
|
||||
Dinei A. F. Flor{\^{e}}ncio and
|
||||
Cha Zhang and
|
||||
Wanxiang Che and
|
||||
Min Zhang and
|
||||
Lidong Zhou},
|
||||
title = {LayoutLMv2: Multi-modal Pre-training for Visually-Rich Document Understanding},
|
||||
journal = {CoRR},
|
||||
volume = {abs/2012.14740},
|
||||
year = {2020},
|
||||
url = {https://arxiv.org/abs/2012.14740},
|
||||
eprinttype = {arXiv},
|
||||
eprint = {2012.14740},
|
||||
timestamp = {Tue, 27 Jul 2021 09:53:52 +0200},
|
||||
biburl = {https://dblp.org/rec/journals/corr/abs-2012-14740.bib},
|
||||
bibsource = {dblp computer science bibliography, https://dblp.org}
|
||||
}
|
||||
```
|
||||
|
After Width: | Height: | Size: 208 KiB |
|
After Width: | Height: | Size: 1.6 MiB |
|
After Width: | Height: | Size: 1.5 MiB |
@@ -0,0 +1,179 @@
|
||||
---
|
||||
comments: true
|
||||
---
|
||||
|
||||
# Algorithms
|
||||
|
||||
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-OCRv3 models list](../ppocr/model_list.en.md).
|
||||
|
||||
>
|
||||
Developers are welcome to contribute more algorithms! Please refer to [add new algorithm](./add_new_algorithm.en.md) guideline.
|
||||
|
||||
## 1. Two-stage OCR Algorithms
|
||||
|
||||
### 1.1 Text Detection Algorithms
|
||||
|
||||
Supported text detection algorithms (Click the link to get the tutorial):
|
||||
|
||||
- [x] [DB && DB++](./text_detection/algorithm_det_db.en.md)
|
||||
- [x] [EAST](./text_detection/algorithm_det_east.en.md)
|
||||
- [x] [SAST](./text_detection/algorithm_det_sast.en.md)
|
||||
- [x] [PSENet](./text_detection/algorithm_det_psenet.en.md)
|
||||
- [x] [FCENet](./text_detection/algorithm_det_fcenet.en.md)
|
||||
- [x] [DRRG](./text_detection/algorithm_det_drrg.en.md)
|
||||
- [x] [CT](./text_detection/algorithm_det_ct.en.md)
|
||||
|
||||
On the ICDAR2015 dataset, the text detection result is as follows:
|
||||
|
||||
|Model|Backbone|Precision|Recall|Hmean|Download link|
|
||||
| --- | --- | --- | --- | --- | --- |
|
||||
|EAST|ResNet50_vd|88.71%|81.36%|84.88%|[trained model](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/det_r50_vd_east_v2.0_train.tar)|
|
||||
|EAST|MobileNetV3|78.20%|79.10%|78.65%|[trained model](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/det_mv3_east_v2.0_train.tar)|
|
||||
|DB|ResNet50_vd|86.41%|78.72%|82.38%|[trained model](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/det_r50_vd_db_v2.0_train.tar)|
|
||||
|DB|MobileNetV3|77.29%|73.08%|75.12%|[trained model](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/det_mv3_db_v2.0_train.tar)|
|
||||
|SAST|ResNet50_vd|91.39%|83.77%|87.42%|[trained model](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/det_r50_vd_sast_icdar15_v2.0_train.tar)|
|
||||
|PSE|ResNet50_vd|85.81%|79.53%|82.55%|[trained model](https://paddleocr.bj.bcebos.com/dygraph_v2.1/en_det/det_r50_vd_pse_v2.0_train.tar)|
|
||||
|PSE|MobileNetV3|82.20%|70.48%|75.89%|[trained model](https://paddleocr.bj.bcebos.com/dygraph_v2.1/en_det/det_mv3_pse_v2.0_train.tar)|
|
||||
|DB++|ResNet50|90.89%|82.66%|86.58%|[pretrained model](https://paddleocr.bj.bcebos.com/dygraph_v2.1/en_det/ResNet50_dcn_asf_synthtext_pretrained.pdparams)/[trained model](https://paddleocr.bj.bcebos.com/dygraph_v2.1/en_det/det_r50_db%2B%2B_icdar15_train.tar)|
|
||||
|
||||
On Total-Text dataset, the text detection result is as follows:
|
||||
|
||||
|Model|Backbone|Precision|Recall|Hmean|Download link|
|
||||
| --- | --- | --- | --- | --- | --- |
|
||||
|SAST|ResNet50_vd|89.63%|78.44%|83.66%|[trained model](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/det_r50_vd_sast_totaltext_v2.0_train.tar)|
|
||||
|CT|ResNet18_vd|88.68%|81.70%|85.05%|[trained model](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/det_r18_ct_train.tar)|
|
||||
|
||||
On CTW1500 dataset, the text detection result is as follows:
|
||||
|
||||
|Model|Backbone|Precision|Recall|Hmean| Download link|
|
||||
| --- | --- | --- | --- | --- |---|
|
||||
|FCE|ResNet50_dcn|88.39%|82.18%|85.27%| [trained model](https://paddleocr.bj.bcebos.com/contribution/det_r50_dcn_fce_ctw_v2.0_train.tar) |
|
||||
|DRRG|ResNet50_vd|89.92%|80.91%|85.18%|[trained model](https://paddleocr.bj.bcebos.com/contribution/det_r50_drrg_ctw_train.tar)|
|
||||
|
||||
**Note:** Additional data, like icdar2013, icdar2017, COCO-Text, ArT, was added to the model training of SAST. Download English public dataset in organized format used by PaddleOCR from:
|
||||
|
||||
- [Baidu Drive](https://pan.baidu.com/s/12cPnZcVuV1zn5DOd4mqjVw) (download code: 2bpi).
|
||||
- [Google Drive](https://drive.google.com/drive/folders/1ll2-XEVyCQLpJjawLDiRlvo_i4BqHCJe?usp=sharing)
|
||||
|
||||
### 1.2 Text Recognition Algorithms
|
||||
|
||||
Supported text recognition algorithms (Click the link to get the tutorial):
|
||||
|
||||
- [x] [CRNN](./text_recognition/algorithm_rec_crnn.en.md)
|
||||
- [x] [Rosetta](./text_recognition/algorithm_rec_rosetta.en.md)
|
||||
- [x] [STAR-Net](./text_recognition/algorithm_rec_starnet.en.md)
|
||||
- [x] [RARE](./text_recognition/algorithm_rec_rare.en.md)
|
||||
- [x] [SRN](./text_recognition/algorithm_rec_srn.en.md)
|
||||
- [x] [NRTR](./text_recognition/algorithm_rec_nrtr.en.md)
|
||||
- [x] [SAR](./text_recognition/algorithm_rec_sar.en.md)
|
||||
- [x] [SEED](./text_recognition/algorithm_rec_seed.en.md)
|
||||
- [x] [SVTR](./text_recognition/algorithm_rec_svtr.en.md)
|
||||
- [x] [ViTSTR](./text_recognition/algorithm_rec_vitstr.en.md)
|
||||
- [x] [ABINet](./text_recognition/algorithm_rec_abinet.en.md)
|
||||
- [x] [VisionLAN](./text_recognition/algorithm_rec_visionlan.en.md)
|
||||
- [x] [SPIN](./text_recognition/algorithm_rec_spin.en.md)
|
||||
- [x] [RobustScanner](./text_recognition/algorithm_rec_robustscanner.en.md)
|
||||
- [x] [RFL](./text_recognition/algorithm_rec_rfl.en.md)
|
||||
- [x] [ParseQ](./text_recognition/algorithm_rec_parseq.md)
|
||||
- [x] [CPPD](./text_recognition/algorithm_rec_cppd.en.md)
|
||||
- [x] [SATRN](./text_recognition/algorithm_rec_satrn.en.md)
|
||||
|
||||
Refer to [DTRB](https://arxiv.org/abs/1904.01906), the training and evaluation result of these above text recognition (using MJSynth and SynthText for training, evaluate on IIIT, SVT, IC03, IC13, IC15, SVTP, CUTE) is as follow:
|
||||
|
||||
|Model|Backbone|Avg Accuracy|Module combination|Download link|
|
||||
|---|---|---|---|---|
|
||||
|Rosetta|Resnet34_vd|79.11%|rec_r34_vd_none_none_ctc|[trained model](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_r34_vd_none_none_ctc_v2.0_train.tar)|
|
||||
|Rosetta|MobileNetV3|75.80%|rec_mv3_none_none_ctc|[trained model](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_mv3_none_none_ctc_v2.0_train.tar)|
|
||||
|CRNN|Resnet34_vd|81.04%|rec_r34_vd_none_bilstm_ctc|[trained model](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_r34_vd_none_bilstm_ctc_v2.0_train.tar)|
|
||||
|CRNN|MobileNetV3|77.95%|rec_mv3_none_bilstm_ctc|[trained model](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_mv3_none_bilstm_ctc_v2.0_train.tar)|
|
||||
|StarNet|Resnet34_vd|82.85%|rec_r34_vd_tps_bilstm_ctc|[trained model](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_r34_vd_tps_bilstm_ctc_v2.0_train.tar)|
|
||||
|StarNet|MobileNetV3|79.28%|rec_mv3_tps_bilstm_ctc|[trained model](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_mv3_tps_bilstm_ctc_v2.0_train.tar)|
|
||||
|RARE|Resnet34_vd|83.98%|rec_r34_vd_tps_bilstm_att |[trained model](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_r34_vd_tps_bilstm_att_v2.0_train.tar)|
|
||||
|RARE|MobileNetV3|81.76%|rec_mv3_tps_bilstm_att |[trained model](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_mv3_tps_bilstm_att_v2.0_train.tar)|
|
||||
|SRN|Resnet50_vd_fpn| 86.31% | rec_r50fpn_vd_none_srn |[trained model](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_r50_vd_srn_train.tar)|
|
||||
|NRTR|NRTR_MTB| 84.21% | rec_mtb_nrtr | [trained model](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_mtb_nrtr_train.tar) |
|
||||
|SAR|Resnet31| 87.20% | rec_r31_sar | [trained model](https://paddleocr.bj.bcebos.com/dygraph_v2.1/rec/rec_r31_sar_train.tar) |
|
||||
|SEED|Aster_Resnet| 85.35% | rec_resnet_stn_bilstm_att | [trained model](https://paddleocr.bj.bcebos.com/dygraph_v2.1/rec/rec_resnet_stn_bilstm_att.tar) |
|
||||
|SVTR|SVTR-Tiny| 89.25% | rec_svtr_tiny_none_ctc_en | [trained model](https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/rec_svtr_tiny_none_ctc_en_train.tar) |
|
||||
|ViTSTR|ViTSTR| 79.82% | rec_vitstr_none_ce | [trained model](https://paddleocr.bj.bcebos.com/rec_vitstr_none_ce_train.tar) |
|
||||
|ABINet|Resnet45| 90.75% | rec_r45_abinet | [trained model](https://paddleocr.bj.bcebos.com/rec_r45_abinet_train.tar) |
|
||||
|VisionLAN|Resnet45| 90.30% | rec_r45_visionlan | [trained model](https://paddleocr.bj.bcebos.com/VisionLAN/rec_r45_visionlan_train.tar) |
|
||||
|SPIN|ResNet32| 90.00% | rec_r32_gaspin_bilstm_att | [trained model](https://paddleocr.bj.bcebos.com/contribution/rec_r32_gaspin_bilstm_att.tar) |
|
||||
|RobustScanner|ResNet31| 87.77% | rec_r31_robustscanner | [trained model](https://paddleocr.bj.bcebos.com/contribution/rec_r31_robustscanner.tar)|
|
||||
|RFL|ResNetRFL| 88.63% | rec_resnet_rfl_att | [trained model](https://paddleocr.bj.bcebos.com/contribution/rec_resnet_rfl_att_train.tar) |
|
||||
|ParseQ|VIT| 91.24% | rec_vit_parseq_synth | [trained model](https://paddleocr.bj.bcebos.com/dygraph_v2.1/parseq/rec_vit_parseq_synth.tgz) |
|
||||
|CPPD|SVTR-Base| 93.8% | rec_svtrnet_cppd_base_en | [trained model](https://paddleocr.bj.bcebos.com/CCPD/rec_svtr_cppd_base_en_train.tar) |
|
||||
|SATRN|ShallowCNN| 88.05% | rec_satrn | [trained model](https://pan.baidu.com/s/10J-Bsd881bimKaclKszlaQ?pwd=lk8a) |
|
||||
|
||||
### 1.3 Text Super-Resolution Algorithms
|
||||
|
||||
Supported text super-resolution algorithms (Click the link to get the tutorial):
|
||||
|
||||
- [x] [Text Gestalt](./super_resolution/algorithm_sr_gestalt.en.md)
|
||||
- [x] [Text Telescope](./super_resolution/algorithm_sr_telescope.en.md)
|
||||
|
||||
On the TextZoom public dataset, the effect of the algorithm is as follows:
|
||||
|
||||
|Model|Backbone|PSNR_Avg|SSIM_Avg|Config|Download link|
|
||||
|---|---|---|---|---|---|
|
||||
|Text Gestalt|tsrn|19.28|0.6560| [configs/sr/sr_tsrn_transformer_strock.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/sr/sr_tsrn_transformer_strock.yml)|[trained model](https://paddleocr.bj.bcebos.com/sr_tsrn_transformer_strock_train.tar)|
|
||||
|Text Telescope|tbsrn|21.56|0.7411| [configs/sr/sr_telescope.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/sr/sr_telescope.yml)|[trained model](https://paddleocr.bj.bcebos.com/contribution/sr_telescope_train.tar)|
|
||||
|
||||
### 1.4 Formula Recognition Algorithm
|
||||
|
||||
Supported formula recognition algorithms (Click the link to get the tutorial):
|
||||
|
||||
- [x] [CAN](./formula_recognition/algorithm_rec_can.en.md)
|
||||
- [x] [LaTeX-OCR](./formula_recognition/algorithm_rec_latex_ocr.en.md)
|
||||
|
||||
On the CROHME handwritten formula dataset, the effect of the algorithm is as follows:
|
||||
|
||||
|Model |Backbone|Config|ExpRate|Download link|
|
||||
| ----- | ----- | ----- | ----- | ----- |
|
||||
|CAN|DenseNet|[rec_d28_can.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/rec/rec_d28_can.yml)|51.72%|[trained model](https://paddleocr.bj.bcebos.com/contribution/rec_d28_can_train.tar)|
|
||||
|
||||
## 2. End-to-end OCR Algorithms
|
||||
|
||||
Supported end-to-end algorithms (Click the link to get the tutorial):
|
||||
|
||||
- [x] [PGNet](./end_to_end/algorithm_e2e_pgnet.en.md)
|
||||
|
||||
## 3. Table Recognition Algorithms
|
||||
|
||||
Supported table recognition algorithms (Click the link to get the tutorial):
|
||||
|
||||
- [x] [TableMaster](./table_recognition/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](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/table/table_master.yml)|77.47%|[trained 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)|
|
||||
|
||||
## 4. Key Information Extraction Algorithms
|
||||
|
||||
Supported KIE algorithms (Click the link to get the tutorial):
|
||||
|
||||
- [x] [VI-LayoutXLM](./kie/algorithm_kie_vi_layoutxlm.en.md)
|
||||
- [x] [LayoutLM](./kie/algorithm_kie_layoutxlm.en.md)
|
||||
- [x] [LayoutLMv2](./kie/algorithm_kie_layoutxlm.en.md)
|
||||
- [x] [LayoutXLM](./kie/algorithm_kie_layoutxlm.en.md)
|
||||
- [x] [SDMGR](./kie/algorithm_kie_sdmgr.en.md)
|
||||
|
||||
On wildreceipt dataset, the algorithm result is as follows:
|
||||
|
||||
|Model|Backbone|Config|Hmean|Download link|
|
||||
| --- | --- | --- | --- | --- |
|
||||
|SDMGR|VGG6|[configs/kie/sdmgr/kie_unet_sdmgr.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/kie/sdmgr/kie_unet_sdmgr.yml)|86.70%|[trained model](https://paddleocr.bj.bcebos.com/dygraph_v2.1/kie/kie_vgg16.tar)|
|
||||
|
||||
On XFUND_zh dataset, the algorithm result is as follows:
|
||||
|
||||
|Model|Backbone|Task|Config|Hmean|Download link|
|
||||
| --- | --- | --- | --- | --- | --- |
|
||||
|VI-LayoutXLM| VI-LayoutXLM-base | SER | [ser_vi_layoutxlm_xfund_zh_udml.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/kie/vi_layoutxlm/ser_vi_layoutxlm_xfund_zh_udml.yml)|**93.19%**|[trained model](https://paddleocr.bj.bcebos.com/ppstructure/models/vi_layoutxlm/ser_vi_layoutxlm_xfund_pretrained.tar)|
|
||||
|LayoutXLM| LayoutXLM-base | SER | [ser_layoutxlm_xfund_zh.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/kie/layoutlm_series/ser_layoutxlm_xfund_zh.yml)|90.38%|[trained model](https://paddleocr.bj.bcebos.com/pplayout/ser_LayoutXLM_xfun_zh.tar)|
|
||||
|LayoutLM| LayoutLM-base | SER | [ser_layoutlm_xfund_zh.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/kie/layoutlm_series/ser_layoutlm_xfund_zh.yml)|77.31%|[trained model](https://paddleocr.bj.bcebos.com/pplayout/ser_LayoutLM_xfun_zh.tar)|
|
||||
|LayoutLMv2| LayoutLMv2-base | SER | [ser_layoutlmv2_xfund_zh.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/kie/layoutlm_series/ser_layoutlmv2_xfund_zh.yml)|85.44%|[trained model](https://paddleocr.bj.bcebos.com/pplayout/ser_LayoutLMv2_xfun_zh.tar)|
|
||||
|VI-LayoutXLM| VI-LayoutXLM-base | RE | [re_vi_layoutxlm_xfund_zh_udml.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/kie/vi_layoutxlm/re_vi_layoutxlm_xfund_zh_udml.yml)|**83.92%**|[trained model](https://paddleocr.bj.bcebos.com/ppstructure/models/vi_layoutxlm/re_vi_layoutxlm_xfund_pretrained.tar)|
|
||||
|LayoutXLM| LayoutXLM-base | RE | [re_layoutxlm_xfund_zh.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/kie/layoutlm_series/re_layoutxlm_xfund_zh.yml)|74.83%|[trained model](https://paddleocr.bj.bcebos.com/pplayout/re_LayoutXLM_xfun_zh.tar)|
|
||||
|LayoutLMv2| LayoutLMv2-base | RE | [re_layoutlmv2_xfund_zh.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/kie/layoutlm_series/re_layoutlmv2_xfund_zh.yml)|67.77%|[trained model](https://paddleocr.bj.bcebos.com/pplayout/re_LayoutLMv2_xfun_zh.tar)|
|
||||
@@ -0,0 +1,180 @@
|
||||
---
|
||||
comments: true
|
||||
---
|
||||
|
||||
# 前沿算法与模型
|
||||
|
||||
本文给出了PaddleOCR已支持的OCR算法列表,以及每个算法在**英文公开数据集**上的模型和指标,主要用于算法简介和算法性能对比,更多包括中文在内的其他数据集上的模型请参考[PP-OCRv3 系列模型下载](../ppocr/model_list.md)。
|
||||
|
||||
PaddleOCR将**持续新增**支持OCR领域前沿算法与模型,**欢迎广大开发者合作共建,贡献更多算法。**
|
||||
|
||||
新增算法可参考教程:[使用PaddleOCR架构添加新算法](./add_new_algorithm.md)
|
||||
|
||||
## 1. 两阶段算法
|
||||
|
||||
### 1.1 文本检测算法
|
||||
|
||||
已支持的文本检测算法列表(戳链接获取使用教程):
|
||||
|
||||
- [x] [DB与DB++](./text_detection/algorithm_det_db.md)
|
||||
- [x] [EAST](./text_detection/algorithm_det_east.md)
|
||||
- [x] [SAST](./text_detection/algorithm_det_sast.md)
|
||||
- [x] [PSENet](./text_detection/algorithm_det_psenet.md)
|
||||
- [x] [FCENet](./text_detection/algorithm_det_fcenet.md)
|
||||
- [x] [DRRG](./text_detection/algorithm_det_drrg.md)
|
||||
- [x] [CT](./text_detection/algorithm_det_ct.md)
|
||||
|
||||
在ICDAR2015文本检测公开数据集上,算法效果如下:
|
||||
|
||||
|模型|骨干网络|precision|recall|Hmean|下载链接|
|
||||
| --- | --- | --- | --- | --- | --- |
|
||||
|EAST|ResNet50_vd|88.71%|81.36%|84.88%|[训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/det_r50_vd_east_v2.0_train.tar)|
|
||||
|EAST|MobileNetV3|78.20%|79.10%|78.65%|[训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/det_mv3_east_v2.0_train.tar)|
|
||||
|DB|ResNet50_vd|86.41%|78.72%|82.38%|[训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/det_r50_vd_db_v2.0_train.tar)|
|
||||
|DB|MobileNetV3|77.29%|73.08%|75.12%|[训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/det_mv3_db_v2.0_train.tar)|
|
||||
|SAST|ResNet50_vd|91.39%|83.77%|87.42%|[训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/det_r50_vd_sast_icdar15_v2.0_train.tar)|
|
||||
|PSE|ResNet50_vd|85.81%|79.53%|82.55%|[训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.1/en_det/det_r50_vd_pse_v2.0_train.tar)|
|
||||
|PSE|MobileNetV3|82.20%|70.48%|75.89%|[训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.1/en_det/det_mv3_pse_v2.0_train.tar)|
|
||||
|DB++|ResNet50|90.89%|82.66%|86.58%|[合成数据预训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.1/en_det/ResNet50_dcn_asf_synthtext_pretrained.pdparams)/[训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.1/en_det/det_r50_db%2B%2B_icdar15_train.tar)|
|
||||
|
||||
在Total-text文本检测公开数据集上,算法效果如下:
|
||||
|
||||
|模型|骨干网络|precision|recall|Hmean|下载链接|
|
||||
| --- | --- | --- | --- | --- | --- |
|
||||
|SAST|ResNet50_vd|89.63%|78.44%|83.66%|[训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/det_r50_vd_sast_totaltext_v2.0_train.tar)|
|
||||
|CT|ResNet18_vd|88.68%|81.70%|85.05%|[训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/det_r18_ct_train.tar)|
|
||||
|
||||
在CTW1500文本检测公开数据集上,算法效果如下:
|
||||
|
||||
|模型|骨干网络|precision|recall|Hmean|下载链接|
|
||||
| --- | --- | --- | --- | --- | --- |
|
||||
|FCE|ResNet50_dcn|88.39%|82.18%|85.27%|[训练模型](https://paddleocr.bj.bcebos.com/contribution/det_r50_dcn_fce_ctw_v2.0_train.tar)|
|
||||
|DRRG|ResNet50_vd|89.92%|80.91%|85.18%|[训练模型](https://paddleocr.bj.bcebos.com/contribution/det_r50_drrg_ctw_train.tar)|
|
||||
|
||||
**说明:** SAST模型训练额外加入了icdar2013、icdar2017、COCO-Text、ArT等公开数据集进行调优。PaddleOCR用到的经过整理格式的英文公开数据集下载:
|
||||
|
||||
- [百度云地址](https://pan.baidu.com/s/12cPnZcVuV1zn5DOd4mqjVw) (提取码: 2bpi)
|
||||
- [Google Drive下载地址](https://drive.google.com/drive/folders/1ll2-XEVyCQLpJjawLDiRlvo_i4BqHCJe?usp=sharing)
|
||||
|
||||
### 1.2 文本识别算法
|
||||
|
||||
已支持的文本识别算法列表(戳链接获取使用教程):
|
||||
|
||||
- [x] [CRNN](./text_recognition/algorithm_rec_crnn.md)
|
||||
- [x] [Rosetta](./text_recognition/algorithm_rec_rosetta.md)
|
||||
- [x] [STAR-Net](./text_recognition/algorithm_rec_starnet.md)
|
||||
- [x] [RARE](./text_recognition/algorithm_rec_rare.md)
|
||||
- [x] [SRN](./text_recognition/algorithm_rec_srn.md)
|
||||
- [x] [NRTR](./text_recognition/algorithm_rec_nrtr.md)
|
||||
- [x] [SAR](./text_recognition/algorithm_rec_sar.md)
|
||||
- [x] [SEED](./text_recognition/algorithm_rec_seed.md)
|
||||
- [x] [SVTR](./text_recognition/algorithm_rec_svtr.md)
|
||||
- [x] [ViTSTR](./text_recognition/algorithm_rec_vitstr.md)
|
||||
- [x] [ABINet](./text_recognition/algorithm_rec_abinet.md)
|
||||
- [x] [VisionLAN](./text_recognition/algorithm_rec_visionlan.md)
|
||||
- [x] [SPIN](./text_recognition/algorithm_rec_spin.md)
|
||||
- [x] [RobustScanner](./text_recognition/algorithm_rec_robustscanner.md)
|
||||
- [x] [RFL](./text_recognition/algorithm_rec_rfl.md)
|
||||
- [x] [ParseQ](./text_recognition/algorithm_rec_parseq.md)
|
||||
- [x] [CPPD](./text_recognition/algorithm_rec_cppd.md)
|
||||
- [x] [SATRN](./text_recognition/algorithm_rec_satrn.md)
|
||||
|
||||
参考[DTRB](https://arxiv.org/abs/1904.01906) (3)文字识别训练和评估流程,使用MJSynth和SynthText两个文字识别数据集训练,在IIIT, SVT, IC03, IC13, IC15, SVTP, CUTE数据集上进行评估,算法效果如下:
|
||||
|
||||
|模型|骨干网络|Avg Accuracy|模型存储命名|下载链接|
|
||||
|---|---|---|---|---|
|
||||
|Rosetta|Resnet34_vd|79.11%|rec_r34_vd_none_none_ctc|[训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_r34_vd_none_none_ctc_v2.0_train.tar)|
|
||||
|Rosetta|MobileNetV3|75.80%|rec_mv3_none_none_ctc|[训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_mv3_none_none_ctc_v2.0_train.tar)|
|
||||
|CRNN|Resnet34_vd|81.04%|rec_r34_vd_none_bilstm_ctc|[训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_r34_vd_none_bilstm_ctc_v2.0_train.tar)|
|
||||
|CRNN|MobileNetV3|77.95%|rec_mv3_none_bilstm_ctc|[训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_mv3_none_bilstm_ctc_v2.0_train.tar)|
|
||||
|StarNet|Resnet34_vd|82.85%|rec_r34_vd_tps_bilstm_ctc|[训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_r34_vd_tps_bilstm_ctc_v2.0_train.tar)|
|
||||
|StarNet|MobileNetV3|79.28%|rec_mv3_tps_bilstm_ctc|[训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_mv3_tps_bilstm_ctc_v2.0_train.tar)|
|
||||
|RARE|Resnet34_vd|83.98%|rec_r34_vd_tps_bilstm_att |[训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_r34_vd_tps_bilstm_att_v2.0_train.tar)|
|
||||
|RARE|MobileNetV3|81.76%|rec_mv3_tps_bilstm_att |[训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_mv3_tps_bilstm_att_v2.0_train.tar)|
|
||||
|SRN|Resnet50_vd_fpn| 86.31% | rec_r50fpn_vd_none_srn | [训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_r50_vd_srn_train.tar) |
|
||||
|NRTR|NRTR_MTB| 84.21% | rec_mtb_nrtr | [训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_mtb_nrtr_train.tar) |
|
||||
|SAR|Resnet31| 87.20% | rec_r31_sar | [训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.1/rec/rec_r31_sar_train.tar) |
|
||||
|SEED|Aster_Resnet| 85.35% | rec_resnet_stn_bilstm_att | [训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.1/rec/rec_resnet_stn_bilstm_att.tar) |
|
||||
|SVTR|SVTR-Tiny| 89.25% | rec_svtr_tiny_none_ctc_en | [训练模型](https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/rec_svtr_tiny_none_ctc_en_train.tar) |
|
||||
|ViTSTR|ViTSTR| 79.82% | rec_vitstr_none_ce | [训练模型](https://paddleocr.bj.bcebos.com/rec_vitstr_none_ce_train.tar) |
|
||||
|ABINet|Resnet45| 90.75% | rec_r45_abinet | [训练模型](https://paddleocr.bj.bcebos.com/rec_r45_abinet_train.tar) |
|
||||
|VisionLAN|Resnet45| 90.30% | rec_r45_visionlan | [训练模型](https://paddleocr.bj.bcebos.com/VisionLAN/rec_r45_visionlan_train.tar) |
|
||||
|SPIN|ResNet32| 90.00% | rec_r32_gaspin_bilstm_att | [训练模型](https://paddleocr.bj.bcebos.com/contribution/rec_r32_gaspin_bilstm_att.tar) |
|
||||
|RobustScanner|ResNet31| 87.77% | rec_r31_robustscanner | [训练模型](https://paddleocr.bj.bcebos.com/contribution/rec_r31_robustscanner.tar)|
|
||||
|RFL|ResNetRFL| 88.63% | rec_resnet_rfl_att | [训练模型](https://paddleocr.bj.bcebos.com/contribution/rec_resnet_rfl_att_train.tar) |
|
||||
|ParseQ|VIT| 91.24% | rec_vit_parseq_synth | [训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.1/parseq/rec_vit_parseq_synth.tgz) |
|
||||
|CPPD|SVTR-Base| 93.8% | rec_svtrnet_cppd_base_en | [训练模型](https://paddleocr.bj.bcebos.com/CCPD/rec_svtr_cppd_base_en_train.tar) |
|
||||
|SATRN|ShallowCNN| 88.05% | rec_satrn | [训练模型](https://pan.baidu.com/s/10J-Bsd881bimKaclKszlaQ?pwd=lk8a) |
|
||||
|
||||
### 1.3 文本超分辨率算法
|
||||
|
||||
已支持的文本超分辨率算法列表(戳链接获取使用教程):
|
||||
|
||||
- [x] [Text Gestalt](./super_resolution/algorithm_sr_gestalt.md)
|
||||
- [x] [Text Telescope](./super_resolution/algorithm_sr_telescope.md)
|
||||
|
||||
在TextZoom公开数据集上,算法效果如下:
|
||||
|
||||
|模型|骨干网络|PSNR_Avg|SSIM_Avg|配置文件|下载链接|
|
||||
|---|---|---|---|---|---|
|
||||
|Text Gestalt|tsrn|19.28|0.6560| [configs/sr/sr_tsrn_transformer_strock.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/sr/sr_tsrn_transformer_strock.yml)|[训练模型](https://paddleocr.bj.bcebos.com/sr_tsrn_transformer_strock_train.tar)|
|
||||
|Text Telescope|tbsrn|21.56|0.7411| [configs/sr/sr_telescope.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/sr/sr_telescope.yml)|[训练模型](https://paddleocr.bj.bcebos.com/contribution/sr_telescope_train.tar)|
|
||||
|
||||
### 1.4 公式识别算法
|
||||
|
||||
已支持的公式识别算法列表(戳链接获取使用教程):
|
||||
|
||||
- [x] [CAN](./formula_recognition/algorithm_rec_can.md)
|
||||
- [x] [LaTeX-OCR](./formula_recognition/algorithm_rec_latex_ocr.md)
|
||||
|
||||
在CROHME手写公式数据集上,算法效果如下:
|
||||
|
||||
|模型 |骨干网络|配置文件|ExpRate|下载链接|
|
||||
| ----- | ----- | ----- | ----- | ----- |
|
||||
|CAN|DenseNet|[rec_d28_can.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/rec/rec_d28_can.yml)|51.72%|[训练模型](https://paddleocr.bj.bcebos.com/contribution/rec_d28_can_train.tar)|
|
||||
|
||||
## 2. 端到端算法
|
||||
|
||||
已支持的端到端OCR算法列表(戳链接获取使用教程):
|
||||
|
||||
- [x] [PGNet](./end_to_end/algorithm_e2e_pgnet.md)
|
||||
|
||||
## 3. 表格识别算法
|
||||
|
||||
已支持的表格识别算法列表(戳链接获取使用教程):
|
||||
|
||||
- [x] [TableMaster](./table_recognition/algorithm_table_master.md)
|
||||
|
||||
在PubTabNet表格识别公开数据集上,算法效果如下:
|
||||
|
||||
|模型|骨干网络|配置文件|acc|下载链接|
|
||||
|---|---|---|---|---|
|
||||
|TableMaster|TableResNetExtra|[configs/table/table_master.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/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)|
|
||||
|
||||
## 4. 关键信息抽取算法
|
||||
|
||||
已支持的关键信息抽取算法列表(戳链接获取使用教程):
|
||||
|
||||
- [x] [VI-LayoutXLM](./kie/algorithm_kie_vi_layoutxlm.md)
|
||||
- [x] [LayoutLM](./kie/algorithm_kie_layoutxlm.md)
|
||||
- [x] [LayoutLMv2](./kie/algorithm_kie_layoutxlm.md)
|
||||
- [x] [LayoutXLM](./kie/algorithm_kie_layoutxlm.md)
|
||||
- [x] [SDMGR](./kie/algorithm_kie_sdmgr.md)
|
||||
|
||||
在wildreceipt发票公开数据集上,算法复现效果如下:
|
||||
|
||||
|模型|骨干网络|配置文件|hmean|下载链接|
|
||||
| --- | --- | --- | --- | --- |
|
||||
|SDMGR|VGG6|[configs/kie/sdmgr/kie_unet_sdmgr.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/kie/sdmgr/kie_unet_sdmgr.yml)|86.70%|[训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.1/kie/kie_vgg16.tar)|
|
||||
|
||||
在XFUND_zh公开数据集上,算法效果如下:
|
||||
|
||||
|模型|骨干网络|任务|配置文件|hmean|下载链接|
|
||||
| --- | --- | --- | --- | --- | --- |
|
||||
|VI-LayoutXLM| VI-LayoutXLM-base | SER | [ser_vi_layoutxlm_xfund_zh_udml.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/kie/vi_layoutxlm/ser_vi_layoutxlm_xfund_zh_udml.yml)|**93.19%**|[训练模型](https://paddleocr.bj.bcebos.com/ppstructure/models/vi_layoutxlm/ser_vi_layoutxlm_xfund_pretrained.tar)|
|
||||
|LayoutXLM| LayoutXLM-base | SER | [ser_layoutxlm_xfund_zh.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/kie/layoutlm_series/ser_layoutxlm_xfund_zh.yml)|90.38%|[训练模型](https://paddleocr.bj.bcebos.com/pplayout/ser_LayoutXLM_xfun_zh.tar)|
|
||||
|LayoutLM| LayoutLM-base | SER | [ser_layoutlm_xfund_zh.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/kie/layoutlm_series/ser_layoutlm_xfund_zh.yml)|77.31%|[训练模型](https://paddleocr.bj.bcebos.com/pplayout/ser_LayoutLM_xfun_zh.tar)|
|
||||
|LayoutLMv2| LayoutLMv2-base | SER | [ser_layoutlmv2_xfund_zh.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/kie/layoutlm_series/ser_layoutlmv2_xfund_zh.yml)|85.44%|[训练模型](https://paddleocr.bj.bcebos.com/pplayout/ser_LayoutLMv2_xfun_zh.tar)|
|
||||
|VI-LayoutXLM| VI-LayoutXLM-base | RE | [re_vi_layoutxlm_xfund_zh_udml.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/kie/vi_layoutxlm/re_vi_layoutxlm_xfund_zh_udml.yml)|**83.92%**|[训练模型](https://paddleocr.bj.bcebos.com/ppstructure/models/vi_layoutxlm/re_vi_layoutxlm_xfund_pretrained.tar)|
|
||||
|LayoutXLM| LayoutXLM-base | RE | [re_layoutxlm_xfund_zh.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/kie/layoutlm_series/re_layoutxlm_xfund_zh.yml)|74.83%|[训练模型](https://paddleocr.bj.bcebos.com/pplayout/re_LayoutXLM_xfun_zh.tar)|
|
||||
|LayoutLMv2| LayoutLMv2-base | RE | [re_layoutlmv2_xfund_zh.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/kie/layoutlm_series/re_layoutlmv2_xfund_zh.yml)|67.77%|[训练模型](https://paddleocr.bj.bcebos.com/pplayout/re_LayoutLMv2_xfun_zh.tar)|
|
||||
@@ -0,0 +1,107 @@
|
||||
---
|
||||
comments: true
|
||||
---
|
||||
|
||||
# Text Gestalt
|
||||
|
||||
## 1. Introduction
|
||||
|
||||
Paper:
|
||||
> [Text Gestalt: Stroke-Aware Scene Text Image Super-Resolution](https://arxiv.org/pdf/2112.08171.pdf)
|
||||
> Chen, Jingye and Yu, Haiyang and Ma, Jianqi and Li, Bin and Xue, Xiangyang
|
||||
> AAAI, 2022
|
||||
|
||||
Referring to the [FudanOCR](https://github.com/FudanVI/FudanOCR/tree/main/text-gestalt) data download instructions, the effect of the super-score algorithm on the TextZoom test set is as follows:
|
||||
|
||||
|Model | Backbone|config|Acc|Download link|
|
||||
|---|---|---|---|---|
|
||||
|Text Gestalt|tsrn|19.28|0.6560| [configs/sr/sr_tsrn_transformer_strock.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/sr/sr_tsrn_transformer_strock.yml)|[train model](https://paddleocr.bj.bcebos.com/sr_tsrn_transformer_strock_train.tar)|
|
||||
|
||||
## 2. Environment
|
||||
|
||||
Please refer to ["Environment Preparation"](../../ppocr/environment.en.md) to configure the PaddleOCR environment, and refer to ["Project Clone"](../../ppocr/blog/clone.en.md)to clone the project code.
|
||||
|
||||
## 3. Model Training / Evaluation / Prediction
|
||||
|
||||
Please refer to [Text Recognition Tutorial](../../ppocr/model_train/recognition.en.md). PaddleOCR modularizes the code, and training different models only requires **changing the configuration file**.
|
||||
|
||||
### Training
|
||||
|
||||
Specifically, after the data preparation is completed, the training can be started. The training command is as follows:
|
||||
|
||||
```bash linenums="1"
|
||||
# Single GPU training (long training period, not recommended)
|
||||
python3 tools/train.py -c configs/sr/sr_tsrn_transformer_strock.yml
|
||||
|
||||
# Multi GPU training, specify the gpu number through the --gpus parameter
|
||||
python3 -m paddle.distributed.launch --gpus '0,1,2,3' tools/train.py -c configs/sr/sr_tsrn_transformer_strock.yml
|
||||
```
|
||||
|
||||
### Evaluation
|
||||
|
||||
```bash linenums="1"
|
||||
# GPU evaluation
|
||||
python3 -m paddle.distributed.launch --gpus '0' tools/eval.py -c configs/sr/sr_tsrn_transformer_strock.yml -o Global.pretrained_model={path/to/weights}/best_accuracy
|
||||
```
|
||||
|
||||
### Prediction
|
||||
|
||||
```bash linenums="1"
|
||||
# The configuration file used for prediction must match the training
|
||||
|
||||
python3 tools/infer_sr.py -c configs/sr/sr_tsrn_transformer_strock.yml -o Global.pretrained_model={path/to/weights}/best_accuracy Global.infer_img=doc/imgs_words_en/word_52.png
|
||||
```
|
||||
|
||||

|
||||
|
||||
After executing the command, the super-resolution result of the above image is as follows:
|
||||
|
||||

|
||||
|
||||
## 4. Inference and Deployment
|
||||
|
||||
### 4.1 Python Inference
|
||||
|
||||
First, the model saved during the training process is converted into an inference model. ( [Model download link](https://paddleocr.bj.bcebos.com/sr_tsrn_transformer_strock_train.tar) ), you can use the following command to convert:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/export_model.py -c configs/sr/sr_tsrn_transformer_strock.yml -o Global.pretrained_model={path/to/weights}/best_accuracy Global.save_inference_dir=./inference/sr_out
|
||||
```
|
||||
|
||||
For Text-Gestalt super-resolution model inference, the following commands can be executed:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_sr.py --sr_model_dir=./inference/sr_out --image_dir=doc/imgs_words_en/word_52.png --sr_image_shape=3,32,128
|
||||
```
|
||||
|
||||
After executing the command, the super-resolution result of the above image is as follows:
|
||||
|
||||

|
||||
|
||||
### 4.2 C++ Inference
|
||||
|
||||
Not supported
|
||||
|
||||
### 4.3 Serving
|
||||
|
||||
Not supported
|
||||
|
||||
### 4.4 More
|
||||
|
||||
Not supported
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
## Citation
|
||||
|
||||
```bibtex
|
||||
@inproceedings{chen2022text,
|
||||
title={Text gestalt: Stroke-aware scene text image super-resolution},
|
||||
author={Chen, Jingye and Yu, Haiyang and Ma, Jianqi and Li, Bin and Xue, Xiangyang},
|
||||
booktitle={Proceedings of the AAAI Conference on Artificial Intelligence},
|
||||
volume={36},
|
||||
number={1},
|
||||
pages={285--293},
|
||||
year={2022}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,107 @@
|
||||
---
|
||||
typora-copy-images-to: images
|
||||
comments: true
|
||||
---
|
||||
|
||||
# Text Gestalt
|
||||
|
||||
## 1. 算法简介
|
||||
|
||||
论文信息:
|
||||
> [Text Gestalt: Stroke-Aware Scene Text Image Super-Resolution](https://arxiv.org/pdf/2112.08171.pdf)
|
||||
> Chen, Jingye and Yu, Haiyang and Ma, Jianqi and Li, Bin and Xue, Xiangyang
|
||||
> AAAI, 2022
|
||||
|
||||
参考[FudanOCR](https://github.com/FudanVI/FudanOCR/tree/main/text-gestalt) 数据下载说明,在TextZoom测试集合上超分算法效果如下:
|
||||
|
||||
|模型|骨干网络|PSNR_Avg|SSIM_Avg|配置文件|下载链接|
|
||||
|---|---|---|---|---|---|
|
||||
|Text Gestalt|tsrn|19.28|0.6560| [configs/sr/sr_tsrn_transformer_strock.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/sr/sr_tsrn_transformer_strock.yml)|[训练模型](https://paddleocr.bj.bcebos.com/sr_tsrn_transformer_strock_train.tar)|
|
||||
|
||||
## 2. 环境配置
|
||||
|
||||
请先参考[《运行环境准备》](../../ppocr/environment.md)配置PaddleOCR运行环境,参考[《项目克隆》](../../ppocr/blog/clone.md)克隆项目代码。
|
||||
|
||||
## 3. 模型训练、评估、预测
|
||||
|
||||
请参考[文本识别训练教程](../../ppocr/model_train/recognition.md)。PaddleOCR对代码进行了模块化,训练不同的识别模型只需要**更换配置文件**即可。
|
||||
|
||||
### 训练
|
||||
|
||||
在完成数据准备后,便可以启动训练,训练命令如下:
|
||||
|
||||
```bash linenums="1"
|
||||
#单卡训练(训练周期长,不建议)
|
||||
python3 tools/train.py -c configs/sr/sr_tsrn_transformer_strock.yml
|
||||
|
||||
# 多卡训练,通过--gpus参数指定卡号
|
||||
python3 -m paddle.distributed.launch --gpus '0,1,2,3' tools/train.py -c configs/sr/sr_tsrn_transformer_strock.yml
|
||||
```
|
||||
|
||||
### 评估
|
||||
|
||||
```bash linenums="1"
|
||||
# GPU 评估, Global.pretrained_model 为待测权重
|
||||
python3 -m paddle.distributed.launch --gpus '0' tools/eval.py -c configs/sr/sr_tsrn_transformer_strock.yml -o Global.pretrained_model={path/to/weights}/best_accuracy
|
||||
```
|
||||
|
||||
### 预测
|
||||
|
||||
```bash linenums="1"
|
||||
# 预测使用的配置文件必须与训练一致
|
||||
python3 tools/infer_sr.py -c configs/sr/sr_tsrn_transformer_strock.yml -o Global.pretrained_model={path/to/weights}/best_accuracy Global.infer_img=doc/imgs_words_en/word_52.png
|
||||
```
|
||||
|
||||

|
||||
|
||||
执行命令后,上面图像的超分结果如下:
|
||||
|
||||

|
||||
|
||||
## 4. 推理部署
|
||||
|
||||
### 4.1 Python推理
|
||||
|
||||
首先将文本超分训练过程中保存的模型,转换成inference model。以 Text-Gestalt 训练的[模型](https://paddleocr.bj.bcebos.com/sr_tsrn_transformer_strock_train.tar) 为例,可以使用如下命令进行转换:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/export_model.py -c configs/sr/sr_tsrn_transformer_strock.yml -o Global.pretrained_model={path/to/weights}/best_accuracy Global.save_inference_dir=./inference/sr_out
|
||||
```
|
||||
|
||||
Text-Gestalt 文本超分模型推理,可以执行如下命令:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_sr.py --sr_model_dir=./inference/sr_out --image_dir=doc/imgs_words_en/word_52.png --sr_image_shape=3,32,128
|
||||
```
|
||||
|
||||
执行命令后,图像的超分结果如下:
|
||||
|
||||

|
||||
|
||||
### 4.2 C++推理
|
||||
|
||||
暂未支持
|
||||
|
||||
### 4.3 Serving服务化部署
|
||||
|
||||
暂未支持
|
||||
|
||||
### 4.4 更多推理部署
|
||||
|
||||
暂未支持
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
## 引用
|
||||
|
||||
```bibtex
|
||||
@inproceedings{chen2022text,
|
||||
title={Text gestalt: Stroke-aware scene text image super-resolution},
|
||||
author={Chen, Jingye and Yu, Haiyang and Ma, Jianqi and Li, Bin and Xue, Xiangyang},
|
||||
booktitle={Proceedings of the AAAI Conference on Artificial Intelligence},
|
||||
volume={36},
|
||||
number={1},
|
||||
pages={285--293},
|
||||
year={2022}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,110 @@
|
||||
---
|
||||
comments: true
|
||||
---
|
||||
|
||||
# Text Gestalt
|
||||
|
||||
## 1. Introduction
|
||||
|
||||
Paper:
|
||||
> [Scene Text Telescope: Text-Focused Scene Image Super-Resolution](https://openaccess.thecvf.com/content/CVPR2021/papers/Chen_Scene_Text_Telescope_Text-Focused_Scene_Image_Super-Resolution_CVPR_2021_paper.pdf)
|
||||
> Chen, Jingye, Bin Li, and Xiangyang Xue
|
||||
> CVPR, 2021
|
||||
|
||||
Referring to the [FudanOCR](https://github.com/FudanVI/FudanOCR/tree/main/scene-text-telescope) data download instructions, the effect of the super-score algorithm on the TextZoom test set is as follows:
|
||||
|
||||
|Model|Backbone|config|Acc|Download link|
|
||||
|---|---|---|---|---|
|
||||
|Text Gestalt|tsrn|21.56|0.7411| [configs/sr/sr_telescope.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/sr/sr_telescope.yml)|[train model](https://paddleocr.bj.bcebos.com/contribution/sr_telescope_train.tar)|
|
||||
|
||||
The [TextZoom dataset](https://paddleocr.bj.bcebos.com/dataset/TextZoom.tar) comes from two superfraction data sets, RealSR and SR-RAW, both of which contain LR-HR pairs. TextZoom has 17367 pairs of training data and 4373 pairs of test data.
|
||||
|
||||
## 2. Environment
|
||||
|
||||
Please refer to ["Environment Preparation"](../../ppocr/environment.en.md) to configure the PaddleOCR environment, and refer to ["Project Clone"](../../ppocr/blog/clone.en.md)to clone the project code.
|
||||
|
||||
## 3. Model Training / Evaluation / Prediction
|
||||
|
||||
Please refer to [Text Recognition Tutorial](../../ppocr/model_train/recognition.en.md). PaddleOCR modularizes the code, and training different models only requires **changing the configuration file**.
|
||||
|
||||
### Training
|
||||
|
||||
Specifically, after the data preparation is completed, the training can be started. The training command is as follows:
|
||||
|
||||
```bash linenums="1"
|
||||
# Single GPU training (long training period, not recommended)
|
||||
python3 tools/train.py -c configs/sr/sr_telescope.yml
|
||||
|
||||
# Multi GPU training, specify the gpu number through the --gpus parameter
|
||||
python3 -m paddle.distributed.launch --gpus '0,1,2,3' tools/train.py -c configs/sr/sr_telescope.yml
|
||||
```
|
||||
|
||||
### Evaluation
|
||||
|
||||
```bash linenums="1"
|
||||
# GPU evaluation
|
||||
python3 -m paddle.distributed.launch --gpus '0' tools/eval.py -c configs/sr/sr_telescope.yml -o Global.pretrained_model={path/to/weights}/best_accuracy
|
||||
```
|
||||
|
||||
### Prediction
|
||||
|
||||
```bash linenums="1"
|
||||
# The configuration file used for prediction must match the training
|
||||
|
||||
python3 tools/infer_sr.py -c configs/sr/sr_telescope.yml -o Global.pretrained_model={path/to/weights}/best_accuracy Global.infer_img=doc/imgs_words_en/word_52.png
|
||||
```
|
||||
|
||||

|
||||
|
||||
After executing the command, the super-resolution result of the above image is as follows:
|
||||
|
||||

|
||||
|
||||
## 4. Inference and Deployment
|
||||
|
||||
### 4.1 Python Inference
|
||||
|
||||
First, the model saved during the training process is converted into an inference model. ( [Model download link](https://paddleocr.bj.bcebos.com/contribution/Telescope_train.tar.gz) ), you can use the following command to convert:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/export_model.py -c configs/sr/sr_telescope.yml -o Global.pretrained_model={path/to/weights}/best_accuracy Global.save_inference_dir=./inference/sr_out
|
||||
```
|
||||
|
||||
For Text-Telescope super-resolution model inference, the following commands can be executed:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_sr.py --sr_model_dir=./inference/sr_out --image_dir=doc/imgs_words_en/word_52.png --sr_image_shape=3,32,128
|
||||
|
||||
```
|
||||
|
||||
After executing the command, the super-resolution result of the above image is as follows:
|
||||
|
||||

|
||||
|
||||
### 4.2 C++ Inference
|
||||
|
||||
Not supported
|
||||
|
||||
### 4.3 Serving
|
||||
|
||||
Not supported
|
||||
|
||||
### 4.4 More
|
||||
|
||||
Not supported
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
## Citation
|
||||
|
||||
```bibtex
|
||||
@INPROCEEDINGS{9578891,
|
||||
author={Chen, Jingye and Li, Bin and Xue, Xiangyang},
|
||||
booktitle={2021 IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
|
||||
title={Scene Text Telescope: Text-Focused Scene Image Super-Resolution},
|
||||
year={2021},
|
||||
volume={},
|
||||
number={},
|
||||
pages={12021-12030},
|
||||
doi={10.1109/CVPR46437.2021.01185}}
|
||||
```
|
||||
@@ -0,0 +1,109 @@
|
||||
---
|
||||
typora-copy-images-to: images
|
||||
comments: true
|
||||
---
|
||||
|
||||
# Text Telescope
|
||||
|
||||
## 1. 算法简介
|
||||
|
||||
论文信息:
|
||||
> [Scene Text Telescope: Text-Focused Scene Image Super-Resolution](https://openaccess.thecvf.com/content/CVPR2021/papers/Chen_Scene_Text_Telescope_Text-Focused_Scene_Image_Super-Resolution_CVPR_2021_paper.pdf)
|
||||
> Chen, Jingye, Bin Li, and Xiangyang Xue
|
||||
> CVPR, 2021
|
||||
|
||||
参考[FudanOCR](https://github.com/FudanVI/FudanOCR/tree/main/scene-text-telescope) 数据下载说明,在TextZoom测试集合上超分算法效果如下:
|
||||
|
||||
|模型|骨干网络|PSNR_Avg|SSIM_Avg|配置文件|下载链接|
|
||||
|---|---|---|---|---|---|
|
||||
|Text Telescope|tbsrn|21.56|0.7411| [configs/sr/sr_telescope.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/sr/sr_telescope.yml)|[训练模型](https://paddleocr.bj.bcebos.com/contribution/sr_telescope_train.tar)|
|
||||
|
||||
[TextZoom数据集](https://paddleocr.bj.bcebos.com/dataset/TextZoom.tar) 来自两个超分数据集RealSR和SR-RAW,两个数据集都包含LR-HR对,TextZoom有17367对训数据和4373对测试数据。
|
||||
|
||||
## 2. 环境配置
|
||||
|
||||
请先参考[《运行环境准备》](../../ppocr/environment.md)配置PaddleOCR运行环境,参考[《项目克隆》](../../ppocr/blog/clone.md)克隆项目代码。
|
||||
|
||||
## 3. 模型训练、评估、预测
|
||||
|
||||
请参考[文本识别训练教程](../../ppocr/model_train/recognition.md)。PaddleOCR对代码进行了模块化,训练不同的识别模型只需要**更换配置文件**即可。
|
||||
|
||||
### 训练
|
||||
|
||||
在完成数据准备后,便可以启动训练,训练命令如下:
|
||||
|
||||
```bash linenums="1"
|
||||
#单卡训练(训练周期长,不建议)
|
||||
python3 tools/train.py -c configs/sr/sr_telescope.yml
|
||||
|
||||
# 多卡训练,通过--gpus参数指定卡号
|
||||
python3 -m paddle.distributed.launch --gpus '0,1,2,3' tools/train.py -c configs/sr/sr_telescope.yml
|
||||
```
|
||||
|
||||
### 评估
|
||||
|
||||
```bash linenums="1"
|
||||
# GPU 评估, Global.pretrained_model 为待测权重
|
||||
python3 -m paddle.distributed.launch --gpus '0' tools/eval.py -c configs/sr/sr_telescope.yml -o Global.pretrained_model={path/to/weights}/best_accuracy
|
||||
```
|
||||
|
||||
### 预测
|
||||
|
||||
```bash linenums="1"
|
||||
# 预测使用的配置文件必须与训练一致
|
||||
python3 tools/infer_sr.py -c configs/sr/sr_telescope.yml -o Global.pretrained_model={path/to/weights}/best_accuracy Global.infer_img=doc/imgs_words_en/word_52.png
|
||||
```
|
||||
|
||||

|
||||
|
||||
执行命令后,上面图像的超分结果如下:
|
||||
|
||||

|
||||
|
||||
## 4. 推理部署
|
||||
|
||||
### 4.1 Python推理
|
||||
|
||||
首先将文本超分训练过程中保存的模型,转换成inference model。以 Text-Telescope 训练的[模型](https://paddleocr.bj.bcebos.com/contribution/Telescope_train.tar.gz) 为例,可以使用如下命令进行转换:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/export_model.py -c configs/sr/sr_telescope.yml -o Global.pretrained_model={path/to/weights}/best_accuracy Global.save_inference_dir=./inference/sr_out
|
||||
```
|
||||
|
||||
Text-Telescope 文本超分模型推理,可以执行如下命令:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_sr.py --sr_model_dir=./inference/sr_out --image_dir=doc/imgs_words_en/word_52.png --sr_image_shape=3,32,128
|
||||
```
|
||||
|
||||
执行命令后,图像的超分结果如下:
|
||||
|
||||

|
||||
|
||||
### 4.2 C++推理
|
||||
|
||||
暂未支持
|
||||
|
||||
### 4.3 Serving服务化部署
|
||||
|
||||
暂未支持
|
||||
|
||||
### 4.4 更多推理部署
|
||||
|
||||
暂未支持
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
## 引用
|
||||
|
||||
```bibtex
|
||||
@INPROCEEDINGS{9578891,
|
||||
author={Chen, Jingye and Li, Bin and Xue, Xiangyang},
|
||||
booktitle={2021 IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
|
||||
title={Scene Text Telescope: Text-Focused Scene Image Super-Resolution},
|
||||
year={2021},
|
||||
volume={},
|
||||
number={},
|
||||
pages={12021-12030},
|
||||
doi={10.1109/CVPR46437.2021.01185}}
|
||||
```
|
||||
|
After Width: | Height: | Size: 8.2 KiB |
|
After Width: | Height: | Size: 8.2 KiB |
|
After Width: | Height: | Size: 8.2 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 16 KiB |
@@ -0,0 +1,93 @@
|
||||
---
|
||||
typora-copy-images-to: images
|
||||
comments: true
|
||||
---
|
||||
|
||||
|
||||
# Table Recognition Algorithm-TableMASTER
|
||||
|
||||
## 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](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/table/table_master.yml)|77.47%|[trained 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)|
|
||||
|
||||
## 2. Environment
|
||||
|
||||
Please refer to ["Environment Preparation"](../../ppocr/environment.en.md) to configure the PaddleOCR environment, and refer to ["Project Clone"](../../ppocr/blog/clone.en.md)to clone the project code.
|
||||
|
||||
## 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](../../../datasets/table_datasets.en.md).
|
||||
|
||||
After the data download is complete, please refer to [Text Recognition Training Tutorial](../../ppocr/model_train/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.
|
||||
|
||||
## 4. Inference and Deployment
|
||||
|
||||
### 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:
|
||||
|
||||
```bash linenums="1"
|
||||
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:
|
||||
|
||||
```bash linenums="1"
|
||||
cd ppstructure/
|
||||
# When predicting all images in a folder, you can modify image_dir to a folder, such as --image_dir='docs/table'.
|
||||
python3 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:
|
||||
|
||||
```bash linenums="1"
|
||||
[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.
|
||||
|
||||
### 4.2 C++ Inference
|
||||
|
||||
Since the post-processing is not written in CPP, the TableMaster does not support CPP inference.
|
||||
|
||||
### 4.3 Serving
|
||||
|
||||
Not supported
|
||||
|
||||
### 4.4 More
|
||||
|
||||
Not supported
|
||||
|
||||
## 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}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,100 @@
|
||||
---
|
||||
typora-copy-images-to: images
|
||||
comments: true
|
||||
---
|
||||
|
||||
|
||||
# 表格识别算法-TableMASTER
|
||||
|
||||
## 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](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/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)|
|
||||
|
||||
## 2. 环境配置
|
||||
|
||||
请先参考[《运行环境准备》](../../ppocr/environment.md)配置PaddleOCR运行环境,参考[《项目克隆》](../../ppocr/blog/clone.md)克隆项目代码。
|
||||
|
||||
## 3. 模型训练、评估、预测
|
||||
|
||||
上述TableMaster模型使用PubTabNet表格识别公开数据集训练得到,数据集下载可参考 [table_datasets](../../../datasets/table_datasets.md)。
|
||||
|
||||
数据下载完成后,请参考[文本识别教程](../../ppocr/model_train/recognition.md)进行训练。PaddleOCR对代码进行了模块化,训练不同的模型只需要**更换配置文件**即可。
|
||||
|
||||
## 4. 推理部署
|
||||
|
||||
### 4.1 Python推理
|
||||
|
||||
首先将训练得到best模型,转换成inference model。以基于TableResNetExtra骨干网络,在PubTabNet数据集训练的模型为例([模型下载地址](https://paddleocr.bj.bcebos.com/contribution/table_master.tar)),可以使用如下命令进行转换:
|
||||
|
||||
```bash linenums="1"
|
||||
# 注意将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`是否为所正确的字典文件。
|
||||
|
||||
转换成功后,在目录下有三个文件:
|
||||
|
||||
```text linenums="1"
|
||||
./inference/table_master/
|
||||
├── inference.pdiparams # 识别inference模型的参数文件
|
||||
├── inference.pdiparams.info # 识别inference模型的参数信息,可忽略
|
||||
└── inference.pdmodel # 识别inference模型的program文件
|
||||
```
|
||||
|
||||
执行如下命令进行模型推理:
|
||||
|
||||
```bash linenums="1"
|
||||
cd ppstructure/
|
||||
python3 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'。
|
||||
```
|
||||
|
||||
执行命令后,上面图像的预测结果(结构信息和表格中每个单元格的坐标)会打印到屏幕上,同时会保存单元格坐标的可视化结果。示例如下:
|
||||
结果如下:
|
||||
|
||||
```bash linenums="1"
|
||||
[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进行使用。
|
||||
|
||||
### 4.2 C++推理部署
|
||||
|
||||
由于C++预处理后处理还未支持TableMaster,所以暂未支持
|
||||
|
||||
### 4.3 Serving服务化部署
|
||||
|
||||
暂不支持
|
||||
|
||||
### 4.4 更多推理部署
|
||||
|
||||
暂不支持
|
||||
|
||||
## 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}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,97 @@
|
||||
---
|
||||
comments: true
|
||||
---
|
||||
|
||||
# 表格识别算法-SLANet-LCNetV2
|
||||
|
||||
## 1. 算法简介
|
||||
|
||||
该算法由来自北京交通大学机器学习与认识计算研究团队的ocr识别队研发,其在PaddleOCR算法模型挑战赛 - 赛题二:通用表格识别任务中排行榜荣获一等奖,排行榜精度相比PP-Structure表格识别模型提升0.8%,推理速度提升3倍。优化思路如下:
|
||||
|
||||
1. 改善推理过程,至EOS停止,速度提升3倍;
|
||||
2. 升级Backbone为LCNetV2(SSLD版本);
|
||||
3. 行列特征增强模块;
|
||||
4. 提升分辨率488至512;
|
||||
5. 三阶段训练策略。
|
||||
|
||||
在PubTabNet表格识别公开数据集上,算法复现效果如下:
|
||||
|
||||
|模型|骨干网络|配置文件|acc|下载链接|
|
||||
| --- | --- | --- | --- | --- |
|
||||
|SLANet|LCNetV2|[configs/table/SLANet_lcnetv2.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/table/SLANet_lcnetv2.yml)|76.67%| [训练模型](https://paddleocr.bj.bcebos.com/openatom/ch_ppstructure_openatom_SLANetv2_train.tar) /[推理模型](https://paddleocr.bj.bcebos.com/openatom/ch_ppstructure_openatom_SLANetv2_infer.tar) |
|
||||
|
||||
## 2. 环境配置
|
||||
|
||||
请先参考[《运行环境准备》](../../ppocr/environment.md)配置PaddleOCR运行环境,参考[《项目克隆》](../../ppocr/blog/clone.md)克隆项目代码。
|
||||
|
||||
## 3. 模型训练、评估、预测
|
||||
|
||||
上述SLANet_LCNetv2模型使用PubTabNet表格识别公开数据集训练得到,数据集下载可参考 [table_datasets](../../../datasets/table_datasets.md)。
|
||||
|
||||
### 启动训练
|
||||
|
||||
数据下载完成后,请参考[文本识别教程](../../ppocr/model_train/recognition.md)进行训练。PaddleOCR对代码进行了模块化,训练不同的模型只需要**更换配置文件**即可。
|
||||
|
||||
训练命令如下:
|
||||
|
||||
```bash linenums="1"
|
||||
# stage1
|
||||
python3 -m paddle.distributed.launch --gpus '0,1,2,3,4,5,6,7' tools/train.py -c configs/table/SLANet_lcnetv2.yml
|
||||
# stage2 加载stage1的best model作为预训练模型,学习率调整为0.0001;
|
||||
# stage3 加载stage2的best model作为预训练模型,不调整学习率,将配置文件中所有的488修改为512.
|
||||
```
|
||||
|
||||
## 4. 推理部署
|
||||
|
||||
### 4.1 Python推理
|
||||
|
||||
将训练得到best模型,转换成inference model,可以使用如下命令进行转换:
|
||||
|
||||
```bash linenums="1"
|
||||
# 注意将pretrained_model的路径设置为本地路径。
|
||||
python3 tools/export_model.py -c configs/table/SLANet_lcnetv2.yml -o Global.pretrained_model=path/best_accuracy Global.save_inference_dir=./inference/slanet_lcnetv2_infer
|
||||
```
|
||||
|
||||
**注意:** 如果您是在自己的数据集上训练的模型,并且调整了字典文件,请注意修改配置文件中的`character_dict_path`是否为所正确的字典文件。
|
||||
|
||||
转换成功后,在目录下有三个文件:
|
||||
|
||||
```text linenums="1"
|
||||
./inference/slanet_lcnetv2_infer/
|
||||
├── inference.pdiparams # 识别inference模型的参数文件
|
||||
├── inference.pdiparams.info # 识别inference模型的参数信息,可忽略
|
||||
└── inference.pdmodel # 识别inference模型的program文件
|
||||
```
|
||||
|
||||
执行如下命令进行模型推理:
|
||||
|
||||
```bash linenums="1"
|
||||
cd ppstructure/
|
||||
python table/predict_structure.py --table_model_dir=../inference/slanet_lcnetv2_infer/ --table_char_dict_path=../ppocr/utils/dict/table_structure_dict.txt --image_dir=docs/table/table.jpg --output=../output/table_slanet_lcnetv2 --use_gpu=False --benchmark=True --enable_mkldnn=True --table_max_len=512
|
||||
# 预测文件夹下所有图像时,可修改image_dir为文件夹,如 --image_dir='docs/table'。
|
||||
```
|
||||
|
||||
执行命令后,上面图像的预测结果(结构信息和表格中每个单元格的坐标)会打印到屏幕上,同时会保存单元格坐标的可视化结果。示例如下:
|
||||
结果如下:
|
||||
|
||||
```bash linenums="1"
|
||||
[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
|
||||
```
|
||||
|
||||
### 4.2 C++推理部署
|
||||
|
||||
由于C++预处理后处理还未支持SLANet
|
||||
|
||||
### 4.3 Serving服务化部署
|
||||
|
||||
暂不支持
|
||||
|
||||
### 4.4 更多推理部署
|
||||
|
||||
暂不支持
|
||||
|
||||
## 5. FAQ
|
||||
@@ -0,0 +1,74 @@
|
||||
---
|
||||
typora-copy-images-to: images
|
||||
comments: true
|
||||
---
|
||||
|
||||
# CT
|
||||
|
||||
## 1. Introduction
|
||||
|
||||
Paper:
|
||||
> [CentripetalText: An Efficient Text Instance Representation for Scene Text Detection](https://arxiv.org/abs/2107.05945)
|
||||
> Tao Sheng, Jie Chen, Zhouhui Lian
|
||||
> NeurIPS, 2021
|
||||
|
||||
On the Total-Text dataset, the text detection result is as follows:
|
||||
|
||||
|Model|Backbone|Configuration|Precision|Recall|Hmean|Download|
|
||||
| --- | --- | --- | --- | --- | --- | --- |
|
||||
|CT|ResNet18_vd|[configs/det/det_r18_vd_ct.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/det/det_r18_vd_ct.yml)|88.68%|81.70%|85.05%|[trained model](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/det_r18_ct_train.tar)|
|
||||
|
||||
## 2. Environment
|
||||
|
||||
Please prepare your environment referring to [prepare the environment](../../ppocr/environment.en.md) and [clone the repo](../../ppocr/blog/clone.en.md).
|
||||
|
||||
## 3. Model Training / Evaluation / Prediction
|
||||
|
||||
The above CT model is trained using the Total-Text text detection public dataset. For the download of the dataset, please refer to [Total-Text-Dataset](https://github.com/cs-chan/Total-Text-Dataset/tree/master/Dataset). PaddleOCR format annotation download link [train.txt](https://paddleocr.bj.bcebos.com/dataset/ct_tipc/train.txt), [test.txt](https://paddleocr.bj.bcebos.com/dataset/ct_tipc/test.txt).
|
||||
|
||||
Please refer to [text detection training tutorial](../../ppocr/model_train/detection.en.md). PaddleOCR has modularized the code structure, so that you only need to **replace the configuration file** to train different detection models.
|
||||
|
||||
## 4. Inference and Deployment
|
||||
|
||||
### 4.1 Python Inference
|
||||
|
||||
First, convert the model saved in the CT text detection training process into an inference model. Taking the model based on the Resnet18_vd backbone network and trained on the Total Text English dataset as example ([model download link](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/det_r18_ct_train.tar)), you can use the following command to convert:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/export_model.py -c configs/det/det_r18_vd_ct.yml -o Global.pretrained_model=./det_r18_ct_train/best_accuracy Global.save_inference_dir=./inference/det_ct
|
||||
```
|
||||
|
||||
CT text detection model inference, you can execute the following command:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_det.py --image_dir="./doc/imgs_en/img623.jpg" --det_model_dir="./inference/det_ct/" --det_algorithm="CT"
|
||||
```
|
||||
|
||||
The visualized text detection results are saved to the `./inference_results` folder by default, and the name of the result file is prefixed with `det_res`. Examples of results are as follows:
|
||||
|
||||

|
||||
|
||||
### 4.2 C++ Inference
|
||||
|
||||
Not supported
|
||||
|
||||
### 4.3 Serving
|
||||
|
||||
Not supported
|
||||
|
||||
### 4.4 More
|
||||
|
||||
Not supported
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
## Citation
|
||||
|
||||
```bibtex
|
||||
@inproceedings{sheng2021centripetaltext,
|
||||
title={CentripetalText: An Efficient Text Instance Representation for Scene Text Detection},
|
||||
author={Tao Sheng and Jie Chen and Zhouhui Lian},
|
||||
booktitle={Thirty-Fifth Conference on Neural Information Processing Systems},
|
||||
year={2021}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,74 @@
|
||||
---
|
||||
typora-copy-images-to: images
|
||||
comments: true
|
||||
---
|
||||
|
||||
# CT
|
||||
|
||||
## 1. 算法简介
|
||||
|
||||
论文信息:
|
||||
> [CentripetalText: An Efficient Text Instance Representation for Scene Text Detection](https://arxiv.org/abs/2107.05945)
|
||||
> Tao Sheng, Jie Chen, Zhouhui Lian
|
||||
> NeurIPS, 2021
|
||||
|
||||
在Total-Text文本检测公开数据集上,算法复现效果如下:
|
||||
|
||||
|模型|骨干网络|配置文件|precision|recall|Hmean|下载链接|
|
||||
| --- | --- | --- | --- | --- | --- | --- |
|
||||
|CT|ResNet18_vd|[configs/det/det_r18_vd_ct.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/det/det_r18_vd_ct.yml)|88.68%|81.70%|85.05%|[训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/det_r18_ct_train.tar)|
|
||||
|
||||
## 2. 环境配置
|
||||
|
||||
请先参考[《运行环境准备》](../../ppocr/environment.md)配置PaddleOCR运行环境,参考[《项目克隆》](../../ppocr/blog/clone.md)克隆项目代码。
|
||||
|
||||
## 3. 模型训练、评估、预测
|
||||
|
||||
CT模型使用Total-Text文本检测公开数据集训练得到,数据集下载可参考 [Total-Text-Dataset](https://github.com/cs-chan/Total-Text-Dataset/tree/master/Dataset), 我们将标签文件转成了paddleocr格式,转换好的标签文件下载参考[train.txt](https://paddleocr.bj.bcebos.com/dataset/ct_tipc/train.txt), [text.txt](https://paddleocr.bj.bcebos.com/dataset/ct_tipc/test.txt)。
|
||||
|
||||
请参考[文本检测训练教程](../../ppocr/model_train/detection.md)。PaddleOCR对代码进行了模块化,训练不同的检测模型只需要**更换配置文件**即可。
|
||||
|
||||
## 4. 推理部署
|
||||
|
||||
### 4.1 Python推理
|
||||
|
||||
首先将CT文本检测训练过程中保存的模型,转换成inference model。以基于Resnet18_vd骨干网络,在Total-Text英文数据集训练的模型为例( [模型下载地址](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/det_r18_ct_train.tar) ),可以使用如下命令进行转换:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/export_model.py -c configs/det/det_r18_vd_ct.yml -o Global.pretrained_model=./det_r18_ct_train/best_accuracy Global.save_inference_dir=./inference/det_ct
|
||||
```
|
||||
|
||||
CT文本检测模型推理,可以执行如下命令:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_det.py --image_dir="./doc/imgs_en/img623.jpg" --det_model_dir="./inference/det_ct/" --det_algorithm="CT"
|
||||
```
|
||||
|
||||
可视化文本检测结果默认保存到`./inference_results`文件夹里面,结果文件的名称前缀为`det_res`。结果示例如下:
|
||||
|
||||

|
||||
|
||||
### 4.2 C++推理
|
||||
|
||||
暂不支持
|
||||
|
||||
### 4.3 Serving服务化部署
|
||||
|
||||
暂不支持
|
||||
|
||||
### 4.4 更多推理部署
|
||||
|
||||
暂不支持
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
## 引用
|
||||
|
||||
```bibtex
|
||||
@inproceedings{sheng2021centripetaltext,
|
||||
title={CentripetalText: An Efficient Text Instance Representation for Scene Text Detection},
|
||||
author={Tao Sheng and Jie Chen and Zhouhui Lian},
|
||||
booktitle={Thirty-Fifth Conference on Neural Information Processing Systems},
|
||||
year={2021}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,98 @@
|
||||
---
|
||||
comments: true
|
||||
---
|
||||
|
||||
# DB && DB++
|
||||
|
||||
## 1. Introduction
|
||||
|
||||
Paper:
|
||||
> [Real-time Scene Text Detection with Differentiable Binarization](https://arxiv.org/abs/1911.08947)
|
||||
> Liao, Minghui and Wan, Zhaoyi and Yao, Cong and Chen, Kai and Bai, Xiang
|
||||
> AAAI, 2020
|
||||
|
||||
> [Real-Time Scene Text Detection with Differentiable Binarization and Adaptive Scale Fusion](https://arxiv.org/abs/2202.10304)
|
||||
> Liao, Minghui and Zou, Zhisheng and Wan, Zhaoyi and Yao, Cong and Bai, Xiang
|
||||
> TPAMI, 2022
|
||||
|
||||
On the ICDAR2015 dataset, the text detection result is as follows:
|
||||
|
||||
|Model|Backbone|Configuration|Precision|Recall|Hmean|Download|
|
||||
| --- | --- | --- | --- | --- | --- | --- |
|
||||
|DB|ResNet50_vd|[configs/det/det_r50_vd_db.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/det/det_r50_vd_db.yml)|86.41%|78.72%|82.38%|[trained model](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/det_r50_vd_db_v2.0_train.tar)|
|
||||
|DB|MobileNetV3|[configs/det/det_mv3_db.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/det/det_mv3_db.yml)|77.29%|73.08%|75.12%|[trained model](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/det_mv3_db_v2.0_train.tar)|
|
||||
|DB++|ResNet50|[configs/det/det_r50_db++_icdar15.yml](https://github.com/PaddlePaddle/PaddleOCR/blob/{{PADDLEOCR_GITHUB_REF}}/configs/det/det_r50_db++_icdar15.yml)|90.89%|82.66%|86.58%|[pretrained model](https://paddleocr.bj.bcebos.com/dygraph_v2.1/en_det/ResNet50_dcn_asf_synthtext_pretrained.pdparams)/[trained model](https://paddleocr.bj.bcebos.com/dygraph_v2.1/en_det/det_r50_db%2B%2B_icdar15_train.tar)|
|
||||
|
||||
On the TD_TR dataset, the text detection result is as follows:
|
||||
|
||||
|Model|Backbone|Configuration|Precision|Recall|Hmean|Download|
|
||||
| --- | --- | --- | --- | --- | --- | --- |
|
||||
|DB++|ResNet50|[configs/det/det_r50_db++_td_tr.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/det/det_r50_db++_td_tr.yml)|92.92%|86.48%|89.58%|[pretrained model](https://paddleocr.bj.bcebos.com/dygraph_v2.1/en_det/ResNet50_dcn_asf_synthtext_pretrained.pdparams)/[trained model](https://paddleocr.bj.bcebos.com/dygraph_v2.1/en_det/det_r50_db%2B%2B_td_tr_train.tar)|
|
||||
|
||||
## 2. Environment
|
||||
|
||||
Please prepare your environment referring to [prepare the environment](../../ppocr/environment.en.md) and [clone the repo](../../ppocr/blog/clone.en.md).
|
||||
|
||||
## 3. Model Training / Evaluation / Prediction
|
||||
|
||||
Please refer to [text detection training tutorial](../../ppocr/model_train/detection.en.md). PaddleOCR has modularized the code structure, so that you only need to **replace the configuration file** to train different detection models.
|
||||
|
||||
## 4. Inference and Deployment
|
||||
|
||||
### 4.1 Python Inference
|
||||
|
||||
First, convert the model saved in the DB text detection training process into an inference model. Taking the model based on the Resnet50_vd backbone network and trained on the ICDAR2015 English dataset as example ([model download link](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/det_r50_vd_db_v2.0_train.tar)), you can use the following command to convert:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/export_model.py -c configs/det/det_r50_vd_db.yml -o Global.pretrained_model=./det_r50_vd_db_v2.0_train/best_accuracy Global.save_inference_dir=./inference/det_db
|
||||
```
|
||||
|
||||
DB text detection model inference, you can execute the following command:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_det.py --image_dir="./doc/imgs_en/img_10.jpg" --det_model_dir="./inference/det_db/"
|
||||
```
|
||||
|
||||
The visualized text detection results are saved to the `./inference_results` folder by default, and the name of the result file is prefixed with `det_res`. Examples of results are as follows:
|
||||
|
||||

|
||||
|
||||
**Note**: Since the ICDAR2015 dataset has only 1,000 training images, mainly for English scenes, the above model has very poor detection result on Chinese text images.
|
||||
|
||||
### 4.2 C++ Inference
|
||||
|
||||
With the inference model prepared, refer to the [cpp infer](../../../version2.x/legacy/cpp_infer.en.md) tutorial for C++ inference.
|
||||
|
||||
### 4.3 Serving
|
||||
|
||||
With the inference model prepared, refer to the [pdserving](../../../version2.x/legacy/paddle_server.en.md) tutorial for service deployment by Paddle Serving.
|
||||
|
||||
### 4.4 More
|
||||
|
||||
More deployment schemes supported for DB:
|
||||
|
||||
- Paddle2ONNX: with the inference model prepared, please refer to the [paddle2onnx](../../../version2.x/legacy/paddle2onnx.en.md) tutorial.
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
## Citation
|
||||
|
||||
```bibtex
|
||||
@inproceedings{liao2020real,
|
||||
title={Real-time scene text detection with differentiable binarization},
|
||||
author={Liao, Minghui and Wan, Zhaoyi and Yao, Cong and Chen, Kai and Bai, Xiang},
|
||||
booktitle={Proceedings of the AAAI Conference on Artificial Intelligence},
|
||||
volume={34},
|
||||
number={07},
|
||||
pages={11474--11481},
|
||||
year={2020}
|
||||
}
|
||||
|
||||
@article{liao2022real,
|
||||
title={Real-Time Scene Text Detection with Differentiable Binarization and Adaptive Scale Fusion},
|
||||
author={Liao, Minghui and Zou, Zhisheng and Wan, Zhaoyi and Yao, Cong and Bai, Xiang},
|
||||
journal={IEEE Transactions on Pattern Analysis and Machine Intelligence},
|
||||
year={2022},
|
||||
publisher={IEEE}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,99 @@
|
||||
---
|
||||
typora-copy-images-to: images
|
||||
comments: true
|
||||
---
|
||||
|
||||
# DB与DB++
|
||||
|
||||
## 1. 算法简介
|
||||
|
||||
论文信息:
|
||||
> [Real-time Scene Text Detection with Differentiable Binarization](https://arxiv.org/abs/1911.08947)
|
||||
> Liao, Minghui and Wan, Zhaoyi and Yao, Cong and Chen, Kai and Bai, Xiang
|
||||
> AAAI, 2020
|
||||
|
||||
> [Real-Time Scene Text Detection with Differentiable Binarization and Adaptive Scale Fusion](https://arxiv.org/abs/2202.10304)
|
||||
> Liao, Minghui and Zou, Zhisheng and Wan, Zhaoyi and Yao, Cong and Bai, Xiang
|
||||
> TPAMI, 2022
|
||||
|
||||
在ICDAR2015文本检测公开数据集上,算法复现效果如下:
|
||||
|
||||
|模型|骨干网络|配置文件|precision|recall|Hmean|下载链接|
|
||||
| --- | --- | --- | --- | --- | --- | --- |
|
||||
|DB|ResNet50_vd|[configs/det/det_r50_vd_db.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/det/det_r50_vd_db.yml)|86.41%|78.72%|82.38%|[训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/det_r50_vd_db_v2.0_train.tar)|
|
||||
|DB|MobileNetV3|[configs/det/det_mv3_db.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/det/det_mv3_db.yml)|77.29%|73.08%|75.12%|[训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/det_mv3_db_v2.0_train.tar)|
|
||||
|DB++|ResNet50|[configs/det/det_r50_db++_icdar15.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/det/det_r50_db++_icdar15.yml)|90.89%|82.66%|86.58%|[合成数据预训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.1/en_det/ResNet50_dcn_asf_synthtext_pretrained.pdparams)/[训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.1/en_det/det_r50_db%2B%2B_icdar15_train.tar)|
|
||||
|
||||
在TD_TR文本检测公开数据集上,算法复现效果如下:
|
||||
|
||||
|模型|骨干网络|配置文件|precision|recall|Hmean|下载链接|
|
||||
| --- | --- | --- | --- | --- | --- | --- |
|
||||
|DB++|ResNet50|[configs/det/det_r50_db++_td_tr.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/det/det_r50_db++_td_tr.yml)|92.92%|86.48%|89.58%|[合成数据预训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.1/en_det/ResNet50_dcn_asf_synthtext_pretrained.pdparams)/[训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.1/en_det/det_r50_db%2B%2B_td_tr_train.tar)|
|
||||
|
||||
## 2. 环境配置
|
||||
|
||||
请先参考[《运行环境准备》](../../ppocr/environment.md)配置PaddleOCR运行环境,参考[《项目克隆》](../../ppocr/blog/clone.md)克隆项目代码。
|
||||
|
||||
## 3. 模型训练、评估、预测
|
||||
|
||||
请参考[文本检测训练教程](../../ppocr/model_train/detection.md)。PaddleOCR对代码进行了模块化,训练不同的检测模型只需要**更换配置文件**即可。
|
||||
|
||||
## 4. 推理部署
|
||||
|
||||
### 4.1 Python推理
|
||||
|
||||
首先将DB文本检测训练过程中保存的模型,转换成inference model。以基于Resnet50_vd骨干网络,在ICDAR2015英文数据集训练的模型为例( [模型下载地址](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/det_r50_vd_db_v2.0_train.tar) ),可以使用如下命令进行转换:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/export_model.py -c configs/det/det_r50_vd_db.yml -o Global.pretrained_model=./det_r50_vd_db_v2.0_train/best_accuracy Global.save_inference_dir=./inference/det_db
|
||||
```
|
||||
|
||||
DB文本检测模型推理,可以执行如下命令:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_det.py --image_dir="./doc/imgs_en/img_10.jpg" --det_model_dir="./inference/det_db/" --det_algorithm="DB"
|
||||
```
|
||||
|
||||
可视化文本检测结果默认保存到`./inference_results`文件夹里面,结果文件的名称前缀为`det_res`。结果示例如下:
|
||||
|
||||

|
||||
|
||||
**注意**:由于ICDAR2015数据集只有1000张训练图像,且主要针对英文场景,所以上述模型对中文文本图像检测效果会比较差。
|
||||
|
||||
### 4.2 C++推理
|
||||
|
||||
准备好推理模型后,参考[cpp infer](../../../version2.x/legacy/cpp_infer.md)教程进行操作即可。
|
||||
|
||||
### 4.3 Serving服务化部署
|
||||
|
||||
准备好推理模型后,参考[pdserving](../../../version2.x/legacy/paddle_server.md)教程进行Serving服务化部署,包括Python Serving和C++ Serving两种模式。
|
||||
|
||||
### 4.4 更多推理部署
|
||||
|
||||
DB模型还支持以下推理部署方式:
|
||||
|
||||
- Paddle2ONNX推理:准备好推理模型后,参考[paddle2onnx](../../../version2.x/legacy/paddle2onnx.md)教程操作。
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
## 引用
|
||||
|
||||
```bibtex
|
||||
@inproceedings{liao2020real,
|
||||
title={Real-time scene text detection with differentiable binarization},
|
||||
author={Liao, Minghui and Wan, Zhaoyi and Yao, Cong and Chen, Kai and Bai, Xiang},
|
||||
booktitle={Proceedings of the AAAI Conference on Artificial Intelligence},
|
||||
volume={34},
|
||||
number={07},
|
||||
pages={11474--11481},
|
||||
year={2020}
|
||||
}
|
||||
|
||||
@article{liao2022real,
|
||||
title={Real-Time Scene Text Detection with Differentiable Binarization and Adaptive Scale Fusion},
|
||||
author={Liao, Minghui and Zou, Zhisheng and Wan, Zhaoyi and Yao, Cong and Bai, Xiang},
|
||||
journal={IEEE Transactions on Pattern Analysis and Machine Intelligence},
|
||||
year={2022},
|
||||
publisher={IEEE}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,61 @@
|
||||
---
|
||||
typora-copy-images-to: images
|
||||
comments: true
|
||||
---
|
||||
|
||||
# DRRG
|
||||
|
||||
## 1. Introduction
|
||||
|
||||
Paper:
|
||||
> [Deep Relational Reasoning Graph Network for Arbitrary Shape Text Detection](https://arxiv.org/abs/2003.07493)
|
||||
> Zhang, Shi-Xue and Zhu, Xiaobin and Hou, Jie-Bo and Liu, Chang and Yang, Chun and Wang, Hongfa and Yin, Xu-Cheng
|
||||
> CVPR, 2020
|
||||
|
||||
On the CTW1500 dataset, the text detection result is as follows:
|
||||
|
||||
|Model|Backbone|Configuration|Precision|Recall|Hmean|Download|
|
||||
| --- | --- | --- | --- | --- | --- | --- |
|
||||
| DRRG | ResNet50_vd | [configs/det/det_r50_drrg_ctw.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/det/det_r50_drrg_ctw.yml)| 89.92%|80.91%|85.18%|[trained model](https://paddleocr.bj.bcebos.com/contribution/det_r50_drrg_ctw_train.tar)|
|
||||
|
||||
## 2. Environment
|
||||
|
||||
Please prepare your environment referring to [prepare the environment](../../ppocr/environment.en.md) and [clone the repo](../../ppocr/blog/clone.en.md).
|
||||
|
||||
## 3. Model Training / Evaluation / Prediction
|
||||
|
||||
The above DRRG model is trained using the CTW1500 text detection public dataset. For the download of the dataset, please refer to [ocr_datasets](../../../datasets/ocr_datasets.en.md).
|
||||
|
||||
After the data download is complete, please refer to [Text Detection Training Tutorial](../../ppocr/model_train/detection.en.md) for training. PaddleOCR has modularized the code structure, so that you only need to **replace the configuration file** to train different detection models.
|
||||
|
||||
## 4. Inference and Deployment
|
||||
|
||||
### 4.1 Python Inference
|
||||
|
||||
Since the model needs to be converted to Numpy data for many times in the forward, DRRG dynamic graph to static graph is not supported.
|
||||
|
||||
### 4.2 C++ Inference
|
||||
|
||||
Not supported
|
||||
|
||||
### 4.3 Serving
|
||||
|
||||
Not supported
|
||||
|
||||
### 4.4 More
|
||||
|
||||
Not supported
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
## Citation
|
||||
|
||||
```bibtex
|
||||
@inproceedings{zhang2020deep,
|
||||
title={Deep relational reasoning graph network for arbitrary shape text detection},
|
||||
author={Zhang, Shi-Xue and Zhu, Xiaobin and Hou, Jie-Bo and Liu, Chang and Yang, Chun and Wang, Hongfa and Yin, Xu-Cheng},
|
||||
booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},
|
||||
pages={9699--9708},
|
||||
year={2020}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,61 @@
|
||||
---
|
||||
typora-copy-images-to: images
|
||||
comments: true
|
||||
---
|
||||
|
||||
# DRRG
|
||||
|
||||
## 1. 算法简介
|
||||
|
||||
论文信息:
|
||||
> [Deep Relational Reasoning Graph Network for Arbitrary Shape Text Detection](https://arxiv.org/abs/2003.07493)
|
||||
> Zhang, Shi-Xue and Zhu, Xiaobin and Hou, Jie-Bo and Liu, Chang and Yang, Chun and Wang, Hongfa and Yin, Xu-Cheng
|
||||
> CVPR, 2020
|
||||
|
||||
在CTW1500文本检测公开数据集上,算法复现效果如下:
|
||||
|
||||
| 模型 |骨干网络|配置文件|precision|recall|Hmean|下载链接|
|
||||
|-----| --- | --- | --- | --- | --- | --- |
|
||||
| DRRG | ResNet50_vd | [configs/det/det_r50_drrg_ctw.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/det/det_r50_drrg_ctw.yml)| 89.92%|80.91%|85.18%|[训练模型](https://paddleocr.bj.bcebos.com/contribution/det_r50_drrg_ctw_train.tar)|
|
||||
|
||||
## 2. 环境配置
|
||||
|
||||
请先参考[《运行环境准备》](../../ppocr/environment.md)配置PaddleOCR运行环境,参考[《项目克隆》](../../ppocr/blog/clone.md)克隆项目代码。
|
||||
|
||||
## 3. 模型训练、评估、预测
|
||||
|
||||
上述DRRG模型使用CTW1500文本检测公开数据集训练得到,数据集下载可参考 [ocr_datasets](../../../datasets/ocr_datasets.md)。
|
||||
|
||||
数据下载完成后,请参考[文本检测训练教程](../../ppocr/model_train/detection.md)进行训练。PaddleOCR对代码进行了模块化,训练不同的检测模型只需要**更换配置文件**即可。
|
||||
|
||||
## 4. 推理部署
|
||||
|
||||
### 4.1 Python推理
|
||||
|
||||
由于模型前向运行时需要多次转换为Numpy数据进行运算,因此DRRG的动态图转静态图暂未支持。
|
||||
|
||||
### 4.2 C++推理
|
||||
|
||||
暂未支持
|
||||
|
||||
### 4.3 Serving服务化部署
|
||||
|
||||
暂未支持
|
||||
|
||||
### 4.4 更多推理部署
|
||||
|
||||
暂未支持
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
## 引用
|
||||
|
||||
```bibtex
|
||||
@inproceedings{zhang2020deep,
|
||||
title={Deep relational reasoning graph network for arbitrary shape text detection},
|
||||
author={Zhang, Shi-Xue and Zhu, Xiaobin and Hou, Jie-Bo and Liu, Chang and Yang, Chun and Wang, Hongfa and Yin, Xu-Cheng},
|
||||
booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},
|
||||
pages={9699--9708},
|
||||
year={2020}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,76 @@
|
||||
---
|
||||
typora-copy-images-to: images
|
||||
comments: true
|
||||
---
|
||||
|
||||
# EAST
|
||||
|
||||
## 1. Introduction
|
||||
|
||||
Paper:
|
||||
> [EAST: An Efficient and Accurate Scene Text Detector](https://arxiv.org/abs/1704.03155)
|
||||
> Xinyu Zhou, Cong Yao, He Wen, Yuzhi Wang, Shuchang Zhou, Weiran He, Jiajun Liang
|
||||
> CVPR, 2017
|
||||
|
||||
On the ICDAR2015 dataset, the text detection result is as follows:
|
||||
|
||||
|Model|Backbone|Configuration|Precision|Recall|Hmean|Download|
|
||||
| --- | --- | --- | --- | --- | --- | --- |
|
||||
|EAST|ResNet50_vd| [det_r50_vd_east.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/det/det_r50_vd_east.yml)|88.71%| 81.36%| 84.88%| [model](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/det_r50_vd_east_v2.0_train.tar)|
|
||||
|EAST|MobileNetV3|[det_mv3_east.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/det/det_mv3_east.yml) | 78.20%| 79.10%| 78.65%| [model](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/det_mv3_east_v2.0_train.tar)|
|
||||
|
||||
## 2. Environment
|
||||
|
||||
Please prepare your environment referring to [prepare the environment](../../ppocr/environment.en.md) and [clone the repo](../../ppocr/blog/clone.en.md).
|
||||
|
||||
## 3. Model Training / Evaluation / Prediction
|
||||
|
||||
The above EAST model is trained using the ICDAR2015 text detection public dataset. For the download of the dataset, please refer to [ocr_datasets](../../../datasets/ocr_datasets.en.md).
|
||||
|
||||
After the data download is complete, please refer to [Text Detection Training Tutorial](../../ppocr/model_train/detection.en.md) for training. PaddleOCR has modularized the code structure, so that you only need to **replace the configuration file** to train different detection models.
|
||||
|
||||
## 4. Inference and Deployment
|
||||
|
||||
### 4.1 Python Inference
|
||||
|
||||
First, convert the model saved in the EAST text detection training process into an inference model. Taking the model based on the Resnet50_vd backbone network and trained on the ICDAR2015 English dataset as example ([model download link](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/det_r50_vd_east_v2.0_train.tar)), you can use the following command to convert:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/export_model.py -c configs/det/det_r50_vd_east.yml -o Global.pretrained_model=./det_r50_vd_east_v2.0_train/best_accuracy Global.save_inference_dir=./inference/det_r50_east/
|
||||
```
|
||||
|
||||
For EAST text detection model inference, you need to set the parameter --det_algorithm="EAST", run the following command:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_det.py --image_dir="./doc/imgs_en/img_10.jpg" --det_model_dir="./inference/det_r50_east/" --det_algorithm="EAST"
|
||||
```
|
||||
|
||||
The visualized text detection results are saved to the `./inference_results` folder by default, and the name of the result file is prefixed with `det_res`.
|
||||
|
||||

|
||||
|
||||
### 4.2 C++ Inference
|
||||
|
||||
Since the post-processing is not written in CPP, the EAST text detection model does not support CPP inference.
|
||||
|
||||
### 4.3 Serving
|
||||
|
||||
Not supported
|
||||
|
||||
### 4.4 More
|
||||
|
||||
Not supported
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
## Citation
|
||||
|
||||
```bibtex
|
||||
@inproceedings{zhou2017east,
|
||||
title={East: an efficient and accurate scene text detector},
|
||||
author={Zhou, Xinyu and Yao, Cong and Wen, He and Wang, Yuzhi and Zhou, Shuchang and He, Weiran and Liang, Jiajun},
|
||||
booktitle={Proceedings of the IEEE conference on Computer Vision and Pattern Recognition},
|
||||
pages={5551--5560},
|
||||
year={2017}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,76 @@
|
||||
---
|
||||
typora-copy-images-to: images
|
||||
comments: true
|
||||
---
|
||||
|
||||
# EAST
|
||||
|
||||
## 1. 算法简介
|
||||
|
||||
论文信息:
|
||||
> [EAST: An Efficient and Accurate Scene Text Detector](https://arxiv.org/abs/1704.03155)
|
||||
> Xinyu Zhou, Cong Yao, He Wen, Yuzhi Wang, Shuchang Zhou, Weiran He, Jiajun Liang
|
||||
> CVPR, 2017
|
||||
|
||||
在ICDAR2015文本检测公开数据集上,算法复现效果如下:
|
||||
|
||||
|模型|骨干网络|配置文件|precision|recall|Hmean|下载链接|
|
||||
| --- | --- | --- | --- | --- | --- | --- |
|
||||
|EAST|ResNet50_vd| [det_r50_vd_east.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/det/det_r50_vd_east.yml)|88.71%| 81.36%| 84.88%| [训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/det_r50_vd_east_v2.0_train.tar)|
|
||||
|EAST|MobileNetV3|[det_mv3_east.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/det/det_mv3_east.yml) | 78.20%| 79.10%| 78.65%| [训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/det_mv3_east_v2.0_train.tar)|
|
||||
|
||||
## 2. 环境配置
|
||||
|
||||
请先参考[《运行环境准备》](../../ppocr/environment.md)配置PaddleOCR运行环境,参考[《项目克隆》](../../ppocr/blog/clone.md)克隆项目代码。
|
||||
|
||||
## 3. 模型训练、评估、预测
|
||||
|
||||
上表中的EAST训练模型使用ICDAR2015文本检测公开数据集训练得到,数据集下载可参考 [ocr_datasets](../../../datasets/ocr_datasets.md)。
|
||||
|
||||
数据下载完成后,请参考[文本检测训练教程](../../ppocr/model_train/detection.md)进行训练。PaddleOCR对代码进行了模块化,训练不同的检测模型只需要**更换配置文件**即可。
|
||||
|
||||
## 4. 推理部署
|
||||
|
||||
### 4.1 Python推理
|
||||
|
||||
首先将EAST文本检测训练过程中保存的模型,转换成inference model。以基于Resnet50_vd骨干网络,在ICDAR2015英文数据集训练的模型为例([训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/det_r50_vd_east_v2.0_train.tar)),可以使用如下命令进行转换:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/export_model.py -c configs/det/det_r50_vd_east.yml -o Global.pretrained_model=./det_r50_vd_east_v2.0_train/best_accuracy Global.save_inference_dir=./inference/det_r50_east/
|
||||
```
|
||||
|
||||
EAST文本检测模型推理,需要设置参数--det_algorithm="EAST",执行预测:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_det.py --image_dir="./doc/imgs_en/img_10.jpg" --det_model_dir="./inference/det_r50_east/" --det_algorithm="EAST"
|
||||
```
|
||||
|
||||
可视化文本检测结果默认保存到`./inference_results`文件夹里面,结果文件的名称前缀为`det_res`。
|
||||
|
||||

|
||||
|
||||
### 4.2 C++推理
|
||||
|
||||
由于后处理暂未使用CPP编写,EAST文本检测模型暂不支持CPP推理。
|
||||
|
||||
### 4.3 Serving服务化部署
|
||||
|
||||
暂未支持
|
||||
|
||||
### 4.4 更多推理部署
|
||||
|
||||
暂未支持
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
## 引用
|
||||
|
||||
```bibtex
|
||||
@inproceedings{zhou2017east,
|
||||
title={East: an efficient and accurate scene text detector},
|
||||
author={Zhou, Xinyu and Yao, Cong and Wen, He and Wang, Yuzhi and Zhou, Shuchang and He, Weiran and Liang, Jiajun},
|
||||
booktitle={Proceedings of the IEEE conference on Computer Vision and Pattern Recognition},
|
||||
pages={5551--5560},
|
||||
year={2017}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,86 @@
|
||||
---
|
||||
typora-copy-images-to: images
|
||||
comments: true
|
||||
---
|
||||
|
||||
# FCENet
|
||||
|
||||
## 1. Introduction
|
||||
|
||||
Paper:
|
||||
> [Fourier Contour Embedding for Arbitrary-Shaped Text Detection](https://arxiv.org/abs/2104.10442)
|
||||
> Yiqin Zhu and Jianyong Chen and Lingyu Liang and Zhanghui Kuang and Lianwen Jin and Wayne Zhang
|
||||
> CVPR, 2021
|
||||
|
||||
On the CTW1500 dataset, the text detection result is as follows:
|
||||
|
||||
|Model|Backbone|Configuration|Precision|Recall|Hmean|Download|
|
||||
| --- | --- | --- | --- | --- | --- | --- |
|
||||
| FCE | ResNet50_dcn | [configs/det/det_r50_vd_dcn_fce_ctw.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/det/det_r50_vd_dcn_fce_ctw.yml)| 88.39%|82.18%|85.27%|[trained model](https://paddleocr.bj.bcebos.com/contribution/det_r50_dcn_fce_ctw_v2.0_train.tar)|
|
||||
|
||||
## 2. Environment
|
||||
|
||||
Please prepare your environment referring to [prepare the environment](../../ppocr/environment.en.md) and [clone the repo](../../ppocr/blog/clone.en.md).
|
||||
|
||||
## 3. Model Training / Evaluation / Prediction
|
||||
|
||||
The above FCE model is trained using the CTW1500 text detection public dataset. For the download of the dataset, please refer to [ocr_datasets](../../../datasets/ocr_datasets.en.md).
|
||||
|
||||
After the data download is complete, please refer to [Text Detection Training Tutorial](../../ppocr/model_train/detection.en.md) for training. PaddleOCR has modularized the code structure, so that you only need to **replace the configuration file** to train different detection models.
|
||||
|
||||
## 4. Inference and Deployment
|
||||
|
||||
### 4.1 Python Inference
|
||||
|
||||
First, convert the model saved in the FCE text detection training process into an inference model. Taking the model based on the Resnet50_vd_dcn backbone network and trained on the CTW1500 English dataset as example ([model download link](https://paddleocr.bj.bcebos.com/contribution/det_r50_dcn_fce_ctw_v2.0_train.tar)), you can use the following command to convert:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/export_model.py -c configs/det/det_r50_vd_dcn_fce_ctw.yml -o Global.pretrained_model=./det_r50_dcn_fce_ctw_v2.0_train/best_accuracy Global.save_inference_dir=./inference/det_fce
|
||||
```
|
||||
|
||||
FCE text detection model inference, to perform non-curved text detection, you can run the following commands:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_det.py --image_dir="./doc/imgs_en/img_10.jpg" --det_model_dir="./inference/det_fce/" --det_algorithm="FCE" --det_fce_box_type=quad
|
||||
```
|
||||
|
||||
The visualized text detection results are saved to the `./inference_results` folder by default, and the name of the result file is prefixed with 'det_res'. Examples of results are as follows:
|
||||
|
||||

|
||||
|
||||
If you want to perform curved text detection, you can execute the following command:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_det.py --image_dir="./doc/imgs_en/img623.jpg" --det_model_dir="./inference/det_fce/" --det_algorithm="FCE" --det_fce_box_type=poly
|
||||
```
|
||||
|
||||
The visualized text detection results are saved to the `./inference_results` folder by default, and the name of the result file is prefixed with 'det_res'. Examples of results are as follows:
|
||||
|
||||

|
||||
|
||||
**Note**: Since the CTW1500 dataset has only 1,000 training images, mainly for English scenes, the above model has very poor detection result on Chinese or curved text images.
|
||||
|
||||
### 4.2 C++ Inference
|
||||
|
||||
Since the post-processing is not written in CPP, the FCE text detection model does not support CPP inference.
|
||||
|
||||
### 4.3 Serving
|
||||
|
||||
Not supported
|
||||
|
||||
### 4.4 More
|
||||
|
||||
Not supported
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
## Citation
|
||||
|
||||
```bibtex
|
||||
@InProceedings{zhu2021fourier,
|
||||
title={Fourier Contour Embedding for Arbitrary-Shaped Text Detection},
|
||||
author={Yiqin Zhu and Jianyong Chen and Lingyu Liang and Zhanghui Kuang and Lianwen Jin and Wayne Zhang},
|
||||
year={2021},
|
||||
booktitle = {CVPR}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,86 @@
|
||||
---
|
||||
typora-copy-images-to: images
|
||||
comments: true
|
||||
---
|
||||
|
||||
# FCENet
|
||||
|
||||
## 1. 算法简介
|
||||
|
||||
论文信息:
|
||||
> [Fourier Contour Embedding for Arbitrary-Shaped Text Detection](https://arxiv.org/abs/2104.10442)
|
||||
> Yiqin Zhu and Jianyong Chen and Lingyu Liang and Zhanghui Kuang and Lianwen Jin and Wayne Zhang
|
||||
> CVPR, 2021
|
||||
|
||||
在CTW1500文本检测公开数据集上,算法复现效果如下:
|
||||
|
||||
| 模型 |骨干网络|配置文件|precision|recall|Hmean|下载链接|
|
||||
|-----| --- | --- | --- | --- | --- | --- |
|
||||
| FCE | ResNet50_dcn | [configs/det/det_r50_vd_dcn_fce_ctw.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/det/det_r50_vd_dcn_fce_ctw.yml)| 88.39%|82.18%|85.27%|[训练模型](https://paddleocr.bj.bcebos.com/contribution/det_r50_dcn_fce_ctw_v2.0_train.tar)|
|
||||
|
||||
## 2. 环境配置
|
||||
|
||||
请先参考[《运行环境准备》](../../ppocr/environment.md)配置PaddleOCR运行环境,参考[《项目克隆》](../../ppocr/blog/clone.md)克隆项目代码。
|
||||
|
||||
## 3. 模型训练、评估、预测
|
||||
|
||||
上述FCE模型使用CTW1500文本检测公开数据集训练得到,数据集下载可参考 [ocr_datasets](../../../datasets/ocr_datasets.md)。
|
||||
|
||||
数据下载完成后,请参考[文本检测训练教程](../../ppocr/model_train/detection.md)进行训练。PaddleOCR对代码进行了模块化,训练不同的检测模型只需要**更换配置文件**即可。
|
||||
|
||||
## 4. 推理部署
|
||||
|
||||
### 4.1 Python推理
|
||||
|
||||
首先将FCE文本检测训练过程中保存的模型,转换成inference model。以基于Resnet50_vd_dcn骨干网络,在CTW1500英文数据集训练的模型为例( [模型下载地址](https://paddleocr.bj.bcebos.com/contribution/det_r50_dcn_fce_ctw_v2.0_train.tar) ),可以使用如下命令进行转换:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/export_model.py -c configs/det/det_r50_vd_dcn_fce_ctw.yml -o Global.pretrained_model=./det_r50_dcn_fce_ctw_v2.0_train/best_accuracy Global.save_inference_dir=./inference/det_fce
|
||||
```
|
||||
|
||||
FCE文本检测模型推理,执行非弯曲文本检测,可以执行如下命令:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_det.py --image_dir="./doc/imgs_en/img_10.jpg" --det_model_dir="./inference/det_fce/" --det_algorithm="FCE" --det_fce_box_type=quad
|
||||
```
|
||||
|
||||
可视化文本检测结果默认保存到`./inference_results`文件夹里面,结果文件的名称前缀为'det_res'。结果示例如下:
|
||||
|
||||

|
||||
|
||||
如果想执行弯曲文本检测,可以执行如下命令:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_det.py --image_dir="./doc/imgs_en/img623.jpg" --det_model_dir="./inference/det_fce/" --det_algorithm="FCE" --det_fce_box_type=poly
|
||||
```
|
||||
|
||||
可视化文本检测结果默认保存到`./inference_results`文件夹里面,结果文件的名称前缀为'det_res'。结果示例如下:
|
||||
|
||||

|
||||
|
||||
**注意**:由于CTW1500数据集只有1000张训练图像,且主要针对英文场景,所以上述模型对中文文本图像检测效果会比较差。
|
||||
|
||||
### 4.2 C++推理
|
||||
|
||||
由于后处理暂未使用CPP编写,FCE文本检测模型暂不支持CPP推理。
|
||||
|
||||
### 4.3 Serving服务化部署
|
||||
|
||||
暂未支持
|
||||
|
||||
### 4.4 更多推理部署
|
||||
|
||||
暂未支持
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
## 引用
|
||||
|
||||
```bibtex
|
||||
@InProceedings{zhu2021fourier,
|
||||
title={Fourier Contour Embedding for Arbitrary-Shaped Text Detection},
|
||||
author={Yiqin Zhu and Jianyong Chen and Lingyu Liang and Zhanghui Kuang and Lianwen Jin and Wayne Zhang},
|
||||
year={2021},
|
||||
booktitle = {CVPR}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,89 @@
|
||||
---
|
||||
typora-copy-images-to: images
|
||||
comments: true
|
||||
---
|
||||
|
||||
|
||||
# PSENet
|
||||
|
||||
## 1. Introduction
|
||||
|
||||
Paper:
|
||||
> [Shape robust text detection with progressive scale expansion network](https://arxiv.org/abs/1903.12473)
|
||||
> Wang, Wenhai and Xie, Enze and Li, Xiang and Hou, Wenbo and Lu, Tong and Yu, Gang and Shao, Shuai
|
||||
> CVPR, 2019
|
||||
|
||||
On the ICDAR2015 dataset, the text detection result is as follows:
|
||||
|
||||
|Model|Backbone|Configuration|Precision|Recall|Hmean|Download|
|
||||
| --- | --- | --- | --- | --- | --- | --- |
|
||||
|PSE| ResNet50_vd | [configs/det/det_r50_vd_pse.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/det/det_r50_vd_pse.yml)| 85.81% |79.53%|82.55%|[trained model](https://paddleocr.bj.bcebos.com/dygraph_v2.1/en_det/det_r50_vd_pse_v2.0_train.tar)|
|
||||
|PSE| MobileNetV3| [configs/det/det_mv3_pse.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/det/det_mv3_pse.yml) | 82.20% |70.48%|75.89%|[trained model](https://paddleocr.bj.bcebos.com/dygraph_v2.1/en_det/det_mv3_pse_v2.0_train.tar)|
|
||||
|
||||
## 2. Environment
|
||||
|
||||
Please prepare your environment referring to [prepare the environment](../../ppocr/environment.en.md) and [clone the repo](../../ppocr/blog/clone.en.md).
|
||||
|
||||
## 3. Model Training / Evaluation / Prediction
|
||||
|
||||
The above PSE model is trained using the ICDAR2015 text detection public dataset. For the download of the dataset, please refer to [ocr_datasets](../../../datasets/ocr_datasets.en.md).
|
||||
|
||||
After the data download is complete, please refer to [Text Detection Training Tutorial](../../ppocr/model_train/detection.en.md) for training. PaddleOCR has modularized the code structure, so that you only need to **replace the configuration file** to train different detection models.
|
||||
|
||||
## 4. Inference and Deployment
|
||||
|
||||
### 4.1 Python Inference
|
||||
|
||||
First, convert the model saved in the PSE text detection training process into an inference model. Taking the model based on the Resnet50_vd backbone network and trained on the ICDAR2015 English dataset as example ([model download link](https://paddleocr.bj.bcebos.com/dygraph_v2.1/en_det/det_r50_vd_pse_v2.0_train.tar)), you can use the following command to convert:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/export_model.py -c configs/det/det_r50_vd_pse.yml -o Global.pretrained_model=./det_r50_vd_pse_v2.0_train/best_accuracy Global.save_inference_dir=./inference/det_pse
|
||||
```
|
||||
|
||||
PSE text detection model inference, to perform non-curved text detection, you can run the following commands:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_det.py --image_dir="./doc/imgs_en/img_10.jpg" --det_model_dir="./inference/det_pse/" --det_algorithm="PSE" --det_pse_box_type=quad
|
||||
```
|
||||
|
||||
The visualized text detection results are saved to the `./inference_results` folder by default, and the name of the result file is prefixed with 'det_res'. Examples of results are as follows:
|
||||
|
||||

|
||||
|
||||
If you want to perform curved text detection, you can execute the following command:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_det.py --image_dir="./doc/imgs_en/img_10.jpg" --det_model_dir="./inference/det_pse/" --det_algorithm="PSE" --det_pse_box_type=poly
|
||||
```
|
||||
|
||||
The visualized text detection results are saved to the `./inference_results` folder by default, and the name of the result file is prefixed with 'det_res'. Examples of results are as follows:
|
||||
|
||||

|
||||
|
||||
**Note**: Since the ICDAR2015 dataset has only 1,000 training images, mainly for English scenes, the above model has very poor detection result on Chinese or curved text images.
|
||||
|
||||
### 4.2 C++ Inference
|
||||
|
||||
Since the post-processing is not written in CPP, the PSE text detection model does not support CPP inference.
|
||||
|
||||
### 4.3 Serving
|
||||
|
||||
Not supported
|
||||
|
||||
### 4.4 More
|
||||
|
||||
Not supported
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
## Citation
|
||||
|
||||
```bibtex
|
||||
@inproceedings{wang2019shape,
|
||||
title={Shape robust text detection with progressive scale expansion network},
|
||||
author={Wang, Wenhai and Xie, Enze and Li, Xiang and Hou, Wenbo and Lu, Tong and Yu, Gang and Shao, Shuai},
|
||||
booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},
|
||||
pages={9336--9345},
|
||||
year={2019}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,88 @@
|
||||
---
|
||||
typora-copy-images-to: images
|
||||
comments: true
|
||||
---
|
||||
|
||||
# PSENet
|
||||
|
||||
## 1. 算法简介
|
||||
|
||||
论文信息:
|
||||
> [Shape robust text detection with progressive scale expansion network](https://arxiv.org/abs/1903.12473)
|
||||
> Wang, Wenhai and Xie, Enze and Li, Xiang and Hou, Wenbo and Lu, Tong and Yu, Gang and Shao, Shuai
|
||||
> CVPR, 2019
|
||||
|
||||
在ICDAR2015文本检测公开数据集上,算法复现效果如下:
|
||||
|
||||
|模型|骨干网络|配置文件|precision|recall|Hmean|下载链接|
|
||||
| --- | --- | --- | --- | --- | --- | --- |
|
||||
|PSE| ResNet50_vd | [configs/det/det_r50_vd_pse.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/det/det_r50_vd_pse.yml)| 85.81% |79.53%|82.55%|[训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.1/en_det/det_r50_vd_pse_v2.0_train.tar)|
|
||||
|PSE| MobileNetV3| [configs/det/det_mv3_pse.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/det/det_mv3_pse.yml) | 82.20% |70.48%|75.89%|[训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.1/en_det/det_mv3_pse_v2.0_train.tar)|
|
||||
|
||||
## 2. 环境配置
|
||||
|
||||
请先参考[《运行环境准备》](../../ppocr/environment.md)配置PaddleOCR运行环境,参考[《项目克隆》](../../ppocr/blog/clone.md)克隆项目代码。
|
||||
|
||||
## 3. 模型训练、评估、预测
|
||||
|
||||
上述PSE模型使用ICDAR2015文本检测公开数据集训练得到,数据集下载可参考 [ocr_datasets](../../../datasets/ocr_datasets.md)。
|
||||
|
||||
数据下载完成后,请参考[文本检测训练教程](../../ppocr/model_train/detection.md)进行训练。PaddleOCR对代码进行了模块化,训练不同的检测模型只需要**更换配置文件**即可。
|
||||
|
||||
## 4. 推理部署
|
||||
|
||||
### 4.1 Python推理
|
||||
|
||||
首先将PSE文本检测训练过程中保存的模型,转换成inference model。以基于Resnet50_vd骨干网络,在ICDAR2015英文数据集训练的模型为例( [模型下载地址](https://paddleocr.bj.bcebos.com/dygraph_v2.1/en_det/det_r50_vd_pse_v2.0_train.tar) ),可以使用如下命令进行转换:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/export_model.py -c configs/det/det_r50_vd_pse.yml -o Global.pretrained_model=./det_r50_vd_pse_v2.0_train/best_accuracy Global.save_inference_dir=./inference/det_pse
|
||||
```
|
||||
|
||||
PSE文本检测模型推理,执行非弯曲文本检测,可以执行如下命令:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_det.py --image_dir="./doc/imgs_en/img_10.jpg" --det_model_dir="./inference/det_pse/" --det_algorithm="PSE" --det_pse_box_type=quad
|
||||
```
|
||||
|
||||
可视化文本检测结果默认保存到`./inference_results`文件夹里面,结果文件的名称前缀为'det_res'。结果示例如下:
|
||||
|
||||

|
||||
|
||||
如果想执行弯曲文本检测,可以执行如下命令:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_det.py --image_dir="./doc/imgs_en/img_10.jpg" --det_model_dir="./inference/det_pse/" --det_algorithm="PSE" --det_pse_box_type=poly
|
||||
```
|
||||
|
||||
可视化文本检测结果默认保存到`./inference_results`文件夹里面,结果文件的名称前缀为'det_res'。结果示例如下:
|
||||
|
||||

|
||||
|
||||
**注意**:由于ICDAR2015数据集只有1000张训练图像,且主要针对英文场景,所以上述模型对中文或弯曲文本图像检测效果会比较差。
|
||||
|
||||
### 4.2 C++推理
|
||||
|
||||
由于后处理暂未使用CPP编写,PSE文本检测模型暂不支持CPP推理。
|
||||
|
||||
### 4.3 Serving服务化部署
|
||||
|
||||
暂未支持
|
||||
|
||||
### 4.4 更多推理部署
|
||||
|
||||
暂未支持
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
## 引用
|
||||
|
||||
```bibtex
|
||||
@inproceedings{wang2019shape,
|
||||
title={Shape robust text detection with progressive scale expansion network},
|
||||
author={Wang, Wenhai and Xie, Enze and Li, Xiang and Hou, Wenbo and Lu, Tong and Yu, Gang and Shao, Shuai},
|
||||
booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},
|
||||
pages={9336--9345},
|
||||
year={2019}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,101 @@
|
||||
---
|
||||
typora-copy-images-to: images
|
||||
comments: true
|
||||
---
|
||||
|
||||
# SAST
|
||||
|
||||
## 1. Introduction
|
||||
|
||||
Paper:
|
||||
> [A Single-Shot Arbitrarily-Shaped Text Detector based on Context Attended Multi-Task Learning](https://arxiv.org/abs/1908.05498)
|
||||
> Wang, Pengfei and Zhang, Chengquan and Qi, Fei and Huang, Zuming and En, Mengyi and Han, Junyu and Liu, Jingtuo and Ding, Errui and Shi, Guangming
|
||||
> ACM MM, 2019
|
||||
|
||||
On the ICDAR2015 dataset, the text detection result is as follows:
|
||||
|
||||
|Model|Backbone|Configuration|Precision|Recall|Hmean|Download|
|
||||
| --- | --- | --- | --- | --- | --- | --- |
|
||||
|SAST|ResNet50_vd|[configs/det/det_r50_vd_sast_icdar15.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/det/det_r50_vd_sast_icdar15.yml)|91.39%|83.77%|87.42%|[trained model](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/det_r50_vd_sast_icdar15_v2.0_train.tar)|
|
||||
|
||||
On the Total-text dataset, the text detection result is as follows:
|
||||
|
||||
|Model|Backbone|Configuration|Precision|Recall|Hmean|Download|
|
||||
| --- | --- | --- | --- | --- | --- | --- |
|
||||
|SAST|ResNet50_vd|[configs/det/det_r50_vd_sast_totaltext.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/det/det_r50_vd_sast_totaltext.yml)|89.63%|78.44%|83.66%|[trained model](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/det_r50_vd_sast_totaltext_v2.0_train.tar)|
|
||||
|
||||
## 2. Environment
|
||||
|
||||
Please prepare your environment referring to [prepare the environment](../../ppocr/environment.en.md) and [clone the repo](../../ppocr/blog/clone.en.md).
|
||||
|
||||
## 3. Model Training / Evaluation / Prediction
|
||||
|
||||
Please refer to [text detection training tutorial](../../ppocr/model_train/detection.en.md). PaddleOCR has modularized the code structure, so that you only need to **replace the configuration file** to train different detection models.
|
||||
|
||||
## 4. Inference and Deployment
|
||||
|
||||
### 4.1 Python Inference
|
||||
|
||||
#### (1). Quadrangle text detection model (ICDAR2015)
|
||||
|
||||
First, convert the model saved in the SAST text detection training process into an inference model. Taking the model based on the Resnet50_vd backbone network and trained on the ICDAR2015 English dataset as an example ([model download link](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/det_r50_vd_sast_icdar15_v2.0_train.tar)), you can use the following command to convert:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/export_model.py -c configs/det/det_r50_vd_sast_icdar15.yml -o Global.pretrained_model=./det_r50_vd_sast_icdar15_v2.0_train/best_accuracy Global.save_inference_dir=./inference/det_sast_ic15
|
||||
```
|
||||
|
||||
**For SAST quadrangle text detection model inference, you need to set the parameter `--det_algorithm="SAST"`**, run the following command:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_det.py --det_algorithm="SAST" --image_dir="./doc/imgs_en/img_10.jpg" --det_model_dir="./inference/det_sast_ic15/"
|
||||
```
|
||||
|
||||
The visualized text detection results are saved to the `./inference_results` folder by default, and the name of the result file is prefixed with 'det_res'. Examples of results are as follows:
|
||||
|
||||

|
||||
|
||||
#### (2). Curved text detection model (Total-Text)
|
||||
|
||||
First, convert the model saved in the SAST text detection training process into an inference model. Taking the model based on the Resnet50_vd backbone network and trained on the Total-Text English dataset as an example ([model download link](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/det_r50_vd_sast_totaltext_v2.0_train.tar)), you can use the following command to convert:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/export_model.py -c configs/det/det_r50_vd_sast_totaltext.yml -o Global.pretrained_model=./det_r50_vd_sast_totaltext_v2.0_train/best_accuracy Global.save_inference_dir=./inference/det_sast_tt
|
||||
```
|
||||
|
||||
For SAST curved text detection model inference, you need to set the parameter `--det_algorithm="SAST"` and `--det_box_type=poly`, run the following command:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_det.py --det_algorithm="SAST" --image_dir="./doc/imgs_en/img623.jpg" --det_model_dir="./inference/det_sast_tt/" --det_box_type='poly'
|
||||
```
|
||||
|
||||
The visualized text detection results are saved to the `./inference_results` folder by default, and the name of the result file is prefixed with 'det_res'. Examples of results are as follows:
|
||||
|
||||

|
||||
|
||||
**Note**: SAST post-processing locality aware NMS has two versions: Python and C++. The speed of C++ version is obviously faster than that of Python version. Due to the compilation version problem of NMS of C++ version, C++ version NMS will be called only in Python 3.5 environment, and python version NMS will be called in other cases.
|
||||
|
||||
### 4.2 C++ Inference
|
||||
|
||||
Not supported
|
||||
|
||||
### 4.3 Serving
|
||||
|
||||
Not supported
|
||||
|
||||
### 4.4 More
|
||||
|
||||
Not supported
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
## Citation
|
||||
|
||||
```bibtex
|
||||
@inproceedings{wang2019single,
|
||||
title={A Single-Shot Arbitrarily-Shaped Text Detector based on Context Attended Multi-Task Learning},
|
||||
author={Wang, Pengfei and Zhang, Chengquan and Qi, Fei and Huang, Zuming and En, Mengyi and Han, Junyu and Liu, Jingtuo and Ding, Errui and Shi, Guangming},
|
||||
booktitle={Proceedings of the 27th ACM International Conference on Multimedia},
|
||||
pages={1277--1285},
|
||||
year={2019}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,101 @@
|
||||
---
|
||||
typora-copy-images-to: images
|
||||
comments: true
|
||||
---
|
||||
|
||||
# SAST
|
||||
|
||||
## 1. 算法简介
|
||||
|
||||
论文信息:
|
||||
> [A Single-Shot Arbitrarily-Shaped Text Detector based on Context Attended Multi-Task Learning](https://arxiv.org/abs/1908.05498)
|
||||
> Wang, Pengfei and Zhang, Chengquan and Qi, Fei and Huang, Zuming and En, Mengyi and Han, Junyu and Liu, Jingtuo and Ding, Errui and Shi, Guangming
|
||||
> ACM MM, 2019
|
||||
|
||||
在ICDAR2015文本检测公开数据集上,算法复现效果如下:
|
||||
|
||||
|模型|骨干网络|配置文件|precision|recall|Hmean|下载链接|
|
||||
| --- | --- | --- | --- | --- | --- | --- |
|
||||
|SAST|ResNet50_vd|[configs/det/det_r50_vd_sast_icdar15.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/det/det_r50_vd_sast_icdar15.yml)|91.39%|83.77%|87.42%|[训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/det_r50_vd_sast_icdar15_v2.0_train.tar)|
|
||||
|
||||
在Total-text文本检测公开数据集上,算法复现效果如下:
|
||||
|
||||
|模型|骨干网络|配置文件|precision|recall|Hmean|下载链接|
|
||||
| --- | --- | --- | --- | --- | --- | --- |
|
||||
|SAST|ResNet50_vd|[configs/det/det_r50_vd_sast_totaltext.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/det/det_r50_vd_sast_totaltext.yml)|89.63%|78.44%|83.66%|[训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/det_r50_vd_sast_totaltext_v2.0_train.tar)|
|
||||
|
||||
## 2. 环境配置
|
||||
|
||||
请先参考[《运行环境准备》](../../ppocr/environment.md)配置PaddleOCR运行环境,参考[《项目克隆》](../../ppocr/blog/clone.md)克隆项目代码。
|
||||
|
||||
## 3. 模型训练、评估、预测
|
||||
|
||||
请参考[文本检测训练教程](../../ppocr/model_train/detection.md)。PaddleOCR对代码进行了模块化,训练不同的检测模型只需要**更换配置文件**即可。
|
||||
|
||||
## 4. 推理部署
|
||||
|
||||
### 4.1 Python推理
|
||||
|
||||
#### (1). 四边形文本检测模型(ICDAR2015)
|
||||
|
||||
首先将SAST文本检测训练过程中保存的模型,转换成inference model。以基于Resnet50_vd骨干网络,在ICDAR2015英文数据集训练的模型为例([模型下载地址](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/det_r50_vd_sast_icdar15_v2.0_train.tar)),可以使用如下命令进行转换:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/export_model.py -c configs/det/det_r50_vd_sast_icdar15.yml -o Global.pretrained_model=./det_r50_vd_sast_icdar15_v2.0_train/best_accuracy Global.save_inference_dir=./inference/det_sast_ic15
|
||||
```
|
||||
|
||||
**SAST文本检测模型推理,需要设置参数`--det_algorithm="SAST"`**,可以执行如下命令:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_det.py --det_algorithm="SAST" --image_dir="./doc/imgs_en/img_10.jpg" --det_model_dir="./inference/det_sast_ic15/"
|
||||
```
|
||||
|
||||
可视化文本检测结果默认保存到`./inference_results`文件夹里面,结果文件的名称前缀为'det_res'。结果示例如下:
|
||||
|
||||

|
||||
|
||||
#### (2). 弯曲文本检测模型(Total-Text)
|
||||
|
||||
首先将SAST文本检测训练过程中保存的模型,转换成inference model。以基于Resnet50_vd骨干网络,在Total-Text英文数据集训练的模型为例([模型下载地址](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/det_r50_vd_sast_totaltext_v2.0_train.tar)),可以使用如下命令进行转换:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/export_model.py -c configs/det/det_r50_vd_sast_totaltext.yml -o Global.pretrained_model=./det_r50_vd_sast_totaltext_v2.0_train/best_accuracy Global.save_inference_dir=./inference/det_sast_tt
|
||||
```
|
||||
|
||||
SAST文本检测模型推理,需要设置参数`--det_algorithm="SAST"`,同时,还需要增加参数`--det_box_type=poly`,可以执行如下命令:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_det.py --det_algorithm="SAST" --image_dir="./doc/imgs_en/img623.jpg" --det_model_dir="./inference/det_sast_tt/" --det_box_type='poly'
|
||||
```
|
||||
|
||||
可视化文本检测结果默认保存到`./inference_results`文件夹里面,结果文件的名称前缀为'det_res'。结果示例如下:
|
||||
|
||||

|
||||
|
||||
**注意**:本代码库中,SAST后处理Locality-Aware NMS有python和c++两种版本,c++版速度明显快于python版。由于c++版本nms编译版本问题,只有python3.5环境下会调用c++版nms,其他情况将调用python版nms。
|
||||
|
||||
### 4.2 C++推理
|
||||
|
||||
暂未支持
|
||||
|
||||
### 4.3 Serving服务化部署
|
||||
|
||||
暂未支持
|
||||
|
||||
### 4.4 更多推理部署
|
||||
|
||||
暂未支持
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
## 引用
|
||||
|
||||
```bibtex
|
||||
@inproceedings{wang2019single,
|
||||
title={A Single-Shot Arbitrarily-Shaped Text Detector based on Context Attended Multi-Task Learning},
|
||||
author={Wang, Pengfei and Zhang, Chengquan and Qi, Fei and Huang, Zuming and En, Mengyi and Han, Junyu and Liu, Jingtuo and Ding, Errui and Shi, Guangming},
|
||||
booktitle={Proceedings of the 27th ACM International Conference on Multimedia},
|
||||
pages={1277--1285},
|
||||
year={2019}
|
||||
}
|
||||
```
|
||||
|
After Width: | Height: | Size: 138 KiB |
|
After Width: | Height: | Size: 134 KiB |
|
After Width: | Height: | Size: 125 KiB |
|
After Width: | Height: | Size: 331 KiB |
|
After Width: | Height: | Size: 332 KiB |
|
After Width: | Height: | Size: 330 KiB |
|
After Width: | Height: | Size: 330 KiB |
|
After Width: | Height: | Size: 332 KiB |
|
After Width: | Height: | Size: 332 KiB |
@@ -0,0 +1,121 @@
|
||||
---
|
||||
comments: true
|
||||
---
|
||||
|
||||
# ABINet
|
||||
|
||||
## 1. Introduction
|
||||
|
||||
Paper:
|
||||
> [ABINet: Read Like Humans: Autonomous, Bidirectional and Iterative Language Modeling for Scene Text Recognition](https://openaccess.thecvf.com/content/CVPR2021/papers/Fang_Read_Like_Humans_Autonomous_Bidirectional_and_Iterative_Language_Modeling_for_CVPR_2021_paper.pdf)
|
||||
> Shancheng Fang and Hongtao Xie and Yuxin Wang and Zhendong Mao and Yongdong Zhang
|
||||
> CVPR, 2021
|
||||
|
||||
Using MJSynth and SynthText two text recognition datasets for training, and evaluating on IIIT, SVT, IC03, IC13, IC15, SVTP, CUTE datasets, the algorithm reproduction effect is as follows:
|
||||
|
||||
|Model|Backbone|config|Acc|Download link|
|
||||
| --- | --- | --- | --- | --- |
|
||||
|ABINet|ResNet45|[rec_r45_abinet.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/rec/rec_r45_abinet.yml)|90.75%|[pretrained & trained model](https://paddleocr.bj.bcebos.com/rec_r45_abinet_train.tar)|
|
||||
|
||||
## 2. Environment
|
||||
|
||||
Please refer to ["Environment Preparation"](../../ppocr/environment.en.md) to configure the PaddleOCR environment, and refer to ["Project Clone"](../../ppocr/blog/clone.en.md)to clone the project code.
|
||||
|
||||
## 3. Model Training / Evaluation / Prediction
|
||||
|
||||
Please refer to [Text Recognition Tutorial](../../ppocr/model_train/recognition.en.md). PaddleOCR modularizes the code, and training different recognition models only requires **changing the configuration file**.
|
||||
|
||||
### Training
|
||||
|
||||
Specifically, after the data preparation is completed, the training can be started. The training command is as follows:
|
||||
|
||||
```bash linenums="1"
|
||||
# Single GPU training (long training period, not recommended)
|
||||
python3 tools/train.py -c configs/rec/rec_r45_abinet.yml
|
||||
|
||||
# Multi GPU training, specify the gpu number through the --gpus parameter
|
||||
python3 -m paddle.distributed.launch --gpus '0,1,2,3' tools/train.py -c configs/rec/rec_r45_abinet.yml
|
||||
```
|
||||
|
||||
### Evaluation
|
||||
|
||||
```bash linenums="1"
|
||||
# GPU evaluation
|
||||
python3 -m paddle.distributed.launch --gpus '0' tools/eval.py -c configs/rec/rec_r45_abinet.yml -o Global.pretrained_model={path/to/weights}/best_accuracy
|
||||
```
|
||||
|
||||
### Prediction
|
||||
|
||||
```bash linenums="1"
|
||||
# The configuration file used for prediction must match the training
|
||||
python3 tools/infer_rec.py -c configs/rec/rec_r45_abinet.yml -o Global.infer_img='./doc/imgs_words_en/word_10.png' Global.pretrained_model=./rec_r45_abinet_train/best_accuracy
|
||||
```
|
||||
|
||||
## 4. Inference and Deployment
|
||||
|
||||
### 4.1 Python Inference
|
||||
|
||||
First, the model saved during the ABINet text recognition training process is converted into an inference model. ( [Model download link](https://paddleocr.bj.bcebos.com/rec_r45_abinet_train.tar)) ), you can use the following command to convert:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/export_model.py -c configs/rec/rec_r45_abinet.yml -o Global.pretrained_model=./rec_r45_abinet_train/best_accuracy Global.save_inference_dir=./inference/rec_r45_abinet
|
||||
```
|
||||
|
||||
**Note:**
|
||||
|
||||
- If you are training the model on your own dataset and have modified the dictionary file, please pay attention to modify the `character_dict_path` in the configuration file to the modified dictionary file.
|
||||
- If you modified the input size during training, please modify the `infer_shape` corresponding to ABINet in the `tools/export_model.py` file.
|
||||
|
||||
After the conversion is successful, there are three files in the directory:
|
||||
|
||||
```text linenums="1"
|
||||
/inference/rec_r45_abinet/
|
||||
├── inference.pdiparams
|
||||
├── inference.pdiparams.info
|
||||
└── inference.pdmodel
|
||||
```
|
||||
|
||||
For ABINet text recognition model inference, the following commands can be executed:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_rec.py --image_dir='./doc/imgs_words_en/word_10.png' --rec_model_dir='./inference/rec_r45_abinet/' --rec_algorithm='ABINet' --rec_image_shape='3,32,128' --rec_char_dict_path='./ppocr/utils/ic15_dict.txt'
|
||||
```
|
||||
|
||||

|
||||
|
||||
After executing the command, the prediction result (recognized text and score) of the image above is printed to the screen, an example is as follows:
|
||||
The result is as follows:
|
||||
|
||||
```bash linenums="1"
|
||||
Predicts of ./doc/imgs_words_en/word_10.png:('pain', 0.9999995231628418)
|
||||
```
|
||||
|
||||
### 4.2 C++ Inference
|
||||
|
||||
Not supported
|
||||
|
||||
### 4.3 Serving
|
||||
|
||||
Not supported
|
||||
|
||||
### 4.4 More
|
||||
|
||||
Not supported
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
1. Note that the MJSynth and SynthText datasets come from [ABINet repo](https://github.com/FangShancheng/ABINet).
|
||||
2. We use the pre-trained model provided by the ABINet authors for finetune training.
|
||||
|
||||
## Citation
|
||||
|
||||
```bibtex
|
||||
@article{Fang2021ABINet,
|
||||
title = {ABINet: Read Like Humans: Autonomous, Bidirectional and Iterative Language Modeling for Scene Text Recognition},
|
||||
author = {Shancheng Fang and Hongtao Xie and Yuxin Wang and Zhendong Mao and Yongdong Zhang},
|
||||
booktitle = {CVPR},
|
||||
year = {2021},
|
||||
url = {https://arxiv.org/abs/2103.06495},
|
||||
pages = {7098-7107}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,136 @@
|
||||
---
|
||||
comments: true
|
||||
---
|
||||
|
||||
# 场景文本识别算法-ABINet
|
||||
|
||||
## 1. 算法简介
|
||||
|
||||
论文信息:
|
||||
> [ABINet: Read Like Humans: Autonomous, Bidirectional and Iterative Language Modeling for Scene Text Recognition](https://openaccess.thecvf.com/content/CVPR2021/papers/Fang_Read_Like_Humans_Autonomous_Bidirectional_and_Iterative_Language_Modeling_for_CVPR_2021_paper.pdf)
|
||||
> Shancheng Fang and Hongtao Xie and Yuxin Wang and Zhendong Mao and Yongdong Zhang
|
||||
> CVPR, 2021
|
||||
|
||||
`ABINet`使用MJSynth和SynthText两个文字识别数据集训练,在IIIT, SVT, IC03, IC13, IC15, SVTP, CUTE数据集上进行评估,算法复现效果如下:
|
||||
|
||||
|模型|骨干网络|配置文件|Acc|下载链接|
|
||||
| --- | --- | --- | --- | --- |
|
||||
|ABINet|ResNet45|[rec_r45_abinet.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/rec/rec_r45_abinet.yml)|90.75%|[预训练、训练模型](https://paddleocr.bj.bcebos.com/rec_r45_abinet_train.tar)|
|
||||
|
||||
## 2. 环境配置
|
||||
|
||||
请先参考[《运行环境准备》](../../ppocr/environment.md)配置PaddleOCR运行环境,参考[《项目克隆》](../../ppocr/blog/clone.md)克隆项目代码。
|
||||
|
||||
## 3. 模型训练、评估、预测
|
||||
|
||||
### 3.1 模型训练
|
||||
|
||||
请参考[文本识别训练教程](../../ppocr/model_train/recognition.md)。PaddleOCR对代码进行了模块化,训练`ABINet`识别模型时需要**更换配置文件**为`ABINet`的[配置文件](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/rec/rec_r45_abinet.yml)。
|
||||
|
||||
#### 启动训练
|
||||
|
||||
具体地,在完成数据准备后,便可以启动训练,训练命令如下:
|
||||
|
||||
```bash linenums="1"
|
||||
#单卡训练(训练周期长,不建议)
|
||||
python3 tools/train.py -c configs/rec/rec_r45_abinet.yml
|
||||
|
||||
# 多卡训练,通过--gpus参数指定卡号
|
||||
python3 -m paddle.distributed.launch --gpus '0,1,2,3' tools/train.py -c configs/rec/rec_r45_abinet.yml
|
||||
```
|
||||
|
||||
### 3.2 评估
|
||||
|
||||
可下载已训练完成的模型文件,使用如下命令进行评估:
|
||||
|
||||
```bash linenums="1"
|
||||
# 注意将pretrained_model的路径设置为本地路径。
|
||||
python3 -m paddle.distributed.launch --gpus '0' tools/eval.py -c configs/rec/rec_r45_abinet.yml -o Global.pretrained_model=./rec_r45_abinet_train/best_accuracy
|
||||
```
|
||||
|
||||
### 3.3 预测
|
||||
|
||||
使用如下命令进行单张图片预测:
|
||||
|
||||
```bash linenums="1"
|
||||
# 注意将pretrained_model的路径设置为本地路径。
|
||||
python3 tools/infer_rec.py -c configs/rec/rec_r45_abinet.yml -o Global.infer_img='./doc/imgs_words_en/word_10.png' Global.pretrained_model=./rec_r45_abinet_train/best_accuracy
|
||||
# 预测文件夹下所有图像时,可修改infer_img为文件夹,如 Global.infer_img='./doc/imgs_words_en/'。
|
||||
```
|
||||
|
||||
## 4. 推理部署
|
||||
|
||||
### 4.1 Python推理
|
||||
|
||||
首先将训练得到best模型,转换成inference model。这里以训练完成的模型为例([模型下载地址](https://paddleocr.bj.bcebos.com/rec_r45_abinet_train.tar) ),可以使用如下命令进行转换:
|
||||
|
||||
```bash linenums="1"
|
||||
# 注意将pretrained_model的路径设置为本地路径。
|
||||
python3 tools/export_model.py -c configs/rec/rec_r45_abinet.yml -o Global.pretrained_model=./rec_r45_abinet_train/best_accuracy Global.save_inference_dir=./inference/rec_r45_abinet/
|
||||
```
|
||||
|
||||
**注意:**
|
||||
|
||||
- 如果您是在自己的数据集上训练的模型,并且调整了字典文件,请注意修改配置文件中的`character_dict_path`是否是所需要的字典文件。
|
||||
- 如果您修改了训练时的输入大小,请修改`tools/export_model.py`文件中的对应ABINet的`infer_shape`。
|
||||
|
||||
转换成功后,在目录下有三个文件:
|
||||
|
||||
```text linenums="1"
|
||||
/inference/rec_r45_abinet/
|
||||
├── inference.pdiparams # 识别inference模型的参数文件
|
||||
├── inference.pdiparams.info # 识别inference模型的参数信息,可忽略
|
||||
└── inference.pdmodel # 识别inference模型的program文件
|
||||
```
|
||||
|
||||
执行如下命令进行模型推理:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_rec.py --image_dir='./doc/imgs_words_en/word_10.png' --rec_model_dir='./inference/rec_r45_abinet/' --rec_algorithm='ABINet' --rec_image_shape='3,32,128' --rec_char_dict_path='./ppocr/utils/ic15_dict.txt'
|
||||
# 预测文件夹下所有图像时,可修改image_dir为文件夹,如 --image_dir='./doc/imgs_words_en/'。
|
||||
```
|
||||
|
||||

|
||||
|
||||
执行命令后,上面图像的预测结果(识别的文本和得分)会打印到屏幕上,示例如下:
|
||||
结果如下:
|
||||
|
||||
```bash linenums="1"
|
||||
Predicts of ./doc/imgs_words_en/word_10.png:('pain', 0.9999995231628418)
|
||||
```
|
||||
|
||||
**注意**:
|
||||
|
||||
- 训练上述模型采用的图像分辨率是[3,32,128],需要通过参数`rec_image_shape`设置为您训练时的识别图像形状。
|
||||
- 在推理时需要设置参数`rec_char_dict_path`指定字典,如果您修改了字典,请修改该参数为您的字典文件。
|
||||
- 如果您修改了预处理方法,需修改`tools/infer/predict_rec.py`中ABINet的预处理为您的预处理方法。
|
||||
|
||||
### 4.2 C++推理部署
|
||||
|
||||
由于C++预处理后处理还未支持ABINet,所以暂未支持
|
||||
|
||||
### 4.3 Serving服务化部署
|
||||
|
||||
暂不支持
|
||||
|
||||
### 4.4 更多推理部署
|
||||
|
||||
暂不支持
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
1. MJSynth和SynthText两种数据集来自于[ABINet源repo](https://github.com/FangShancheng/ABINet) 。
|
||||
2. 我们使用ABINet作者提供的预训练模型进行finetune训练。
|
||||
|
||||
## 引用
|
||||
|
||||
```bibtex
|
||||
@article{Fang2021ABINet,
|
||||
title = {ABINet: Read Like Humans: Autonomous, Bidirectional and Iterative Language Modeling for Scene Text Recognition},
|
||||
author = {Shancheng Fang and Hongtao Xie and Yuxin Wang and Zhendong Mao and Yongdong Zhang},
|
||||
booktitle = {CVPR},
|
||||
year = {2021},
|
||||
url = {https://arxiv.org/abs/2103.06495},
|
||||
pages = {7098-7107}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,99 @@
|
||||
---
|
||||
comments: true
|
||||
---
|
||||
|
||||
# STAR-Net
|
||||
|
||||
## 1. Introduction
|
||||
|
||||
Paper:
|
||||
> [STAR-Net: a spatial attention residue network for scene text recognition.](https://www.bmva-archive.org.uk/bmvc/2016/papers/paper043/paper043.pdf)
|
||||
> Wei Liu, Chaofeng Chen, Kwan-Yee K. Wong, Zhizhong Su and Junyu Han.
|
||||
> BMVC, pages 43.1-43.13, 2016
|
||||
|
||||
Using MJSynth and SynthText two text recognition datasets for training, and evaluating on IIIT, SVT, IC03, IC13, IC15, SVTP, CUTE datasets, the algorithm reproduction effect is as follows:
|
||||
|
||||
|Model|Backbone|ACC|config|Download link|
|
||||
| --- | --- | --- | --- | --- |
|
||||
|---|---|---|---|---|
|
||||
|StarNet|Resnet34_vd|84.44%|[configs/rec/rec_r34_vd_tps_bilstm_ctc.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/rec/rec_r34_vd_tps_bilstm_ctc.yml)|[训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_r34_vd_tps_bilstm_ctc_v2.0_train.tar)|
|
||||
|StarNet|MobileNetV3|81.42%|[configs/rec/rec_mv3_tps_bilstm_ctc.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/rec/rec_mv3_tps_bilstm_ctc.yml)|[训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_mv3_tps_bilstm_ctc_v2.0_train.tar)|
|
||||
|
||||
## 2. Environment
|
||||
|
||||
Please refer to ["Environment Preparation"](../../ppocr/environment.en.md) to configure the PaddleOCR environment, and refer to ["Project Clone"](../../ppocr/blog/clone.en.md)to clone the project code.
|
||||
|
||||
## 3. Model Training / Evaluation / Prediction
|
||||
|
||||
Please refer to [Text Recognition Tutorial](../../ppocr/model_train/recognition.en.md). PaddleOCR modularizes the code, and training different recognition models only requires **changing the configuration file**.
|
||||
|
||||
### Training
|
||||
|
||||
Specifically, after the data preparation is completed, the training can be started. The training command is as follows:
|
||||
|
||||
```bash linenums="1"
|
||||
# Single GPU training (long training period, not recommended)
|
||||
python3 tools/train.py -c configs/rec/rec_r34_vd_tps_bilstm_ctc.yml
|
||||
|
||||
# Multi GPU training, specify the gpu number through the --gpus parameter
|
||||
python3 -m paddle.distributed.launch --gpus '0,1,2,3' tools/train.py -c rec_r34_vd_tps_bilstm_ctc.yml
|
||||
```
|
||||
|
||||
### Evaluation
|
||||
|
||||
```bash linenums="1"
|
||||
# GPU evaluation
|
||||
python3 -m paddle.distributed.launch --gpus '0' tools/eval.py -c configs/rec/rec_r34_vd_tps_bilstm_ctc.yml -o Global.pretrained_model={path/to/weights}/best_accuracy
|
||||
```
|
||||
|
||||
### Prediction
|
||||
|
||||
```bash linenums="1"
|
||||
# The configuration file used for prediction must match the training
|
||||
python3 tools/infer_rec.py -c configs/rec/rec_r34_vd_tps_bilstm_ctc.yml -o Global.pretrained_model={path/to/weights}/best_accuracy Global.infer_img=doc/imgs_words/en/word_1.png
|
||||
```
|
||||
|
||||
## 4. Inference and Deployment
|
||||
|
||||
### 4.1 Python Inference
|
||||
|
||||
First, the model saved during the STAR-Net text recognition training process is converted into an inference model. ( [Model download link](https://paddleocr.bj.bcebos.com/dygraph_v2.1/rec/rec_r31_STAR-Net_train.tar) ), you can use the following command to convert:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/export_model.py -c configs/rec/rec_r34_vd_tps_bilstm_ctc.yml -o Global.pretrained_model=./rec_r34_vd_tps_bilstm_ctc_v2.0_train/best_accuracy Global.save_inference_dir=./inference/rec_starnet
|
||||
```
|
||||
|
||||
For STAR-Net text recognition model inference, the following commands can be executed:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_rec.py --image_dir="./doc/imgs_words_en/word_336.png" --rec_model_dir="./inference/rec_starnet/" --rec_image_shape="3, 32, 100" --rec_char_dict_path="./ppocr/utils/ic15_dict.txt"
|
||||
```
|
||||
|
||||
### 4.2 C++ Inference
|
||||
|
||||
With the inference model prepared, refer to the [cpp infer](../../../version2.x/legacy/cpp_infer.en.md) tutorial for C++ inference.
|
||||
|
||||
### 4.3 Serving
|
||||
|
||||
With the inference model prepared, refer to the [pdserving](../../../version2.x/legacy/paddle_server.en.md) tutorial for service deployment by Paddle Serving.
|
||||
|
||||
### 4.4 More
|
||||
|
||||
More deployment schemes supported for STAR-Net:
|
||||
|
||||
- Paddle2ONNX: with the inference model prepared, please refer to the [paddle2onnx](../../../version2.x/legacy/paddle2onnx.en.md) tutorial.
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
## Citation
|
||||
|
||||
```bibtex
|
||||
@inproceedings{liu2016star,
|
||||
title={STAR-Net: a spatial attention residue network for scene text recognition.},
|
||||
author={Liu, Wei and Chen, Chaofeng and Wong, Kwan-Yee K and Su, Zhizhong and Han, Junyu},
|
||||
booktitle={BMVC},
|
||||
volume={2},
|
||||
pages={7},
|
||||
year={2016}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,150 @@
|
||||
---
|
||||
comments: true
|
||||
---
|
||||
|
||||
# CPPD
|
||||
|
||||
## 1. Introduction
|
||||
|
||||
Paper:
|
||||
> [Context Perception Parallel Decoder for Scene Text Recognition](https://arxiv.org/abs/2307.12270)
|
||||
> Yongkun Du and Zhineng Chen and Caiyan Jia and Xiaoting Yin and Chenxia Li and Yuning Du and Yu-Gang Jiang
|
||||
|
||||
Scene text recognition models based on deep learning typically follow an Encoder-Decoder structure, where the decoder can be categorized into two types: (1) CTC and (2) Attention-based. Currently, most state-of-the-art (SOTA) models use an Attention-based decoder, which can be further divided into AR and PD types. In general, AR decoders achieve higher recognition accuracy than PD, while PD decoders are faster than AR. CPPD, with carefully designed CO and CC modules, achieves a balance between the accuracy of AR and the speed of PD.
|
||||
|
||||
The accuracy (%) and model files of CPPD on the public dataset of scene text recognition are as follows::
|
||||
|
||||
* English dataset from [PARSeq](https://github.com/baudm/parseq).
|
||||
|
||||
| Model |IC13<br/>857 | SVT |IIIT5k<br/>3000 |IC15<br/>1811| SVTP |CUTE80 | Avg | Download |
|
||||
|:----------:|:------:|:-----:|:---------:|:------:|:-----:|:-----:|:-----:|:-------:|
|
||||
| CPPD Tiny | 97.1 | 94.4 | 96.6 | 86.6 | 88.5 | 90.3 | 92.25 | [en](https://paddleocr.bj.bcebos.com/CCPD/rec_svtr_cppd_tiny_en_train.tar) |
|
||||
| CPPD Base | 98.2 | 95.5 | 97.6 | 87.9 | 90.0 | 92.7 | 93.80 | [en](https://paddleocr.bj.bcebos.com/CCPD/rec_svtr_cppd_base_en_train.tar)|
|
||||
| CPPD Base 48*160 | 97.5 | 95.5 | 97.7 | 87.7 | 92.4 | 93.7 | 94.10 | [en](https://paddleocr.bj.bcebos.com/CCPD/rec_svtr_cppd_base_48_160_en_train.tar) |
|
||||
|
||||
* Trained on Synth dataset(MJ+ST), Test on Union14M-L benchmark from [U14m](https://github.com/Mountchicken/Union14M/).
|
||||
|
||||
| Model |Curve | Multi-<br/>Oriented |Artistic |Contextless| Salient | Multi-<br/>word | General | Avg | Download |
|
||||
|:----------:|:------:|:-----:|:---------:|:------:|:-----:|:-----:|:-----:|:-------:|:-------:|
|
||||
| CPPD Tiny | 52.4 | 12.3 | 48.2 | 54.4 | 61.5 | 53.4 | 61.4 | 49.10 | Same as the table above. |
|
||||
| CPPD Base | 65.5 | 18.6 | 56.0 | 61.9 | 71.0 | 57.5 | 65.8 | 56.63 | Same as the table above. |
|
||||
| CPPD Base 48*160 | 71.9 | 22.1 | 60.5 | 67.9 | 78.3 | 63.9 | 67.1 | 61.69 | Same as the table above. |
|
||||
|
||||
* Trained on Union14M-L training dataset.
|
||||
|
||||
| Model |IC13<br/>857 | SVT |IIIT5k<br/>3000 |IC15<br/>1811| SVTP |CUTE80 | Avg | Download |
|
||||
|:----------:|:------:|:-----:|:---------:|:------:|:-----:|:-----:|:-----:|:-------:|
|
||||
| CPPD Base 32*128 | 98.7 | 98.5 | 99.4 | 91.7 | 96.7 | 99.7 | 97.44 | [en](https://paddleocr.bj.bcebos.com/CCPD/rec_svtr_cppd_base_u14m_train.tar) |
|
||||
|
||||
| Model |Curve | Multi-<br/>Oriented |Artistic |Contextless| Salient | Multi-<br/>word | General | Avg | Download |
|
||||
|:----------:|:------:|:-----:|:---------:|:------:|:-----:|:-----:|:-----:|:-------:|:-------:|
|
||||
| CPPD Base 32*128 | 87.5 | 70.7 | 78.2 | 82.9 | 85.5 | 85.4 | 84.3 | 82.08 | Same as the table above. |
|
||||
|
||||
* Chinese dataset from [Chinese Benchmark](https://github.com/FudanVI/benchmarking-chinese-text-recognition).
|
||||
|
||||
| Model | Scene | Web | Document | Handwriting | Avg | Download |
|
||||
|:----------:|:------:|:-----:|:---------:|:------:|:-----:|:-----:|
|
||||
| CPPD Base | 74.4 | 76.1 | 98.6 | 55.3 | 76.10 | [ch](https://paddleocr.bj.bcebos.com/CCPD/rec_svtr_cppd_base_ch_train.tar) |
|
||||
| CPPD Base + STN | 78.4 | 79.3 | 98.9 | 57.6 | 78.55 | [ch](https://paddleocr.bj.bcebos.com/CCPD/rec_svtr_cppd_base_stn_ch_train.tar) |
|
||||
|
||||
## 2. Environment
|
||||
|
||||
Please refer to ["Environment Preparation"](../../ppocr/environment.en.md) to configure the PaddleOCR environment, and refer to ["Project Clone"](../../ppocr/blog/clone.en.md)to clone the project code.
|
||||
|
||||
### Dataset Preparation
|
||||
|
||||
[English dataset download](https://github.com/baudm/parseq)
|
||||
[Union14M-Benchmark download](https://github.com/Mountchicken/Union14M)
|
||||
[Chinese dataset download](https://github.com/fudanvi/benchmarking-chinese-text-recognition#download)
|
||||
|
||||
## 3. Model Training / Evaluation / Prediction
|
||||
|
||||
Please refer to [Text Recognition Tutorial](../../ppocr/model_train/recognition.en.md). PaddleOCR modularizes the code, and training different recognition models only requires **changing the configuration file**.
|
||||
|
||||
### Training
|
||||
|
||||
Specifically, after the data preparation is completed, the training can be started. The training command is as follows:
|
||||
|
||||
```bash linenums="1"
|
||||
# Single GPU training (long training period, not recommended)
|
||||
python3 tools/train.py -c configs/rec/rec_svtrnet_cppd_base_en.yml
|
||||
|
||||
# Multi GPU training, specify the gpu number through the --gpus parameter
|
||||
python3 -m paddle.distributed.launch --gpus '0,1,2,3' tools/train.py -c configs/rec/rec_svtrnet_cppd_base_en.yml
|
||||
```
|
||||
|
||||
### Evaluation
|
||||
|
||||
You can download the model files and configuration files provided by `CPPD`: [download link](https://paddleocr.bj.bcebos.com/CCPD/rec_svtr_cppd_base_en_train.tar), take `CPPD-B` as an example, using the following command to evaluate:
|
||||
|
||||
```bash linenums="1"
|
||||
# Download the tar archive containing the model files and configuration files of CPPD-B and extract it
|
||||
wget https://paddleocr.bj.bcebos.com/CCPD/rec_svtr_cppd_base_en_train.tar && tar xf rec_svtr_cppd_base_en_train.tar
|
||||
# GPU evaluation
|
||||
python3 -m paddle.distributed.launch --gpus '0' tools/eval.py -c ./rec_svtr_cppd_base_en_train/rec_svtrnet_cppd_base_en.yml -o Global.pretrained_model=./rec_svtr_cppd_base_en_train/best_model
|
||||
```
|
||||
|
||||
### Prediction
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer_rec.py -c ./rec_svtr_cppd_base_en_train/rec_svtrnet_cppd_base_en.yml -o Global.infer_img='./doc/imgs_words_en/word_10.png' Global.pretrained_model=./rec_svtr_cppd_base_en_train/best_model
|
||||
```
|
||||
|
||||
## 4. Inference and Deployment
|
||||
|
||||
### 4.1 Python Inference
|
||||
|
||||
First, the model saved during the CPPD text recognition training process is converted into an inference model. ( [Model download link](https://paddleocr.bj.bcebos.com/CCPD/rec_svtr_cppd_base_en_train.tar) ), you can use the following command to convert:
|
||||
|
||||
```bash linenums="1"
|
||||
# export model
|
||||
# en
|
||||
python3 tools/export_model.py -c configs/rec/rec_svtrnet_cppd_base_en.yml -o Global.pretrained_model=./rec_svtr_cppd_base_en_train/best_model.pdparams Global.save_inference_dir=./rec_svtr_cppd_base_en_infer
|
||||
# ch
|
||||
python3 tools/export_model.py -c configs/rec/rec_svtrnet_cppd_base_ch.yml -o Global.pretrained_model=./rec_svtr_cppd_base_ch_train/best_model.pdparams Global.save_inference_dir=./rec_svtr_cppd_base_ch_infer
|
||||
|
||||
# speed test
|
||||
# docker image https://hub.docker.com/r/paddlepaddle/paddle/tags/: sudo docker pull paddlepaddle/paddle:2.4.2-gpu-cuda11.2-cudnn8.2-trt8.0
|
||||
# install auto_log: pip install https://paddleocr.bj.bcebos.com/libs/auto_log-1.2.0-py3-none-any.whl
|
||||
# en
|
||||
python3 tools/infer/predict_rec.py --image_dir='../iiik' --rec_model_dir='./rec_svtr_cppd_base_en_infer/' --rec_algorithm='CPPD' --rec_image_shape='3,32,100' --rec_char_dict_path='./ppocr/utils/ic15_dict.txt' --warmup=True --benchmark=True --rec_batch_num=1 --use_tensorrt=True
|
||||
# ch
|
||||
python3 tools/infer/predict_rec.py --image_dir='../iiik' --rec_model_dir='./rec_svtr_cppd_base_ch_infer/' --rec_algorithm='CPPDPadding' --rec_image_shape='3,32,256' --warmup=True --benchmark=True --rec_batch_num=1 --use_tensorrt=True
|
||||
# stn_ch
|
||||
python3 tools/infer/predict_rec.py --image_dir='../iiik' --rec_model_dir='./rec_svtr_cppd_base_stn_ch_infer/' --rec_algorithm='CPPD' --rec_image_shape='3,64,256' --warmup=True --benchmark=True --rec_batch_num=1 --use_tensorrt=True
|
||||
```
|
||||
|
||||
**Note:** If you are training the model on your own dataset and have modified the dictionary file, please pay attention to modify the `character_dict_path` in the configuration file to the modified dictionary file.
|
||||
|
||||
After the conversion is successful, there are three files in the directory:
|
||||
|
||||
```text linenums="1"
|
||||
/inference/rec_svtr_cppd_base_en_infer/
|
||||
├── inference.pdiparams
|
||||
├── inference.pdiparams.info
|
||||
└── inference.pdmodel
|
||||
```
|
||||
|
||||
### 4.2 C++ Inference
|
||||
|
||||
Not supported
|
||||
|
||||
### 4.3 Serving
|
||||
|
||||
Not supported
|
||||
|
||||
### 4.4 More
|
||||
|
||||
Not supported
|
||||
|
||||
## Citation
|
||||
|
||||
```bibtex
|
||||
@article{Du2023CPPD,
|
||||
title = {Context Perception Parallel Decoder for Scene Text Recognition},
|
||||
author = {Du, Yongkun and Chen, Zhineng and Jia, Caiyan and Yin, Xiaoting and Li, Chenxia and Du, Yuning and Jiang, Yu-Gang},
|
||||
booktitle = {Arxiv},
|
||||
year = {2023},
|
||||
url = {https://arxiv.org/abs/2307.12270}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,175 @@
|
||||
---
|
||||
comments: true
|
||||
---
|
||||
|
||||
# 场景文本识别算法-CPPD
|
||||
|
||||
## 1. 算法简介
|
||||
|
||||
论文信息:
|
||||
> [Context Perception Parallel Decoder for Scene Text Recognition](https://arxiv.org/abs/2307.12270)
|
||||
> Yongkun Du and Zhineng Chen and Caiyan Jia and Xiaoting Yin and Chenxia Li and Yuning Du and Yu-Gang Jiang
|
||||
|
||||
### CPPD算法简介
|
||||
|
||||
基于深度学习的场景文本识别模型通常是Encoder-Decoder结构,其中decoder可以分为两种:(1)CTC,(2)Attention-based。目前SOTA模型大多使用Attention-based的decoder,而attention-based可以分为AR和PD两种,一般来说,AR解码器识别精度优于PD,而PD解码速度快于AR,CPPD通过精心设计的CO和CC模块,达到了“AR的精度,PD的速度”的效果。
|
||||
|
||||
CPPD在场景文本识别公开数据集上的精度(%)和模型文件如下:
|
||||
|
||||
* 英文训练集和测试集来自于[PARSeq](https://github.com/baudm/parseq)。
|
||||
|
||||
| 模型 |IC13<br/>857 | SVT |IIIT5k<br/>3000 |IC15<br/>1811| SVTP |CUTE80 | Avg | 下载链接 |
|
||||
|:----------:|:------:|:-----:|:---------:|:------:|:-----:|:-----:|:-----:|:-------:|
|
||||
| CPPD Tiny | 97.1 | 94.4 | 96.6 | 86.6 | 88.5 | 90.3 | 92.25 | [英文](https://paddleocr.bj.bcebos.com/CCPD/rec_svtr_cppd_tiny_en_train.tar) |
|
||||
| CPPD Base | 98.2 | 95.5 | 97.6 | 87.9 | 90.0 | 92.7 | 93.80 | [英文](https://paddleocr.bj.bcebos.com/CCPD/rec_svtr_cppd_base_en_train.tar)|
|
||||
| CPPD Base 48*160 | 97.5 | 95.5 | 97.7 | 87.7 | 92.4 | 93.7 | 94.10 | [英文](https://paddleocr.bj.bcebos.com/CCPD/rec_svtr_cppd_base_48_160_en_train.tar) |
|
||||
|
||||
* 英文合成数据集(MJ+ST)训练,英文Union14M-L benchmark测试结果[U14m](https://github.com/Mountchicken/Union14M/)。
|
||||
|
||||
| 模型 |Curve | Multi-<br/>Oriented |Artistic |Contextless| Salient | Multi-<br/>word | General | Avg | 下载链接 |
|
||||
|:----------:|:------:|:-----:|:---------:|:------:|:-----:|:-----:|:-----:|:-------:|:-------:|
|
||||
| CPPD Tiny | 52.4 | 12.3 | 48.2 | 54.4 | 61.5 | 53.4 | 61.4 | 49.10 | 同上表 |
|
||||
| CPPD Base | 65.5 | 18.6 | 56.0 | 61.9 | 71.0 | 57.5 | 65.8 | 56.63 | 同上表 |
|
||||
| CPPD Base 48*160 | 71.9 | 22.1 | 60.5 | 67.9 | 78.3 | 63.9 | 67.1 | 61.69 | 同上表 |
|
||||
|
||||
* Union14M-L 训练集From scratch训练,英文测试结果。
|
||||
|
||||
| 模型 |IC13<br/>857 | SVT |IIIT5k<br/>3000 |IC15<br/>1811| SVTP |CUTE80 | Avg | 下载链接 |
|
||||
|:----------:|:------:|:-----:|:---------:|:------:|:-----:|:-----:|:-----:|:-------:|
|
||||
| CPPD Base 32*128 | 98.5 | 97.7 | 99.2 | 90.3 | 94.6 | 98.3 | 96.42 | Coming soon |
|
||||
|
||||
| 模型 |Curve | Multi-<br/>Oriented |Artistic |Contextless| Salient | Multi-<br/>word | General | Avg | 下载链接 |
|
||||
|:----------:|:------:|:-----:|:---------:|:------:|:-----:|:-----:|:-----:|:-------:|:-------:|
|
||||
| CPPD Base 32*128 | 83.0 | 71.2 | 75.1 | 80.9 | 79.4 | 82.6 | 83.7 | 79.41 | Coming soon |
|
||||
|
||||
* 加载合成数据集预训练模型,Union14M-L 训练集微调训练,英文测试结果。
|
||||
|
||||
| 模型 |IC13<br/>857 | SVT |IIIT5k<br/>3000 |IC15<br/>1811| SVTP |CUTE80 | Avg | 下载链接 |
|
||||
|:----------:|:------:|:-----:|:---------:|:------:|:-----:|:-----:|:-----:|:-------:|
|
||||
| CPPD Base 32*128 | 98.7 | 98.5 | 99.4 | 91.7 | 96.7 | 99.7 | 97.44 | [英文](https://paddleocr.bj.bcebos.com/CCPD/rec_svtr_cppd_base_u14m_train.tar) |
|
||||
|
||||
| 模型 |Curve | Multi-<br/>Oriented |Artistic |Contextless| Salient | Multi-<br/>word | General | Avg | 下载链接 |
|
||||
|:----------:|:------:|:-----:|:---------:|:------:|:-----:|:-----:|:-----:|:-------:|:-------:|
|
||||
| CPPD Base 32*128 | 87.5 | 70.7 | 78.2 | 82.9 | 85.5 | 85.4 | 84.3 | 82.08 | 同上表 |
|
||||
|
||||
* 中文训练集和测试集来自于[Chinese Benchmark](https://github.com/FudanVI/benchmarking-chinese-text-recognition)。
|
||||
|
||||
| 模型 | Scene | Web | Document | Handwriting | Avg | 下载链接 |
|
||||
|:----------:|:------:|:-----:|:---------:|:------:|:-----:|:-----:|
|
||||
| CPPD Base | 74.4 | 76.1 | 98.6 | 55.3 | 76.10 | [中文](https://paddleocr.bj.bcebos.com/CCPD/rec_svtr_cppd_base_ch_train.tar) |
|
||||
| CPPD Base + STN | 78.4 | 79.3 | 98.9 | 57.6 | 78.55 | [中文](https://paddleocr.bj.bcebos.com/CCPD/rec_svtr_cppd_base_stn_ch_train.tar) |
|
||||
|
||||
## 2. 环境配置
|
||||
|
||||
请先参考[《运行环境准备》](../../ppocr/environment.md)配置PaddleOCR运行环境,参考[《项目克隆》](../../ppocr/blog/clone.md)克隆项目代码。
|
||||
|
||||
## 3. 模型训练、评估、预测
|
||||
|
||||
### 3.1 模型训练
|
||||
|
||||
#### 数据集准备
|
||||
|
||||
[英文数据集下载](https://github.com/baudm/parseq)
|
||||
|
||||
[Union14M-L 下载](https://github.com/Mountchicken/Union14M)
|
||||
|
||||
[中文数据集下载](https://github.com/fudanvi/benchmarking-chinese-text-recognition#download)
|
||||
|
||||
#### 启动训练
|
||||
|
||||
请参考[文本识别训练教程](../../ppocr/model_train/recognition.md)。PaddleOCR对代码进行了模块化,训练`CPPD`识别模型时需要**更换配置文件**为`CPPD`的[配置文件](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/rec/rec_svtrnet_cppd_base_en.yml)。
|
||||
|
||||
具体地,在完成数据准备后,便可以启动训练,训练命令如下:
|
||||
|
||||
```bash linenums="1"
|
||||
#单卡训练(训练周期长,不建议)
|
||||
python3 tools/train.py -c configs/rec/rec_svtrnet_cppd_base_en.yml
|
||||
|
||||
# 多卡训练,通过--gpus参数指定卡号
|
||||
python3 -m paddle.distributed.launch --gpus '0,1,2,3' tools/train.py -c configs/rec/rec_svtrnet_cppd_base_en.yml
|
||||
```
|
||||
|
||||
### 3.2 评估
|
||||
|
||||
可下载`CPPD`提供的模型文件和配置文件:[下载地址](https://paddleocr.bj.bcebos.com/CCPD/rec_svtr_cppd_base_en_train.tar) ,以`CPPD-B`为例,使用如下命令进行评估:
|
||||
|
||||
```bash linenums="1"
|
||||
# 下载包含CPPD-B的模型文件和配置文件的tar压缩包并解压
|
||||
wget https://paddleocr.bj.bcebos.com/CCPD/rec_svtr_cppd_base_en_train.tar && tar xf rec_svtr_cppd_base_en_train.tar
|
||||
# 注意将pretrained_model的路径设置为本地路径。
|
||||
python3 -m paddle.distributed.launch --gpus '0' tools/eval.py -c ./rec_svtr_cppd_base_en_train/rec_svtrnet_cppd_base_en.yml -o Global.pretrained_model=./rec_svtr_cppd_base_en_train/best_model
|
||||
```
|
||||
|
||||
### 3.3 预测
|
||||
|
||||
使用如下命令进行单张图片预测:
|
||||
|
||||
```bash linenums="1"
|
||||
# 注意将pretrained_model的路径设置为本地路径。
|
||||
python3 tools/infer_rec.py -c ./rec_svtr_cppd_base_en_train/rec_svtrnet_cppd_base_en.yml -o Global.infer_img='./doc/imgs_words_en/word_10.png' Global.pretrained_model=./rec_svtr_cppd_base_en_train/best_model
|
||||
# 预测文件夹下所有图像时,可修改infer_img为文件夹,如 Global.infer_img='./doc/imgs_words_en/'。
|
||||
```
|
||||
|
||||
## 4. 推理部署
|
||||
|
||||
### 4.1 Python推理
|
||||
|
||||
首先将训练得到best模型,转换成inference model。下面以基于`CPPD-B`,在英文数据集训练的模型为例([模型和配置文件下载地址](https://paddleocr.bj.bcebos.com/CCPD/rec_svtr_cppd_base_en_train.tar),可以使用如下命令进行转换:
|
||||
|
||||
**注意:**
|
||||
|
||||
* 如果您是在自己的数据集上训练的模型,并且调整了字典文件,请注意修改配置文件中的`character_dict_path`是否为所正确的字典文件。
|
||||
|
||||
执行如下命令进行模型导出和推理:
|
||||
|
||||
```bash linenums="1"
|
||||
# 注意将pretrained_model的路径设置为本地路径。
|
||||
# export model
|
||||
# en
|
||||
python3 tools/export_model.py -c configs/rec/rec_svtrnet_cppd_base_en.yml -o Global.pretrained_model=./rec_svtr_cppd_base_en_train/best_model.pdparams Global.save_inference_dir=./rec_svtr_cppd_base_en_infer
|
||||
# ch
|
||||
python3 tools/export_model.py -c configs/rec/rec_svtrnet_cppd_base_ch.yml -o Global.pretrained_model=./rec_svtr_cppd_base_ch_train/best_model.pdparams Global.save_inference_dir=./rec_svtr_cppd_base_ch_infer
|
||||
|
||||
# speed test
|
||||
# docker image https://hub.docker.com/r/paddlepaddle/paddle/tags/: sudo docker pull paddlepaddle/paddle:2.4.2-gpu-cuda11.2-cudnn8.2-trt8.0
|
||||
# install auto_log: pip install https://paddleocr.bj.bcebos.com/libs/auto_log-1.2.0-py3-none-any.whl
|
||||
# en
|
||||
python3 tools/infer/predict_rec.py --image_dir='../iiik' --rec_model_dir='./rec_svtr_cppd_base_en_infer/' --rec_algorithm='CPPD' --rec_image_shape='3,32,100' --rec_char_dict_path='./ppocr/utils/ic15_dict.txt' --warmup=True --benchmark=True --rec_batch_num=1 --use_tensorrt=True
|
||||
# ch
|
||||
python3 tools/infer/predict_rec.py --image_dir='../iiik' --rec_model_dir='./rec_svtr_cppd_base_ch_infer/' --rec_algorithm='CPPDPadding' --rec_image_shape='3,32,256' --warmup=True --benchmark=True --rec_batch_num=1 --use_tensorrt=True
|
||||
# stn_ch
|
||||
python3 tools/infer/predict_rec.py --image_dir='../iiik' --rec_model_dir='./rec_svtr_cppd_base_stn_ch_infer/' --rec_algorithm='CPPD' --rec_image_shape='3,64,256' --warmup=True --benchmark=True --rec_batch_num=1 --use_tensorrt=True
|
||||
```
|
||||
|
||||
导出成功后,在目录下有三个文件:
|
||||
|
||||
```
|
||||
/inference/rec_svtr_cppd_base_en_infer/
|
||||
├── inference.pdiparams # 识别inference模型的参数文件
|
||||
├── inference.pdiparams.info # 识别inference模型的参数信息,可忽略
|
||||
└── inference.pdmodel # 识别inference模型的program文件
|
||||
```
|
||||
|
||||
### 4.2 C++推理部署
|
||||
|
||||
由于C++预处理后处理还未支持CPPD,所以暂未支持
|
||||
|
||||
### 4.3 Serving服务化部署
|
||||
|
||||
暂不支持
|
||||
|
||||
### 4.4 更多推理部署
|
||||
|
||||
暂不支持
|
||||
|
||||
## 引用
|
||||
|
||||
```bibtex
|
||||
@article{Du2023CPPD,
|
||||
title = {Context Perception Parallel Decoder for Scene Text Recognition},
|
||||
author = {Du, Yongkun and Chen, Zhineng and Jia, Caiyan and Yin, Xiaoting and Li, Chenxia and Du, Yuning and Jiang, Yu-Gang},
|
||||
booktitle = {Arxiv},
|
||||
year = {2023},
|
||||
url = {https://arxiv.org/abs/2307.12270}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,102 @@
|
||||
---
|
||||
comments: true
|
||||
---
|
||||
|
||||
# CRNN
|
||||
|
||||
## 1. Introduction
|
||||
|
||||
Paper:
|
||||
> [An End-to-End Trainable Neural Network for Image-based Sequence Recognition and Its Application to Scene Text Recognition](https://arxiv.org/abs/1507.05717)
|
||||
|
||||
> Baoguang Shi, Xiang Bai, Cong Yao
|
||||
|
||||
> IEEE, 2015
|
||||
|
||||
Using MJSynth and SynthText two text recognition datasets for training, and evaluating on IIIT, SVT, IC03, IC13, IC15, SVTP, CUTE datasets, the algorithm reproduction effect is as follows:
|
||||
|
||||
|Model|Backbone|ACC|config|Download link|
|
||||
| --- | --- | --- | --- | --- |
|
||||
|---|---|---|---|---|
|
||||
|CRNN|Resnet34_vd|81.04%|[configs/rec/rec_r34_vd_none_bilstm_ctc.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/rec/rec_r34_vd_none_bilstm_ctc.yml)|[训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_r34_vd_none_bilstm_ctc_v2.0_train.tar)|
|
||||
|CRNN|MobileNetV3|77.95%|[configs/rec/rec_mv3_none_bilstm_ctc.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/rec/rec_mv3_none_bilstm_ctc.yml)|[训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_mv3_none_bilstm_ctc_v2.0_train.tar)|
|
||||
|
||||
## 2. Environment
|
||||
|
||||
Please refer to ["Environment Preparation"](../../ppocr/environment.en.md) to configure the PaddleOCR environment, and refer to ["Project Clone"](../../ppocr/blog/clone.en.md)to clone the project code.
|
||||
|
||||
## 3. Model Training / Evaluation / Prediction
|
||||
|
||||
Please refer to [Text Recognition Tutorial](../../ppocr/model_train/recognition.en.md). PaddleOCR modularizes the code, and training different recognition models only requires **changing the configuration file**.
|
||||
|
||||
### Training
|
||||
|
||||
Specifically, after the data preparation is completed, the training can be started. The training command is as follows:
|
||||
|
||||
```bash linenums="1"
|
||||
# Single GPU training (long training period, not recommended)
|
||||
python3 tools/train.py -c configs/rec/rec_r34_vd_none_bilstm_ctc.yml
|
||||
|
||||
# Multi GPU training, specify the gpu number through the --gpus parameter
|
||||
python3 -m paddle.distributed.launch --gpus '0,1,2,3' tools/train.py -c configs/rec/rec_r34_vd_none_bilstm_ctc.yml
|
||||
```
|
||||
|
||||
### Evaluation
|
||||
|
||||
```bash linenums="1"
|
||||
# GPU evaluation
|
||||
python3 -m paddle.distributed.launch --gpus '0' tools/eval.py -c configs/rec/rec_r34_vd_none_bilstm_ctc.yml -o Global.pretrained_model={path/to/weights}/best_accuracy
|
||||
```
|
||||
|
||||
### Prediction
|
||||
|
||||
```bash linenums="1"
|
||||
# The configuration file used for prediction must match the training
|
||||
python3 tools/infer_rec.py -c configs/rec/rec_r34_vd_none_bilstm_ctc.yml -o Global.pretrained_model={path/to/weights}/best_accuracy Global.infer_img=doc/imgs_words/en/word_1.png
|
||||
```
|
||||
|
||||
## 4. Inference and Deployment
|
||||
|
||||
### 4.1 Python Inference
|
||||
|
||||
First, the model saved during the CRNN text recognition training process is converted into an inference model. ( [Model download link](https://paddleocr.bj.bcebos.com/dygraph_v2.1/rec/rec_r31_CRNN_train.tar) ), you can use the following command to convert:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/export_model.py -c configs/rec/rec_r34_vd_none_bilstm_ctc.yml -o Global.pretrained_model=./rec_r34_vd_none_bilstm_ctc_v2.0_train/best_accuracy Global.save_inference_dir=./inference/rec_crnn
|
||||
```
|
||||
|
||||
For CRNN text recognition model inference, the following commands can be executed:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_rec.py --image_dir="./doc/imgs_words_en/word_336.png" --rec_model_dir="./inference/rec_crnn/" --rec_image_shape="3, 32, 100" --rec_char_dict_path="./ppocr/utils/ic15_dict.txt"
|
||||
```
|
||||
|
||||
### 4.2 C++ Inference
|
||||
|
||||
With the inference model prepared, refer to the [cpp infer](../../../version2.x/legacy/cpp_infer.en.md) tutorial for C++ inference.
|
||||
|
||||
### 4.3 Serving
|
||||
|
||||
With the inference model prepared, refer to the [pdserving](../../../version2.x/legacy/paddle_server.en.md) tutorial for service deployment by Paddle Serving.
|
||||
|
||||
### 4.4 More
|
||||
|
||||
More deployment schemes supported for CRNN:
|
||||
|
||||
- Paddle2ONNX: with the inference model prepared, please refer to the [paddle2onnx](../../../version2.x/legacy/paddle_server.en.md) tutorial.
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
## Citation
|
||||
|
||||
```bibtex
|
||||
@ARTICLE{7801919,
|
||||
author={Shi, Baoguang and Bai, Xiang and Yao, Cong},
|
||||
journal={IEEE Transactions on Pattern Analysis and Machine Intelligence},
|
||||
title={An End-to-End Trainable Neural Network for Image-Based Sequence Recognition and Its Application to Scene Text Recognition},
|
||||
year={2017},
|
||||
volume={39},
|
||||
number={11},
|
||||
pages={2298-2304},
|
||||
doi={10.1109/TPAMI.2016.2646371}}
|
||||
```
|
||||
@@ -0,0 +1,118 @@
|
||||
---
|
||||
typora-copy-images-to: images
|
||||
comments: true
|
||||
---
|
||||
|
||||
# CRNN
|
||||
|
||||
## 1. 算法简介
|
||||
|
||||
论文信息:
|
||||
> [An End-to-End Trainable Neural Network for Image-based Sequence Recognition and Its Application to Scene Text Recognition](https://arxiv.org/abs/1507.05717)
|
||||
> Baoguang Shi, Xiang Bai, Cong Yao
|
||||
> IEEE, 2015
|
||||
|
||||
参考[DTRB](https://arxiv.org/abs/1904.01906) 文字识别训练和评估流程,使用MJSynth和SynthText两个文字识别数据集训练,在IIIT, SVT, IC03, IC13, IC15, SVTP, CUTE数据集上进行评估,算法效果如下:
|
||||
|
||||
|模型|骨干网络|Avg Accuracy|配置文件|下载链接|
|
||||
|---|---|---|---|---|
|
||||
|CRNN|Resnet34_vd|81.04%|[configs/rec/rec_r34_vd_none_bilstm_ctc.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/rec/rec_r34_vd_none_bilstm_ctc.yml)|[训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_r34_vd_none_bilstm_ctc_v2.0_train.tar)|
|
||||
|CRNN|MobileNetV3|77.95%|[configs/rec/rec_mv3_none_bilstm_ctc.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/rec/rec_mv3_none_bilstm_ctc.yml)|[训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_mv3_none_bilstm_ctc_v2.0_train.tar)|
|
||||
|
||||
## 2. 环境配置
|
||||
|
||||
请先参考[《运行环境准备》](../../ppocr/environment.md)配置PaddleOCR运行环境,参考[《项目克隆》](../../ppocr/blog/clone.md)克隆项目代码。
|
||||
|
||||
## 3. 模型训练、评估、预测
|
||||
|
||||
请参考[文本识别训练教程](../../ppocr/model_train/recognition.md)。PaddleOCR对代码进行了模块化,训练不同的识别模型只需要**更换配置文件**即可。
|
||||
|
||||
### 训练
|
||||
|
||||
在完成数据准备后,便可以启动训练,训练命令如下:
|
||||
|
||||
```bash linenums="1"
|
||||
# 单卡训练(训练周期长,不建议)
|
||||
python3 tools/train.py -c configs/rec/rec_r34_vd_none_bilstm_ctc.yml
|
||||
|
||||
# 多卡训练,通过--gpus参数指定卡号
|
||||
python3 -m paddle.distributed.launch --gpus '0,1,2,3' tools/train.py -c rec_r34_vd_none_bilstm_ctc.yml
|
||||
```
|
||||
|
||||
### 评估
|
||||
|
||||
```bash linenums="1"
|
||||
# GPU 评估, Global.pretrained_model 为待测权重
|
||||
python3 -m paddle.distributed.launch --gpus '0' tools/eval.py -c configs/rec/rec_r34_vd_none_bilstm_ctc.yml -o Global.pretrained_model={path/to/weights}/best_accuracy
|
||||
```
|
||||
|
||||
### 预测
|
||||
|
||||
```bash linenums="1"
|
||||
# 预测使用的配置文件必须与训练一致
|
||||
python3 tools/infer_rec.py -c configs/rec/rec_r34_vd_none_bilstm_ctc.yml -o Global.pretrained_model={path/to/weights}/best_accuracy Global.infer_img=doc/imgs_words/en/word_1.png
|
||||
```
|
||||
|
||||
## 4. 推理部署
|
||||
|
||||
### 4.1 Python推理
|
||||
|
||||
首先将 CRNN 文本识别训练过程中保存的模型,转换成inference model。以基于Resnet34_vd骨干网络,使用MJSynth和SynthText两个英文文本识别合成数据集训练的[模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_r34_vd_none_bilstm_ctc_v2.0_train.tar) 为例,可以使用如下命令进行转换:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/export_model.py -c configs/rec/rec_r34_vd_none_bilstm_ctc.yml -o Global.pretrained_model=./rec_r34_vd_none_bilstm_ctc_v2.0_train/best_accuracy Global.save_inference_dir=./inference/rec_crnn
|
||||
```
|
||||
|
||||
CRNN 文本识别模型推理,可以执行如下命令:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_rec.py --image_dir="./doc/imgs_words_en/word_336.png" --rec_model_dir="./inference/rec_crnn/" --rec_image_shape="3, 32, 100" --rec_char_dict_path="./ppocr/utils/ic15_dict.txt"
|
||||
```
|
||||
|
||||

|
||||
|
||||
执行命令后,上面图像的识别结果如下:
|
||||
|
||||
```bash linenums="1"
|
||||
Predicts of ./doc/imgs_words_en/word_336.png:('super', 0.9999073)
|
||||
```
|
||||
|
||||
**注意**:由于上述模型是参考[DTRB](https://arxiv.org/abs/1904.01906)文本识别训练和评估流程,与超轻量级中文识别模型训练有两方面不同:
|
||||
|
||||
- 训练时采用的图像分辨率不同,训练上述模型采用的图像分辨率是[3,32,100],而中文模型训练时,为了保证长文本的识别效果,训练时采用的图像分辨率是[3, 32, 320]。预测推理程序默认的形状参数是训练中文采用的图像分辨率,即[3, 32, 320]。因此,这里推理上述英文模型时,需要通过参数rec_image_shape设置识别图像的形状。
|
||||
- 字符列表,DTRB论文中实验只是针对26个小写英文本母和10个数字进行实验,总共36个字符。所有大小字符都转成了小写字符,不在上面列表的字符都忽略,认为是空格。因此这里没有输入字符字典,而是通过如下命令生成字典.因此在推理时需要设置参数rec_char_dict_path,指定为英文字典"./ppocr/utils/ic15_dict.txt"。
|
||||
|
||||
```python linenums="1"
|
||||
self.character_str = "0123456789abcdefghijklmnopqrstuvwxyz"
|
||||
dict_character = list(self.character_str)
|
||||
```
|
||||
|
||||
### 4.2 C++推理
|
||||
|
||||
准备好推理模型后,参考[cpp infer](../../../version2.x/legacy/cpp_infer.md)教程进行操作即可。
|
||||
|
||||
### 4.3 Serving服务化部署
|
||||
|
||||
准备好推理模型后,参考[pdserving](../../../version2.x/legacy/paddle_server.md)教程进行Serving服务化部署,包括Python Serving和C++ Serving两种模式。
|
||||
|
||||
### 4.4 更多推理部署
|
||||
|
||||
CRNN模型还支持以下推理部署方式:
|
||||
|
||||
- Paddle2ONNX推理:准备好推理模型后,参考[paddle2onnx](../../../version2.x/legacy/paddle2onnx.md)教程操作。
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
## 引用
|
||||
|
||||
```bibtex
|
||||
@ARTICLE{7801919,
|
||||
author={Shi, Baoguang and Bai, Xiang and Yao, Cong},
|
||||
journal={IEEE Transactions on Pattern Analysis and Machine Intelligence},
|
||||
title={An End-to-End Trainable Neural Network for Image-Based Sequence Recognition and Its Application to Scene Text Recognition},
|
||||
year={2017},
|
||||
volume={39},
|
||||
number={11},
|
||||
pages={2298-2304},
|
||||
doi={10.1109/TPAMI.2016.2646371}}
|
||||
```
|
||||
@@ -0,0 +1,256 @@
|
||||
---
|
||||
comments: true
|
||||
---
|
||||
|
||||
# NRTR
|
||||
|
||||
## 1. Introduction
|
||||
|
||||
Paper:
|
||||
> [NRTR: A No-Recurrence Sequence-to-Sequence Model For Scene Text Recognition](https://arxiv.org/abs/1806.00926)
|
||||
> Fenfen Sheng and Zhineng Chen and Bo Xu
|
||||
> ICDAR, 2019
|
||||
|
||||
Using MJSynth and SynthText two text recognition datasets for training, and evaluating on IIIT, SVT, IC03, IC13, IC15, SVTP, CUTE datasets, the algorithm reproduction effect is as follows:
|
||||
|
||||
|Model|Backbone|config|Acc|Download link|
|
||||
| --- | --- | --- | --- | --- |
|
||||
|NRTR|MTB|[rec_mtb_nrtr.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/rec/rec_mtb_nrtr.yml)|84.21%|[trained model](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_mtb_nrtr_train.tar)|
|
||||
|
||||
## 2. Environment
|
||||
|
||||
Please refer to ["Environment Preparation"](../../ppocr/environment.en.md) to configure the PaddleOCR environment, and refer to ["Project Clone"](../../ppocr/blog/clone.en.md)to clone the project code.
|
||||
|
||||
## 3. Model Training / Evaluation / Prediction
|
||||
|
||||
Please refer to [Text Recognition Tutorial](../../ppocr/model_train/recognition.en.md). PaddleOCR modularizes the code, and training different recognition models only requires **changing the configuration file**.
|
||||
|
||||
### Training
|
||||
|
||||
Specifically, after the data preparation is completed, the training can be started. The training command is as follows:
|
||||
|
||||
```bash linenums="1"
|
||||
# Single GPU training (long training period, not recommended)
|
||||
python3 tools/train.py -c configs/rec/rec_mtb_nrtr.yml
|
||||
|
||||
# Multi GPU training, specify the gpu number through the --gpus parameter
|
||||
python3 -m paddle.distributed.launch --gpus '0,1,2,3' tools/train.py -c configs/rec/rec_mtb_nrtr.yml
|
||||
```
|
||||
|
||||
### Evaluation
|
||||
|
||||
```bash linenums="1"
|
||||
# GPU evaluation
|
||||
python3 -m paddle.distributed.launch --gpus '0' tools/eval.py -c configs/rec/rec_mtb_nrtr.yml -o Global.pretrained_model={path/to/weights}/best_accuracy
|
||||
```
|
||||
|
||||
### Prediction
|
||||
|
||||
```bash linenums="1"
|
||||
# The configuration file used for prediction must match the training
|
||||
python3 tools/infer_rec.py -c configs/rec/rec_mtb_nrtr.yml -o Global.infer_img='./doc/imgs_words_en/word_10.png' Global.pretrained_model=./rec_mtb_nrtr_train/best_accuracy
|
||||
```
|
||||
|
||||
## 4. Inference and Deployment
|
||||
|
||||
### 4.1 Python Inference
|
||||
|
||||
First, the model saved during the NRTR text recognition training process is converted into an inference model. ( [Model download link](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_mtb_nrtr_train.tar)) ), you can use the following command to convert:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/export_model.py -c configs/rec/rec_mtb_nrtr.yml -o Global.pretrained_model=./rec_mtb_nrtr_train/best_accuracy Global.save_inference_dir=./inference/rec_mtb_nrtr
|
||||
```
|
||||
|
||||
**Note:**
|
||||
|
||||
- If you are training the model on your own dataset and have modified the dictionary file, please pay attention to modify the `character_dict_path` in the configuration file to the modified dictionary file.
|
||||
- If you modified the input size during training, please modify the `infer_shape` corresponding to NRTR in the `tools/export_model.py` file.
|
||||
|
||||
After the conversion is successful, there are three files in the directory:
|
||||
|
||||
```text linenums="1"
|
||||
/inference/rec_mtb_nrtr/
|
||||
├── inference.pdiparams
|
||||
├── inference.pdiparams.info
|
||||
└── inference.pdmodel
|
||||
```
|
||||
|
||||
For NRTR text recognition model inference, the following commands can be executed:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_rec.py --image_dir='./doc/imgs_words_en/word_10.png' --rec_model_dir='./inference/rec_mtb_nrtr/' --rec_algorithm='NRTR' --rec_image_shape='1,32,100' --rec_char_dict_path='./ppocr/utils/EN_symbol_dict.txt'
|
||||
```
|
||||
|
||||

|
||||
|
||||
After executing the command, the prediction result (recognized text and score) of the image above is printed to the screen, an example is as follows:
|
||||
|
||||
```bash linenums="1"
|
||||
Predicts of ./doc/imgs_words_en/word_10.png:('pain', 0.9465042352676392)
|
||||
```
|
||||
|
||||
### 4.2 C++ Inference
|
||||
|
||||
Not supported
|
||||
|
||||
### 4.3 Serving
|
||||
|
||||
Not supported
|
||||
|
||||
### 4.4 More
|
||||
|
||||
Not supported
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
1. In the `NRTR` paper, Beam search is used to decode characters, but the speed is slow. Beam search is not used by default here, and greedy search is used to decode characters.
|
||||
|
||||
## 6. Release Note
|
||||
|
||||
1. The release/2.6 version updates the NRTR code structure. The new version of NRTR can load the model parameters of the old version (release/2.5 and before), and you may use the following code to convert the old version model parameters to the new version model parameters:
|
||||
|
||||
<details>
|
||||
<summary>Click to expand</summary>
|
||||
|
||||
```python linenums="1"
|
||||
params = paddle.load('path/' + '.pdparams') # the old version parameters
|
||||
state_dict = model.state_dict() # the new version model parameters
|
||||
new_state_dict = {}
|
||||
|
||||
for k1, v1 in state_dict.items():
|
||||
|
||||
k = k1
|
||||
if 'encoder' in k and 'self_attn' in k and 'qkv' in k and 'weight' in k:
|
||||
|
||||
k_para = k[:13] + 'layers.' + k[13:]
|
||||
q = params[k_para.replace('qkv', 'conv1')].transpose((1, 0, 2, 3))
|
||||
k = params[k_para.replace('qkv', 'conv2')].transpose((1, 0, 2, 3))
|
||||
v = params[k_para.replace('qkv', 'conv3')].transpose((1, 0, 2, 3))
|
||||
|
||||
new_state_dict[k1] = np.concatenate([q[:, :, 0, 0], k[:, :, 0, 0], v[:, :, 0, 0]], -1)
|
||||
|
||||
elif 'encoder' in k and 'self_attn' in k and 'qkv' in k and 'bias' in k:
|
||||
|
||||
k_para = k[:13] + 'layers.' + k[13:]
|
||||
q = params[k_para.replace('qkv', 'conv1')]
|
||||
k = params[k_para.replace('qkv', 'conv2')]
|
||||
v = params[k_para.replace('qkv', 'conv3')]
|
||||
|
||||
new_state_dict[k1] = np.concatenate([q, k, v], -1)
|
||||
|
||||
elif 'encoder' in k and 'self_attn' in k and 'out_proj' in k:
|
||||
|
||||
k_para = k[:13] + 'layers.' + k[13:]
|
||||
new_state_dict[k1] = params[k_para]
|
||||
|
||||
elif 'encoder' in k and 'norm3' in k:
|
||||
k_para = k[:13] + 'layers.' + k[13:]
|
||||
new_state_dict[k1] = params[k_para.replace('norm3', 'norm2')]
|
||||
|
||||
elif 'encoder' in k and 'norm1' in k:
|
||||
k_para = k[:13] + 'layers.' + k[13:]
|
||||
new_state_dict[k1] = params[k_para]
|
||||
|
||||
|
||||
elif 'decoder' in k and 'self_attn' in k and 'qkv' in k and 'weight' in k:
|
||||
k_para = k[:13] + 'layers.' + k[13:]
|
||||
q = params[k_para.replace('qkv', 'conv1')].transpose((1, 0, 2, 3))
|
||||
k = params[k_para.replace('qkv', 'conv2')].transpose((1, 0, 2, 3))
|
||||
v = params[k_para.replace('qkv', 'conv3')].transpose((1, 0, 2, 3))
|
||||
new_state_dict[k1] = np.concatenate([q[:, :, 0, 0], k[:, :, 0, 0], v[:, :, 0, 0]], -1)
|
||||
|
||||
elif 'decoder' in k and 'self_attn' in k and 'qkv' in k and 'bias' in k:
|
||||
k_para = k[:13] + 'layers.' + k[13:]
|
||||
q = params[k_para.replace('qkv', 'conv1')]
|
||||
k = params[k_para.replace('qkv', 'conv2')]
|
||||
v = params[k_para.replace('qkv', 'conv3')]
|
||||
new_state_dict[k1] = np.concatenate([q, k, v], -1)
|
||||
|
||||
elif 'decoder' in k and 'self_attn' in k and 'out_proj' in k:
|
||||
|
||||
k_para = k[:13] + 'layers.' + k[13:]
|
||||
new_state_dict[k1] = params[k_para]
|
||||
|
||||
elif 'decoder' in k and 'cross_attn' in k and 'q' in k and 'weight' in k:
|
||||
k_para = k[:13] + 'layers.' + k[13:]
|
||||
k_para = k_para.replace('cross_attn', 'multihead_attn')
|
||||
q = params[k_para.replace('q', 'conv1')].transpose((1, 0, 2, 3))
|
||||
new_state_dict[k1] = q[:, :, 0, 0]
|
||||
|
||||
elif 'decoder' in k and 'cross_attn' in k and 'q' in k and 'bias' in k:
|
||||
k_para = k[:13] + 'layers.' + k[13:]
|
||||
k_para = k_para.replace('cross_attn', 'multihead_attn')
|
||||
q = params[k_para.replace('q', 'conv1')]
|
||||
new_state_dict[k1] = q
|
||||
|
||||
elif 'decoder' in k and 'cross_attn' in k and 'kv' in k and 'weight' in k:
|
||||
k_para = k[:13] + 'layers.' + k[13:]
|
||||
k_para = k_para.replace('cross_attn', 'multihead_attn')
|
||||
k = params[k_para.replace('kv', 'conv2')].transpose((1, 0, 2, 3))
|
||||
v = params[k_para.replace('kv', 'conv3')].transpose((1, 0, 2, 3))
|
||||
new_state_dict[k1] = np.concatenate([k[:, :, 0, 0], v[:, :, 0, 0]], -1)
|
||||
|
||||
elif 'decoder' in k and 'cross_attn' in k and 'kv' in k and 'bias' in k:
|
||||
k_para = k[:13] + 'layers.' + k[13:]
|
||||
k_para = k_para.replace('cross_attn', 'multihead_attn')
|
||||
k = params[k_para.replace('kv', 'conv2')]
|
||||
v = params[k_para.replace('kv', 'conv3')]
|
||||
new_state_dict[k1] = np.concatenate([k, v], -1)
|
||||
|
||||
elif 'decoder' in k and 'cross_attn' in k and 'out_proj' in k:
|
||||
|
||||
k_para = k[:13] + 'layers.' + k[13:]
|
||||
k_para = k_para.replace('cross_attn', 'multihead_attn')
|
||||
new_state_dict[k1] = params[k_para]
|
||||
elif 'decoder' in k and 'norm' in k:
|
||||
k_para = k[:13] + 'layers.' + k[13:]
|
||||
new_state_dict[k1] = params[k_para]
|
||||
elif 'mlp' in k and 'weight' in k:
|
||||
k_para = k[:13] + 'layers.' + k[13:]
|
||||
k_para = k_para.replace('fc', 'conv')
|
||||
k_para = k_para.replace('mlp.', '')
|
||||
w = params[k_para].transpose((1, 0, 2, 3))
|
||||
new_state_dict[k1] = w[:, :, 0, 0]
|
||||
elif 'mlp' in k and 'bias' in k:
|
||||
k_para = k[:13] + 'layers.' + k[13:]
|
||||
k_para = k_para.replace('fc', 'conv')
|
||||
k_para = k_para.replace('mlp.', '')
|
||||
w = params[k_para]
|
||||
new_state_dict[k1] = w
|
||||
|
||||
else:
|
||||
new_state_dict[k1] = params[k1]
|
||||
|
||||
if list(new_state_dict[k1].shape) != list(v1.shape):
|
||||
print(k1)
|
||||
|
||||
|
||||
for k, v1 in state_dict.items():
|
||||
if k not in new_state_dict.keys():
|
||||
print(1, k)
|
||||
elif list(new_state_dict[k].shape) != list(v1.shape):
|
||||
print(2, k)
|
||||
|
||||
|
||||
|
||||
model.set_state_dict(new_state_dict)
|
||||
paddle.save(model.state_dict(), 'nrtrnew_from_old_params.pdparams')
|
||||
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
2. The new version has a clean code structure and improved inference speed compared with the old version.
|
||||
|
||||
## Citation
|
||||
|
||||
```bibtex
|
||||
@article{Sheng2019NRTR,
|
||||
title = {NRTR: A No-Recurrence Sequence-to-Sequence Model For Scene Text Recognition},
|
||||
author = {Fenfen Sheng and Zhineng Chen and Bo Xu},
|
||||
booktitle = {ICDAR},
|
||||
year = {2019},
|
||||
url = {http://arxiv.org/abs/1806.00926},
|
||||
pages = {781-786}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,272 @@
|
||||
---
|
||||
typora-copy-images-to: images
|
||||
comments: true
|
||||
---
|
||||
|
||||
# 场景文本识别算法-NRTR
|
||||
|
||||
## 1. 算法简介
|
||||
|
||||
论文信息:
|
||||
> [NRTR: A No-Recurrence Sequence-to-Sequence Model For Scene Text Recognition](https://arxiv.org/abs/1806.00926)
|
||||
> Fenfen Sheng and Zhineng Chen and Bo Xu
|
||||
> ICDAR, 2019
|
||||
|
||||
`NRTR`使用MJSynth和SynthText两个文字识别数据集训练,在IIIT, SVT, IC03, IC13, IC15, SVTP, CUTE数据集上进行评估,算法复现效果如下:
|
||||
|
||||
|模型|骨干网络|配置文件|Acc|下载链接|
|
||||
| --- | --- | --- | --- | --- |
|
||||
|NRTR|MTB|[rec_mtb_nrtr.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/rec/rec_mtb_nrtr.yml)|84.21%|[训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_mtb_nrtr_train.tar)|
|
||||
|
||||
## 2. 环境配置
|
||||
|
||||
请先参考[《运行环境准备》](../../ppocr/environment.md)配置PaddleOCR运行环境,参考[《项目克隆》](../../ppocr/blog/clone.md)克隆项目代码。
|
||||
|
||||
## 3. 模型训练、评估、预测
|
||||
|
||||
### 3.1 模型训练
|
||||
|
||||
请参考[文本识别训练教程](../../ppocr/model_train/recognition.md)。PaddleOCR对代码进行了模块化,训练`NRTR`识别模型时需要**更换配置文件**为`NRTR`的[配置文件](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/rec/rec_mtb_nrtr.yml)。
|
||||
|
||||
#### 启动训练
|
||||
|
||||
具体地,在完成数据准备后,便可以启动训练,训练命令如下:
|
||||
|
||||
```bash linenums="1"
|
||||
#单卡训练(训练周期长,不建议)
|
||||
python3 tools/train.py -c configs/rec/rec_mtb_nrtr.yml
|
||||
|
||||
# 多卡训练,通过--gpus参数指定卡号
|
||||
python3 -m paddle.distributed.launch --gpus '0,1,2,3' tools/train.py -c configs/rec/rec_mtb_nrtr.yml
|
||||
```
|
||||
|
||||
### 3.2 评估
|
||||
|
||||
可下载已训练完成的模型文件,使用如下命令进行评估:
|
||||
|
||||
```bash linenums="1"
|
||||
# 注意将pretrained_model的路径设置为本地路径。
|
||||
python3 -m paddle.distributed.launch --gpus '0' tools/eval.py -c configs/rec/rec_mtb_nrtr.yml -o Global.pretrained_model=./rec_mtb_nrtr_train/best_accuracy
|
||||
```
|
||||
|
||||
### 3.3 预测
|
||||
|
||||
使用如下命令进行单张图片预测:
|
||||
|
||||
```bash linenums="1"
|
||||
# 注意将pretrained_model的路径设置为本地路径。
|
||||
python3 tools/infer_rec.py -c configs/rec/rec_mtb_nrtr.yml -o Global.infer_img='./doc/imgs_words_en/word_10.png' Global.pretrained_model=./rec_mtb_nrtr_train/best_accuracy
|
||||
# 预测文件夹下所有图像时,可修改infer_img为文件夹,如 Global.infer_img='./doc/imgs_words_en/'。
|
||||
```
|
||||
|
||||
## 4. 推理部署
|
||||
|
||||
### 4.1 Python推理
|
||||
|
||||
首先将训练得到best模型,转换成inference model。这里以训练完成的模型为例([模型下载地址](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_mtb_nrtr_train.tar) ),可以使用如下命令进行转换:
|
||||
|
||||
```bash linenums="1"
|
||||
# 注意将pretrained_model的路径设置为本地路径。
|
||||
python3 tools/export_model.py -c configs/rec/rec_mtb_nrtr.yml -o Global.pretrained_model=./rec_mtb_nrtr_train/best_accuracy Global.save_inference_dir=./inference/rec_mtb_nrtr/
|
||||
```
|
||||
|
||||
**注意:**
|
||||
|
||||
- 如果您是在自己的数据集上训练的模型,并且调整了字典文件,请注意修改配置文件中的`character_dict_path`是否是所需要的字典文件。
|
||||
- 如果您修改了训练时的输入大小,请修改`tools/export_model.py`文件中的对应NRTR的`infer_shape`。
|
||||
|
||||
转换成功后,在目录下有三个文件:
|
||||
|
||||
```text linenums="1"
|
||||
/inference/rec_mtb_nrtr/
|
||||
├── inference.pdiparams # 识别inference模型的参数文件
|
||||
├── inference.pdiparams.info # 识别inference模型的参数信息,可忽略
|
||||
└── inference.pdmodel # 识别inference模型的program文件
|
||||
```
|
||||
|
||||
执行如下命令进行模型推理:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_rec.py --image_dir='./doc/imgs_words_en/word_10.png' --rec_model_dir='./inference/rec_mtb_nrtr/' --rec_algorithm='NRTR' --rec_image_shape='1,32,100' --rec_char_dict_path='./ppocr/utils/EN_symbol_dict.txt'
|
||||
# 预测文件夹下所有图像时,可修改image_dir为文件夹,如 --image_dir='./doc/imgs_words_en/'。
|
||||
```
|
||||
|
||||

|
||||
|
||||
执行命令后,上面图像的预测结果(识别的文本和得分)会打印到屏幕上,示例如下:
|
||||
|
||||
```bash linenums="1"
|
||||
Predicts of ./doc/imgs_words_en/word_10.png:('pain', 0.9465042352676392)
|
||||
```
|
||||
|
||||
**注意**:
|
||||
|
||||
- 训练上述模型采用的图像分辨率是[1,32,100],需要通过参数`rec_image_shape`设置为您训练时的识别图像形状。
|
||||
- 在推理时需要设置参数`rec_char_dict_path`指定字典,如果您修改了字典,请修改该参数为您的字典文件。
|
||||
- 如果您修改了预处理方法,需修改`tools/infer/predict_rec.py`中NRTR的预处理为您的预处理方法。
|
||||
|
||||
### 4.2 C++推理部署
|
||||
|
||||
由于C++预处理后处理还未支持NRTR,所以暂未支持
|
||||
|
||||
### 4.3 Serving服务化部署
|
||||
|
||||
暂不支持
|
||||
|
||||
### 4.4 更多推理部署
|
||||
|
||||
暂不支持
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
1. `NRTR`论文中使用Beam搜索进行解码字符,但是速度较慢,这里默认未使用Beam搜索,以贪婪搜索进行解码字符。
|
||||
|
||||
## 6. 发行公告
|
||||
|
||||
1. release/2.6更新NRTR代码结构,新版NRTR可加载旧版(release/2.5及之前)模型参数,使用下面示例代码将旧版模型参数转换为新版模型参数:
|
||||
|
||||
<details>
|
||||
<summary>详情</summary>
|
||||
|
||||
```python linenums="1"
|
||||
params = paddle.load('path/' + '.pdparams') # 旧版本参数
|
||||
state_dict = model.state_dict() # 新版模型参数
|
||||
new_state_dict = {}
|
||||
|
||||
for k1, v1 in state_dict.items():
|
||||
|
||||
k = k1
|
||||
if 'encoder' in k and 'self_attn' in k and 'qkv' in k and 'weight' in k:
|
||||
|
||||
k_para = k[:13] + 'layers.' + k[13:]
|
||||
q = params[k_para.replace('qkv', 'conv1')].transpose((1, 0, 2, 3))
|
||||
k = params[k_para.replace('qkv', 'conv2')].transpose((1, 0, 2, 3))
|
||||
v = params[k_para.replace('qkv', 'conv3')].transpose((1, 0, 2, 3))
|
||||
|
||||
new_state_dict[k1] = np.concatenate([q[:, :, 0, 0], k[:, :, 0, 0], v[:, :, 0, 0]], -1)
|
||||
|
||||
elif 'encoder' in k and 'self_attn' in k and 'qkv' in k and 'bias' in k:
|
||||
|
||||
k_para = k[:13] + 'layers.' + k[13:]
|
||||
q = params[k_para.replace('qkv', 'conv1')]
|
||||
k = params[k_para.replace('qkv', 'conv2')]
|
||||
v = params[k_para.replace('qkv', 'conv3')]
|
||||
|
||||
new_state_dict[k1] = np.concatenate([q, k, v], -1)
|
||||
|
||||
elif 'encoder' in k and 'self_attn' in k and 'out_proj' in k:
|
||||
|
||||
k_para = k[:13] + 'layers.' + k[13:]
|
||||
new_state_dict[k1] = params[k_para]
|
||||
|
||||
elif 'encoder' in k and 'norm3' in k:
|
||||
k_para = k[:13] + 'layers.' + k[13:]
|
||||
new_state_dict[k1] = params[k_para.replace('norm3', 'norm2')]
|
||||
|
||||
elif 'encoder' in k and 'norm1' in k:
|
||||
k_para = k[:13] + 'layers.' + k[13:]
|
||||
new_state_dict[k1] = params[k_para]
|
||||
|
||||
|
||||
elif 'decoder' in k and 'self_attn' in k and 'qkv' in k and 'weight' in k:
|
||||
k_para = k[:13] + 'layers.' + k[13:]
|
||||
q = params[k_para.replace('qkv', 'conv1')].transpose((1, 0, 2, 3))
|
||||
k = params[k_para.replace('qkv', 'conv2')].transpose((1, 0, 2, 3))
|
||||
v = params[k_para.replace('qkv', 'conv3')].transpose((1, 0, 2, 3))
|
||||
new_state_dict[k1] = np.concatenate([q[:, :, 0, 0], k[:, :, 0, 0], v[:, :, 0, 0]], -1)
|
||||
|
||||
elif 'decoder' in k and 'self_attn' in k and 'qkv' in k and 'bias' in k:
|
||||
k_para = k[:13] + 'layers.' + k[13:]
|
||||
q = params[k_para.replace('qkv', 'conv1')]
|
||||
k = params[k_para.replace('qkv', 'conv2')]
|
||||
v = params[k_para.replace('qkv', 'conv3')]
|
||||
new_state_dict[k1] = np.concatenate([q, k, v], -1)
|
||||
|
||||
elif 'decoder' in k and 'self_attn' in k and 'out_proj' in k:
|
||||
|
||||
k_para = k[:13] + 'layers.' + k[13:]
|
||||
new_state_dict[k1] = params[k_para]
|
||||
|
||||
elif 'decoder' in k and 'cross_attn' in k and 'q' in k and 'weight' in k:
|
||||
k_para = k[:13] + 'layers.' + k[13:]
|
||||
k_para = k_para.replace('cross_attn', 'multihead_attn')
|
||||
q = params[k_para.replace('q', 'conv1')].transpose((1, 0, 2, 3))
|
||||
new_state_dict[k1] = q[:, :, 0, 0]
|
||||
|
||||
elif 'decoder' in k and 'cross_attn' in k and 'q' in k and 'bias' in k:
|
||||
k_para = k[:13] + 'layers.' + k[13:]
|
||||
k_para = k_para.replace('cross_attn', 'multihead_attn')
|
||||
q = params[k_para.replace('q', 'conv1')]
|
||||
new_state_dict[k1] = q
|
||||
|
||||
elif 'decoder' in k and 'cross_attn' in k and 'kv' in k and 'weight' in k:
|
||||
k_para = k[:13] + 'layers.' + k[13:]
|
||||
k_para = k_para.replace('cross_attn', 'multihead_attn')
|
||||
k = params[k_para.replace('kv', 'conv2')].transpose((1, 0, 2, 3))
|
||||
v = params[k_para.replace('kv', 'conv3')].transpose((1, 0, 2, 3))
|
||||
new_state_dict[k1] = np.concatenate([k[:, :, 0, 0], v[:, :, 0, 0]], -1)
|
||||
|
||||
elif 'decoder' in k and 'cross_attn' in k and 'kv' in k and 'bias' in k:
|
||||
k_para = k[:13] + 'layers.' + k[13:]
|
||||
k_para = k_para.replace('cross_attn', 'multihead_attn')
|
||||
k = params[k_para.replace('kv', 'conv2')]
|
||||
v = params[k_para.replace('kv', 'conv3')]
|
||||
new_state_dict[k1] = np.concatenate([k, v], -1)
|
||||
|
||||
elif 'decoder' in k and 'cross_attn' in k and 'out_proj' in k:
|
||||
|
||||
k_para = k[:13] + 'layers.' + k[13:]
|
||||
k_para = k_para.replace('cross_attn', 'multihead_attn')
|
||||
new_state_dict[k1] = params[k_para]
|
||||
elif 'decoder' in k and 'norm' in k:
|
||||
k_para = k[:13] + 'layers.' + k[13:]
|
||||
new_state_dict[k1] = params[k_para]
|
||||
elif 'mlp' in k and 'weight' in k:
|
||||
k_para = k[:13] + 'layers.' + k[13:]
|
||||
k_para = k_para.replace('fc', 'conv')
|
||||
k_para = k_para.replace('mlp.', '')
|
||||
w = params[k_para].transpose((1, 0, 2, 3))
|
||||
new_state_dict[k1] = w[:, :, 0, 0]
|
||||
elif 'mlp' in k and 'bias' in k:
|
||||
k_para = k[:13] + 'layers.' + k[13:]
|
||||
k_para = k_para.replace('fc', 'conv')
|
||||
k_para = k_para.replace('mlp.', '')
|
||||
w = params[k_para]
|
||||
new_state_dict[k1] = w
|
||||
|
||||
else:
|
||||
new_state_dict[k1] = params[k1]
|
||||
|
||||
if list(new_state_dict[k1].shape) != list(v1.shape):
|
||||
print(k1)
|
||||
|
||||
|
||||
for k, v1 in state_dict.items():
|
||||
if k not in new_state_dict.keys():
|
||||
print(1, k)
|
||||
elif list(new_state_dict[k].shape) != list(v1.shape):
|
||||
print(2, k)
|
||||
|
||||
|
||||
|
||||
model.set_state_dict(new_state_dict)
|
||||
paddle.save(model.state_dict(), 'nrtrnew_from_old_params.pdparams')
|
||||
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
2. 新版相比与旧版,代码结构简洁,推理速度有所提高。
|
||||
|
||||
## 引用
|
||||
|
||||
```bibtex
|
||||
@article{Sheng2019NRTR,
|
||||
title = {NRTR: A No-Recurrence Sequence-to-Sequence Model For Scene Text Recognition},
|
||||
author = {Fenfen Sheng and Zhineng Chen and Bo Xu},
|
||||
booktitle = {ICDAR},
|
||||
year = {2019},
|
||||
url = {http://arxiv.org/abs/1806.00926},
|
||||
pages = {781-786}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,105 @@
|
||||
---
|
||||
comments: true
|
||||
---
|
||||
|
||||
# PasreQ
|
||||
|
||||
## 1. Introduction
|
||||
|
||||
Paper:
|
||||
> [Scene Text Recognition with Permuted Autoregressive Sequence Models](https://arxiv.org/abs/2207.06966)
|
||||
> Darwin Bautista, Rowel Atienza
|
||||
> ECCV, 2021
|
||||
|
||||
Using real datasets (real) and synthetic datasets (synth) for training respectively,and evaluating on IIIT, SVT, IC03, IC13, IC15, SVTP, CUTE datasets.
|
||||
|
||||
- The real datasets include COCO-Text, RCTW17, Uber-Text, ArT, LSVT, MLT19, ReCTS, TextOCR and OpenVINO datasets.
|
||||
- The synthesis datasets include MJSynth and SynthText datasets.
|
||||
|
||||
the algorithm reproduction effect is as follows:
|
||||
|
||||
|Training Dataset|Model|Backbone|config|Acc|Download link|
|
||||
| --- | --- | --- | --- | --- | --- |
|
||||
|Synth|ParseQ|VIT|[rec_vit_parseq.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/rec/rec_vit_parseq.yml)|91.24%|[train model](https://paddleocr.bj.bcebos.com/dygraph_v2.1/parseq/rec_vit_parseq_synth.tgz)|
|
||||
|Real|ParseQ|VIT|[rec_vit_parseq.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/rec/rec_vit_parseq.yml)|94.74%|[train model](https://paddleocr.bj.bcebos.com/dygraph_v2.1/parseq/rec_vit_parseq_real.tgz)|
|
||||
|
||||
## 2. Environment
|
||||
|
||||
Please refer to ["Environment Preparation"](../../ppocr/environment.en.md) to configure the PaddleOCR environment, and refer to ["Project Clone"](../../ppocr/blog/clone.en.md)to clone the project code.
|
||||
|
||||
## 3. Model Training / Evaluation / Prediction
|
||||
|
||||
Please refer to [Text Recognition Tutorial](../../ppocr/model_train/recognition.en.md). PaddleOCR modularizes the code, and training different recognition models only requires **changing the configuration file**.
|
||||
|
||||
### Training
|
||||
|
||||
Specifically, after the data preparation is completed, the training can be started. The training command is as follows:
|
||||
|
||||
```bash linenums="1"
|
||||
# Single GPU training (long training period, not recommended)
|
||||
python3 tools/train.py -c configs/rec/rec_vit_parseq.yml
|
||||
|
||||
# Multi GPU training, specify the gpu number through the --gpus parameter
|
||||
python3 -m paddle.distributed.launch --gpus '0,1,2,3' tools/train.py -c configs/rec/rec_vit_parseq.yml
|
||||
```
|
||||
|
||||
### Evaluation
|
||||
|
||||
```bash linenums="1"
|
||||
# GPU evaluation
|
||||
python3 -m paddle.distributed.launch --gpus '0' tools/eval.py -c configs/rec/rec_vit_parseq.yml -o Global.pretrained_model={path/to/weights}/best_accuracy
|
||||
```
|
||||
|
||||
### Prediction
|
||||
|
||||
```bash linenums="1"
|
||||
# The configuration file used for prediction must match the training
|
||||
python3 tools/infer_rec.py -c configs/rec/rec_vit_parseq.yml -o Global.pretrained_model={path/to/weights}/best_accuracy Global.infer_img=doc/imgs_words/en/word_1.png
|
||||
```
|
||||
|
||||
## 4. Inference and Deployment
|
||||
|
||||
### 4.1 Python Inference
|
||||
|
||||
First, the model saved during the SAR text recognition training process is converted into an inference model. ( [Model download link](https://paddleocr.bj.bcebos.com/dygraph_v2.1/parseq/rec_vit_parseq_real.tgz) ), you can use the following command to convert:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/export_model.py -c configs/rec/rec_vit_parseq.yml -o Global.pretrained_model=./rec_vit_parseq_real/best_accuracy Global.save_inference_dir=./inference/rec_parseq
|
||||
```
|
||||
|
||||
For SAR text recognition model inference, the following commands can be executed:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_rec.py --image_dir="./doc/imgs_words/en/word_1.png" --rec_model_dir="./inference/rec_parseq/" --rec_image_shape="3, 32, 128" --rec_algorithm="ParseQ" --rec_char_dict_path="ppocr/utils/dict/parseq_dict.txt" --max_text_length=25 --use_space_char=False
|
||||
```
|
||||
|
||||
### 4.2 C++ Inference
|
||||
|
||||
Not supported
|
||||
|
||||
### 4.3 Serving
|
||||
|
||||
Not supported
|
||||
|
||||
### 4.4 More
|
||||
|
||||
Not supported
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
## Citation
|
||||
|
||||
```bibtex
|
||||
@InProceedings{bautista2022parseq,
|
||||
title={Scene Text Recognition with Permuted Autoregressive Sequence Models},
|
||||
author={Bautista, Darwin and Atienza, Rowel},
|
||||
booktitle={European Conference on Computer Vision},
|
||||
pages={178--196},
|
||||
month={10},
|
||||
year={2022},
|
||||
publisher={Springer Nature Switzerland},
|
||||
address={Cham},
|
||||
doi={10.1007/978-3-031-19815-1_11},
|
||||
url={https://doi.org/10.1007/978-3-031-19815-1_11}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,105 @@
|
||||
---
|
||||
comments: true
|
||||
---
|
||||
|
||||
# ParseQ
|
||||
|
||||
## 1. 算法简介
|
||||
|
||||
论文信息:
|
||||
> [Scene Text Recognition with Permuted Autoregressive Sequence Models](https://arxiv.org/abs/2207.06966)
|
||||
> Darwin Bautista, Rowel Atienza
|
||||
> ECCV, 2021
|
||||
|
||||
原论文分别使用真实文本识别数据集(Real)和合成文本识别数据集(Synth)进行训练,在IIIT, SVT, IC03, IC13, IC15, SVTP, CUTE数据集上进行评估。其中:
|
||||
|
||||
- 真实文本识别数据集(Real)包含COCO-Text, RCTW17, Uber-Text, ArT, LSVT, MLT19, ReCTS, TextOCR, OpenVINO数据集
|
||||
- 合成文本识别数据集(Synth)包含MJSynth和SynthText数据集
|
||||
|
||||
在不同数据集上训练的算法的复现效果如下:
|
||||
|
||||
|数据集|模型|骨干网络|配置文件|Acc|下载链接|
|
||||
| --- | --- | --- | --- | --- | --- |
|
||||
|Synth|ParseQ|VIT|[rec_vit_parseq.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/rec/rec_vit_parseq.yml)|91.24%|[训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.1/parseq/rec_vit_parseq_synth.tgz)|
|
||||
|Real|ParseQ|VIT|[rec_vit_parseq.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/rec/rec_vit_parseq.yml)|94.74%|[训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.1/parseq/rec_vit_parseq_real.tgz)|
|
||||
|
||||
## 2. 环境配置
|
||||
|
||||
请先参考[《运行环境准备》](../../ppocr/environment.md)配置PaddleOCR运行环境,参考[《项目克隆》](../../ppocr/blog/clone.md)克隆项目代码。
|
||||
|
||||
## 3. 模型训练、评估、预测
|
||||
|
||||
请参考[文本识别教程](../../ppocr/model_train/recognition.md)。PaddleOCR对代码进行了模块化,训练不同的识别模型只需要**更换配置文件**即可。
|
||||
|
||||
### 训练
|
||||
|
||||
具体地,在完成数据准备后,便可以启动训练,训练命令如下:
|
||||
|
||||
```bash linenums="1"
|
||||
# 单卡训练(训练周期长,不建议)
|
||||
python3 tools/train.py -c configs/rec/rec_vit_parseq.yml
|
||||
|
||||
# 多卡训练,通过--gpus参数指定卡号
|
||||
python3 -m paddle.distributed.launch --gpus '0,1,2,3' tools/train.py -c configs/rec/rec_vit_parseq.yml
|
||||
```
|
||||
|
||||
### 评估
|
||||
|
||||
```bash linenums="1"
|
||||
# GPU 评估, Global.pretrained_model 为待测权重
|
||||
python3 -m paddle.distributed.launch --gpus '0' tools/eval.py -c configs/rec/rec_vit_parseq.yml -o Global.pretrained_model={path/to/weights}/best_accuracy
|
||||
```
|
||||
|
||||
### 预测
|
||||
|
||||
```bash linenums="1"
|
||||
# 预测使用的配置文件必须与训练一致
|
||||
python3 tools/infer_rec.py -c configs/rec/rec_vit_parseq.yml -o Global.pretrained_model={path/to/weights}/best_accuracy Global.infer_img=doc/imgs_words/en/word_1.png
|
||||
```
|
||||
|
||||
## 4. 推理部署
|
||||
|
||||
### 4.1 Python推理
|
||||
|
||||
首先将ParseQ文本识别训练过程中保存的模型,转换成inference model。( [模型下载地址](https://paddleocr.bj.bcebos.com/dygraph_v2.1/parseq/rec_vit_parseq_real.tgz) ),可以使用如下命令进行转换:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/export_model.py -c configs/rec/rec_vit_parseq.yml -o Global.pretrained_model=./rec_vit_parseq_real/best_accuracy Global.save_inference_dir=./inference/rec_parseq
|
||||
```
|
||||
|
||||
ParseQ文本识别模型推理,可以执行如下命令:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_rec.py --image_dir="./doc/imgs_words/en/word_1.png" --rec_model_dir="./inference/rec_parseq/" --rec_image_shape="3, 32, 128" --rec_algorithm="ParseQ" --rec_char_dict_path="ppocr/utils/dict/parseq_dict.txt" --max_text_length=25 --use_space_char=False
|
||||
```
|
||||
|
||||
### 4.2 C++推理
|
||||
|
||||
由于C++预处理后处理还未支持ParseQ,所以暂未支持
|
||||
|
||||
### 4.3 Serving服务化部署
|
||||
|
||||
暂不支持
|
||||
|
||||
### 4.4 更多推理部署
|
||||
|
||||
暂不支持
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
## 引用
|
||||
|
||||
```bibtex
|
||||
@InProceedings{bautista2022parseq,
|
||||
title={Scene Text Recognition with Permuted Autoregressive Sequence Models},
|
||||
author={Bautista, Darwin and Atienza, Rowel},
|
||||
booktitle={European Conference on Computer Vision},
|
||||
pages={178--196},
|
||||
month={10},
|
||||
year={2022},
|
||||
publisher={Springer Nature Switzerland},
|
||||
address={Cham},
|
||||
doi={10.1007/978-3-031-19815-1_11},
|
||||
url={https://doi.org/10.1007/978-3-031-19815-1_11}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,100 @@
|
||||
---
|
||||
comments: true
|
||||
---
|
||||
|
||||
# RARE
|
||||
|
||||
## 1. Introduction
|
||||
|
||||
Paper information:
|
||||
> [Robust Scene Text Recognition with Automatic Rectification](https://arxiv.org/abs/1603.03915v2)
|
||||
> Baoguang Shi, Xinggang Wang, Pengyuan Lyu, Cong Yao, Xiang Bai∗
|
||||
> CVPR, 2016
|
||||
|
||||
Using MJSynth and SynthText two text recognition datasets for training, and evaluating on IIIT, SVT, IC03, IC13, IC15, SVTP, CUTE datasets, the algorithm reproduction effect is as follows:
|
||||
|
||||
|Models|Backbone Networks|Configuration Files|Avg Accuracy|Download Links|
|
||||
| --- | --- | --- | --- | --- |
|
||||
|RARE|Resnet34_vd|[configs/rec/rec_r34_vd_tps_bilstm_att.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/rec/rec_r34_vd_tps_bilstm_att.yml)|83.60%|[training model](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_r34_vd_tps_bilstm_att_v2.0_train.tar)|
|
||||
|RARE|MobileNetV3|[configs/rec/rec_mv3_tps_bilstm_att.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/rec/rec_mv3_tps_bilstm_att.yml)|82.50%|[trained model](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_mv3_tps_bilstm_att_v2.0_train.tar)|
|
||||
|
||||
## 2. Environment
|
||||
|
||||
Please refer to [Operating Environment Preparation](../../ppocr/environment.en.md) to configure the PaddleOCR operating environment, and refer to [Project Clone](../../ppocr/blog/clone.en.md)to clone the project code.
|
||||
|
||||
## 3. Model Training / Evaluation / Prediction
|
||||
|
||||
Please refer to [Text Recognition Training Tutorial](../../ppocr/model_train/recognition.en.md). PaddleOCR modularizes the code, and training different recognition models only requires **changing the configuration file**. Take the backbone network based on Resnet34_vd as an example:
|
||||
|
||||
### 3.1 Training
|
||||
|
||||
````bash linenums="1"
|
||||
# Single card training (long training period, not recommended)
|
||||
python3 tools/train.py -c configs/rec/rec_r34_vd_tps_bilstm_att.yml
|
||||
# Multi-card training, specify the card number through the --gpus parameter
|
||||
python3 -m paddle.distributed.launch --gpus '0,1,2,3' tools/train.py -c configs/rec/rec_r34_vd_tps_bilstm_att.yml
|
||||
````
|
||||
|
||||
### 3.2 Evaluation
|
||||
|
||||
````bash linenums="1"
|
||||
# GPU evaluation, Global.pretrained_model is the model to be evaluated
|
||||
python3 -m paddle.distributed.launch --gpus '0' tools/eval.py -c configs/rec/rec_r34_vd_tps_bilstm_att.yml -o Global.pretrained_model={path/to/weights}/best_accuracy
|
||||
````
|
||||
|
||||
### 3.3 Prediction
|
||||
|
||||
````bash linenums="1"
|
||||
python3 tools/infer_rec.py -c configs/rec/rec_r34_vd_tps_bilstm_att.yml -o Global.pretrained_model={path/to/weights}/best_accuracy Global.infer_img=doc/imgs_words/en/word_1.png
|
||||
````
|
||||
|
||||
## 4. Inference
|
||||
|
||||
### 4.1 Python Inference
|
||||
|
||||
First, convert the model saved during the RARE text recognition training process into an inference model. Take the model trained on the MJSynth and SynthText text recognition datasets based on the Resnet34_vd backbone network as an example ([Model download address](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_r34_vd_tps_bilstm_att_v2.0_train.tar) ), which can be converted using the following command:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/export_model.py -c configs/rec/rec_r34_vd_tps_bilstm_att.yml -o Global.pretrained_model=./rec_r34_vd_tps_bilstm_att_v2.0_train/best_accuracy Global.save_inference_dir=./inference/rec_rare
|
||||
````
|
||||
|
||||
RARE text recognition model inference, you can execute the following commands:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_rec.py --image_dir="doc/imgs_words/en/word_1.png" --rec_model_dir="./inference/rec_rare/" --rec_image_shape="3, 32, 100" --rec_char_dict_path= "./ppocr/utils/ic15_dict.txt"
|
||||
````
|
||||
|
||||
The inference results are as follows:
|
||||
|
||||

|
||||
|
||||
````text linenums="1"
|
||||
Predicts of doc/imgs_words/en/word_1.png:('joint ', 0.9999969601631165)
|
||||
````
|
||||
|
||||
### 4.2 C++ Inference
|
||||
|
||||
Not currently supported
|
||||
|
||||
### 4.3 Serving
|
||||
|
||||
Not currently supported
|
||||
|
||||
### 4.4 More
|
||||
|
||||
The RARE model also supports the following inference deployment methods:
|
||||
|
||||
- Paddle2ONNX Inference: After preparing the inference model, refer to the [paddle2onnx](../../../version2.x/legacy/paddle2onnx.en.md) tutorial.
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
## Citation
|
||||
|
||||
````bibtex
|
||||
@inproceedings{2016Robust,
|
||||
title={Robust Scene Text Recognition with Automatic Rectification},
|
||||
author={ Shi, B. and Wang, X. and Lyu, P. and Cong, Y. and Xiang, B. },
|
||||
booktitle={2016 IEEE Conference on Computer Vision and Pattern Recognition (CVPR)},
|
||||
year={2016},
|
||||
}
|
||||
````
|
||||
@@ -0,0 +1,100 @@
|
||||
---
|
||||
comments: true
|
||||
---
|
||||
|
||||
# RARE
|
||||
|
||||
## 1. 算法简介
|
||||
|
||||
论文信息:
|
||||
> [Robust Scene Text Recognition with Automatic Rectification](https://arxiv.org/abs/1603.03915v2)
|
||||
> Baoguang Shi, Xinggang Wang, Pengyuan Lyu, Cong Yao, Xiang Bai∗
|
||||
> CVPR, 2016
|
||||
|
||||
使用MJSynth和SynthText两个文字识别数据集训练,在IIIT, SVT, IC03, IC13, IC15, SVTP, CUTE数据集上进行评估,算法复现效果如下:
|
||||
|
||||
|模型|骨干网络|配置文件|Avg Accuracy|下载链接|
|
||||
| --- | --- | --- | --- | --- |
|
||||
|RARE|Resnet34_vd|[configs/rec/rec_r34_vd_tps_bilstm_att.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/rec/rec_r34_vd_tps_bilstm_att.yml)|83.60%|[训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_r34_vd_tps_bilstm_att_v2.0_train.tar)|
|
||||
|RARE|MobileNetV3|[configs/rec/rec_mv3_tps_bilstm_att.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/rec/rec_mv3_tps_bilstm_att.yml)|82.50%|[训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_mv3_tps_bilstm_att_v2.0_train.tar)|
|
||||
|
||||
## 2. 环境配置
|
||||
|
||||
请先参考[《运行环境准备》](../../ppocr/environment.md)配置PaddleOCR运行环境,参考[《项目克隆》](../../ppocr/blog/clone.md)克隆项目代码。
|
||||
|
||||
## 3. 模型训练、评估、预测
|
||||
|
||||
请参考[文本识别训练教程](../../ppocr/model_train/recognition.md)。PaddleOCR对代码进行了模块化,训练不同的识别模型只需要**更换配置文件**即可。以基于Resnet34_vd骨干网络为例:
|
||||
|
||||
### 3.1 训练
|
||||
|
||||
```bash linenums="1"
|
||||
# 单卡训练(训练周期长,不建议)
|
||||
python3 tools/train.py -c configs/rec/rec_r34_vd_tps_bilstm_att.yml
|
||||
# 多卡训练,通过--gpus参数指定卡号
|
||||
python3 -m paddle.distributed.launch --gpus '0,1,2,3' tools/train.py -c configs/rec/rec_r34_vd_tps_bilstm_att.yml
|
||||
```
|
||||
|
||||
### 3.2 评估
|
||||
|
||||
```bash linenums="1"
|
||||
# GPU评估, Global.pretrained_model为待评估模型
|
||||
python3 -m paddle.distributed.launch --gpus '0' tools/eval.py -c configs/rec/rec_r34_vd_tps_bilstm_att.yml -o Global.pretrained_model={path/to/weights}/best_accuracy
|
||||
```
|
||||
|
||||
### 3.3 预测
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer_rec.py -c configs/rec/rec_r34_vd_tps_bilstm_att.yml -o Global.pretrained_model={path/to/weights}/best_accuracy Global.infer_img=doc/imgs_words/en/word_1.png
|
||||
```
|
||||
|
||||
## 4. 推理部署
|
||||
|
||||
### 4.1 Python推理
|
||||
|
||||
首先将RARE文本识别训练过程中保存的模型,转换成inference model。以基于Resnet34_vd骨干网络,在MJSynth和SynthText两个文字识别数据集训练得到的模型为例( [模型下载地址](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_r34_vd_tps_bilstm_att_v2.0_train.tar) ),可以使用如下命令进行转换:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/export_model.py -c configs/rec/rec_r34_vd_tps_bilstm_att.yml -o Global.pretrained_model=./rec_r34_vd_tps_bilstm_att_v2.0_train/best_accuracy Global.save_inference_dir=./inference/rec_rare
|
||||
```
|
||||
|
||||
RARE文本识别模型推理,可以执行如下命令:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_rec.py --image_dir="doc/imgs_words/en/word_1.png" --rec_model_dir="./inference/rec_rare/" --rec_image_shape="3, 32, 100" --rec_char_dict_path="./ppocr/utils/ic15_dict.txt"
|
||||
```
|
||||
|
||||
推理结果如下所示:
|
||||
|
||||

|
||||
|
||||
```text linenums="1"
|
||||
Predicts of doc/imgs_words/en/word_1.png:('joint ', 0.9999969601631165)
|
||||
```
|
||||
|
||||
### 4.2 C++推理
|
||||
|
||||
暂不支持
|
||||
|
||||
### 4.3 Serving服务化部署
|
||||
|
||||
暂不支持
|
||||
|
||||
### 4.4 更多推理部署
|
||||
|
||||
RARE模型还支持以下推理部署方式:
|
||||
|
||||
- Paddle2ONNX推理:准备好推理模型后,参考[paddle2onnx](../../../version2.x/legacy/paddle2onnx.md)教程操作。
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
## 引用
|
||||
|
||||
```bibtex
|
||||
@inproceedings{2016Robust,
|
||||
title={Robust Scene Text Recognition with Automatic Rectification},
|
||||
author={ Shi, B. and Wang, X. and Lyu, P. and Cong, Y. and Xiang, B. },
|
||||
booktitle={2016 IEEE Conference on Computer Vision and Pattern Recognition (CVPR)},
|
||||
year={2016},
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,126 @@
|
||||
---
|
||||
comments: true
|
||||
---
|
||||
|
||||
# RFL
|
||||
|
||||
## 1. Introduction
|
||||
|
||||
Paper:
|
||||
> [Reciprocal Feature Learning via Explicit and Implicit Tasks in Scene Text Recognition](https://arxiv.org/abs/2105.06229.pdf)
|
||||
> Hui Jiang, Yunlu Xu, Zhanzhan Cheng, Shiliang Pu, Yi Niu, Wenqi Ren, Fei Wu, and Wenming Tan
|
||||
> ICDAR, 2021
|
||||
|
||||
Using MJSynth and SynthText two text recognition datasets for training, and evaluating on IIIT, SVT, IC03, IC13, IC15, SVTP, CUTE datasets, the algorithm reproduction effect is as follows:
|
||||
|
||||
|Model|Backbone|config|Acc|Download link|
|
||||
| --- | --- | --- | --- | --- |
|
||||
|RFL-CNT|ResNetRFL|[rec_resnet_rfl_visual.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/rec/rec_resnet_rfl_visual.yml)|93.40%|[训练模型](https://paddleocr.bj.bcebos.com/contribution/rec_resnet_rfl_visual_train.tar)|
|
||||
|RFL-Att|ResNetRFL|[rec_resnet_rfl_att.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/rec/rec_resnet_rfl_att.yml)|88.63%|[训练模型](https://paddleocr.bj.bcebos.com/contribution/rec_resnet_rfl_att_train.tar)|
|
||||
|
||||
## 2. Environment
|
||||
|
||||
Please refer to ["Environment Preparation"](../../ppocr/environment.en.md) to configure the PaddleOCR environment, and refer to ["Project Clone"](../../ppocr/blog/clone.en.md)to clone the project code.
|
||||
|
||||
## 3. Model Training / Evaluation / Prediction
|
||||
|
||||
PaddleOCR modularizes the code, and training different recognition models only requires **changing the configuration file**.
|
||||
|
||||
### Training
|
||||
|
||||
Specifically, after the data preparation is completed, the training can be started. The training command is as follows:
|
||||
|
||||
```bash linenums="1"
|
||||
#step1:train the CNT branch
|
||||
# Single GPU training (long training period, not recommended)
|
||||
python3 tools/train.py -c configs/rec/rec_resnet_rfl_visual.yml
|
||||
|
||||
# Multi GPU training, specify the gpu number through the --gpus parameter
|
||||
python3 -m paddle.distributed.launch --gpus '0,1,2,3' tools/train.py -c configs/rec/rec_resnet_rfl_visual.yml
|
||||
|
||||
#step2:joint training of CNT and Att branches
|
||||
# Single GPU training (long training period, not recommended)
|
||||
python3 tools/train.py -c configs/rec/rec_resnet_rfl_att.yml -o Global.pretrained_model={path/to/weights}/best_accuracy
|
||||
|
||||
# Multi GPU training, specify the gpu number through the --gpus parameter
|
||||
python3 -m paddle.distributed.launch --gpus '0,1,2,3' tools/train.py -c configs/rec/rec_resnet_rfl_att.yml -o Global.pretrained_model={path/to/weights}/best_accuracy
|
||||
```
|
||||
|
||||
### Evaluation
|
||||
|
||||
```bash linenums="1"
|
||||
# GPU evaluation
|
||||
python3 -m paddle.distributed.launch --gpus '0' tools/eval.py -c configs/rec/rec_resnet_rfl_att.yml -o Global.pretrained_model={path/to/weights}/best_accuracy
|
||||
```
|
||||
|
||||
### Prediction
|
||||
|
||||
```bash linenums="1"
|
||||
# The configuration file used for prediction must match the training
|
||||
python3 tools/infer_rec.py -c configs/rec/rec_resnet_rfl_att.yml -o Global.infer_img='./doc/imgs_words_en/word_10.png' Global.pretrained_model={path/to/weights}/best_accuracy
|
||||
```
|
||||
|
||||
## 4. Inference and Deployment
|
||||
|
||||
### 4.1 Python Inference
|
||||
|
||||
First, the model saved during the RFL text recognition training process is converted into an inference model. ( [Model download link](https://paddleocr.bj.bcebos.com/contribution/rec_resnet_rfl.tar)) ), you can use the following command to convert:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/export_model.py -c configs/rec/rec_resnet_rfl_att.yml -o Global.pretrained_model={path/to/weights}/best_accuracy Global.save_inference_dir=./inference/rec_resnet_rfl_att
|
||||
```
|
||||
|
||||
**Note:**
|
||||
|
||||
- If you are training the model on your own dataset and have modified the dictionary file, please pay attention to modify the `character_dict_path` in the configuration file to the modified dictionary file.
|
||||
- If you modified the input size during training, please modify the `infer_shape` corresponding to NRTR in the `tools/export_model.py` file.
|
||||
|
||||
After the conversion is successful, there are three files in the directory:
|
||||
|
||||
```text linenums="1"
|
||||
/inference/rec_resnet_rfl_att/
|
||||
├── inference.pdiparams
|
||||
├── inference.pdiparams.info
|
||||
└── inference.pdmodel
|
||||
```
|
||||
|
||||
For RFL text recognition model inference, the following commands can be executed:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_rec.py --image_dir='./doc/imgs_words_en/word_10.png' --rec_model_dir='./inference/rec_resnet_rfl_att/' --rec_algorithm='RFL' --rec_image_shape='1,32,100'
|
||||
```
|
||||
|
||||

|
||||
|
||||
After executing the command, the prediction result (recognized text and score) of the image above is printed to the screen, an example is as follows:
|
||||
The result is as follows:
|
||||
|
||||
```bash linenums="1"
|
||||
Predicts of ./doc/imgs_words_en/word_10.png:('pain', 0.9999927282333374)
|
||||
```
|
||||
|
||||
### 4.2 C++ Inference
|
||||
|
||||
Not supported
|
||||
|
||||
### 4.3 Serving
|
||||
|
||||
Not supported
|
||||
|
||||
### 4.4 More
|
||||
|
||||
Not supported
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
## Citation
|
||||
|
||||
```bibtex
|
||||
@article{2021Reciprocal,
|
||||
title = {Reciprocal Feature Learning via Explicit and Implicit Tasks in Scene Text Recognition},
|
||||
author = {Jiang, H. and Xu, Y. and Cheng, Z. and Pu, S. and Niu, Y. and Ren, W. and Wu, F. and Tan, W. },
|
||||
booktitle = {ICDAR},
|
||||
year = {2021},
|
||||
url = {https://arxiv.org/abs/2105.06229}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,140 @@
|
||||
---
|
||||
comments: true
|
||||
---
|
||||
|
||||
# 场景文本识别算法-RFL
|
||||
|
||||
## 1. 算法简介
|
||||
|
||||
论文信息:
|
||||
> [Reciprocal Feature Learning via Explicit and Implicit Tasks in Scene Text Recognition](https://arxiv.org/abs/2105.06229.pdf)
|
||||
> Hui Jiang, Yunlu Xu, Zhanzhan Cheng, Shiliang Pu, Yi Niu, Wenqi Ren, Fei Wu, and Wenming Tan
|
||||
> ICDAR, 2021
|
||||
|
||||
`RFL`使用MJSynth和SynthText两个文字识别数据集训练,在IIIT, SVT, IC03, IC13, IC15, SVTP, CUTE数据集上进行评估,算法复现效果如下:
|
||||
|
||||
|模型|骨干网络|配置文件|Acc|下载链接|
|
||||
| --- | --- | --- | --- | --- |
|
||||
|RFL-CNT|ResNetRFL|[rec_resnet_rfl_visual.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/rec/rec_resnet_rfl_visual.yml)|93.40%|[训练模型](https://paddleocr.bj.bcebos.com/contribution/rec_resnet_rfl_visual_train.tar)|
|
||||
|RFL-Att|ResNetRFL|[rec_resnet_rfl_att.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/rec/rec_resnet_rfl_att.yml)|88.63%|[训练模型](https://paddleocr.bj.bcebos.com/contribution/rec_resnet_rfl_att_train.tar)|
|
||||
|
||||
## 2. 环境配置
|
||||
|
||||
请先参考[《运行环境准备》](../../ppocr/environment.md)配置PaddleOCR运行环境,参考[《项目克隆》](../../ppocr/blog/clone.md)克隆项目代码。
|
||||
|
||||
## 3. 模型训练、评估、预测
|
||||
|
||||
### 3.1 模型训练
|
||||
|
||||
PaddleOCR对代码进行了模块化,训练`RFL`识别模型时需要**更换配置文件**为`RFL`的[配置文件](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/rec/rec_resnet_rfl_att.yml)。
|
||||
|
||||
#### 启动训练
|
||||
|
||||
具体地,在完成数据准备后,便可以启动训练,训练命令如下:
|
||||
|
||||
```bash linenums="1"
|
||||
#step1:训练CNT分支
|
||||
#单卡训练(训练周期长,不建议)
|
||||
python3 tools/train.py -c configs/rec/rec_resnet_rfl_visual.yml
|
||||
|
||||
# 多卡训练,通过--gpus参数指定卡号
|
||||
python3 -m paddle.distributed.launch --gpus '0,1,2,3' tools/train.py -c configs/rec/rec_resnet_rfl_visual.yml
|
||||
|
||||
#step2:联合训练CNT和Att分支,注意将pretrained_model的路径设置为本地路径。
|
||||
#单卡训练(训练周期长,不建议)
|
||||
python3 tools/train.py -c configs/rec/rec_resnet_rfl_att.yml -o Global.pretrained_model=./output/rec/rec_resnet_rfl_visual/best_accuracy
|
||||
|
||||
# 多卡训练,通过--gpus参数指定卡号
|
||||
python3 -m paddle.distributed.launch --gpus '0,1,2,3' tools/train.py -c configs/rec/rec_resnet_rfl_att.yml -o Global.pretrained_model=./output/rec/rec_resnet_rfl_visual/best_accuracy
|
||||
```
|
||||
|
||||
### 3.2 评估
|
||||
|
||||
可下载已训练完成的[模型文件](https://paddleocr.bj.bcebos.com/contribution/rec_resnet_rfl.tar),使用如下命令进行评估:
|
||||
|
||||
```bash linenums="1"
|
||||
# 注意将pretrained_model的路径设置为本地路径。
|
||||
python3 -m paddle.distributed.launch --gpus '0' tools/eval.py -c configs/rec/rec_resnet_rfl_att.yml -o Global.pretrained_model=./output/rec/rec_resnet_rfl_att/best_accuracy
|
||||
```
|
||||
|
||||
### 3.3 预测
|
||||
|
||||
使用如下命令进行单张图片预测:
|
||||
|
||||
```bash linenums="1"
|
||||
# 注意将pretrained_model的路径设置为本地路径。
|
||||
python3 tools/infer_rec.py -c configs/rec/rec_resnet_rfl_att.yml -o Global.infer_img='./doc/imgs_words_en/word_10.png' Global.pretrained_model=./output/rec/rec_resnet_rfl_att/best_accuracy
|
||||
# 预测文件夹下所有图像时,可修改infer_img为文件夹,如 Global.infer_img='./doc/imgs_words_en/'。
|
||||
```
|
||||
|
||||
## 4. 推理部署
|
||||
|
||||
### 4.1 Python推理
|
||||
|
||||
首先将训练得到best模型,转换成inference model。这里以训练完成的模型为例([模型下载地址](https://paddleocr.bj.bcebos.com/contribution/rec_resnet_rfl.tar) ),可以使用如下命令进行转换:
|
||||
|
||||
```bash linenums="1"
|
||||
# 注意将pretrained_model的路径设置为本地路径。
|
||||
python3 tools/export_model.py -c configs/rec/rec_resnet_rfl_att.yml -o Global.pretrained_model=./output/rec/rec_resnet_rfl_att/best_accuracy Global.save_inference_dir=./inference/rec_resnet_rfl_att/
|
||||
```
|
||||
|
||||
**注意:** 如果您是在自己的数据集上训练的模型,并且调整了字典文件,请注意修改配置文件中的`character_dict_path`是否是所需要的字典文件。
|
||||
|
||||
- 如果您修改了训练时的输入大小,请修改`tools/export_model.py`文件中的对应RFL的`infer_shape`。
|
||||
|
||||
转换成功后,在目录下有三个文件:
|
||||
|
||||
```text linenums="1"
|
||||
/inference/rec_resnet_rfl_att/
|
||||
├── inference.pdiparams # 识别inference模型的参数文件
|
||||
├── inference.pdiparams.info # 识别inference模型的参数信息,可忽略
|
||||
└── inference.pdmodel # 识别inference模型的program文件
|
||||
```
|
||||
|
||||
执行如下命令进行模型推理:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_rec.py --image_dir='./doc/imgs_words_en/word_10.png' --rec_model_dir='./inference/rec_resnet_rfl_att/' --rec_algorithm='RFL' --rec_image_shape='1,32,100'
|
||||
# 预测文件夹下所有图像时,可修改image_dir为文件夹,如 --image_dir='./doc/imgs_words_en/'。
|
||||
```
|
||||
|
||||

|
||||
|
||||
执行命令后,上面图像的预测结果(识别的文本和得分)会打印到屏幕上,示例如下:
|
||||
结果如下:
|
||||
|
||||
```bash linenums="1"
|
||||
Predicts of ./doc/imgs_words_en/word_10.png:('pain', 0.9999927282333374)
|
||||
```
|
||||
|
||||
**注意**:
|
||||
|
||||
- 训练上述模型采用的图像分辨率是[1,32,100],需要通过参数`rec_image_shape`设置为您训练时的识别图像形状。
|
||||
- 在推理时需要设置参数`rec_char_dict_path`指定字典,如果您修改了字典,请修改该参数为您的字典文件。
|
||||
- 如果您修改了预处理方法,需修改`tools/infer/predict_rec.py`中RFL的预处理为您的预处理方法。
|
||||
|
||||
### 4.2 C++推理部署
|
||||
|
||||
由于C++预处理后处理还未支持RFL,所以暂未支持
|
||||
|
||||
### 4.3 Serving服务化部署
|
||||
|
||||
暂不支持
|
||||
|
||||
### 4.4 更多推理部署
|
||||
|
||||
暂不支持
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
## 引用
|
||||
|
||||
```bibtex
|
||||
@article{2021Reciprocal,
|
||||
title = {Reciprocal Feature Learning via Explicit and Implicit Tasks in Scene Text Recognition},
|
||||
author = {Jiang, H. and Xu, Y. and Cheng, Z. and Pu, S. and Niu, Y. and Ren, W. and Wu, F. and Tan, W. },
|
||||
booktitle = {ICDAR},
|
||||
year = {2021},
|
||||
url = {https://arxiv.org/abs/2105.06229}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,96 @@
|
||||
---
|
||||
comments: true
|
||||
---
|
||||
|
||||
# RobustScanner
|
||||
|
||||
## 1. Introduction
|
||||
|
||||
Paper:
|
||||
> [RobustScanner: Dynamically Enhancing Positional Clues for Robust Text Recognition](https://arxiv.org/pdf/2007.07542.pdf)
|
||||
> Xiaoyu Yue, Zhanghui Kuang, Chenhao Lin, Hongbin Sun, Wayne
|
||||
Zhang
|
||||
> ECCV, 2020
|
||||
|
||||
Using MJSynth and SynthText two text recognition datasets for training, and evaluating on IIIT, SVT, IC13, IC15, SVTP, CUTE datasets, the algorithm reproduction effect is as follows:
|
||||
|
||||
|Model|Backbone|config|Acc|Download link|
|
||||
| --- | --- | --- | --- | --- |
|
||||
|RobustScanner|ResNet31|[rec_r31_robustscanner.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/rec/rec_r31_robustscanner.yml)|87.77%|[trained model](https://paddleocr.bj.bcebos.com/contribution/rec_r31_robustscanner.tar)|
|
||||
|
||||
Note:In addition to using the two text recognition datasets MJSynth and SynthText, [SynthAdd](https://pan.baidu.com/share/init?surl=uV0LtoNmcxbO-0YA7Ch4dg) data (extraction code: 627x), and some real data are used in training, the specific data details can refer to the paper.
|
||||
|
||||
## 2. Environment
|
||||
|
||||
Please refer to ["Environment Preparation"](../../ppocr/environment.en.md) to configure the PaddleOCR environment, and refer to ["Project Clone"](../../ppocr/blog/clone.en.md)to clone the project code.
|
||||
|
||||
## 3. Model Training / Evaluation / Prediction
|
||||
|
||||
Please refer to [Text Recognition Tutorial](../../ppocr/model_train/recognition.en.md). PaddleOCR modularizes the code, and training different recognition models only requires **changing the configuration file**.
|
||||
|
||||
### Training
|
||||
|
||||
Specifically, after the data preparation is completed, the training can be started. The training command is as follows:
|
||||
|
||||
```bash linenums="1"
|
||||
# Single GPU training (long training period, not recommended)
|
||||
python3 tools/train.py -c configs/rec/rec_r31_robustscanner.yml
|
||||
|
||||
# Multi GPU training, specify the gpu number through the --gpus parameter
|
||||
python3 -m paddle.distributed.launch --gpus '0,1,2,3' tools/train.py -c configs/rec/rec_r31_robustscanner.yml
|
||||
```
|
||||
|
||||
### Evaluation
|
||||
|
||||
```bash linenums="1"
|
||||
# GPU evaluation
|
||||
python3 -m paddle.distributed.launch --gpus '0' tools/eval.py -c configs/rec/rec_r31_robustscanner.yml -o Global.pretrained_model={path/to/weights}/best_accuracy
|
||||
```
|
||||
|
||||
### Prediction
|
||||
|
||||
```bash linenums="1"
|
||||
# The configuration file used for prediction must match the training
|
||||
python3 tools/infer_rec.py -c configs/rec/rec_r31_robustscanner.yml -o Global.pretrained_model={path/to/weights}/best_accuracy Global.infer_img=doc/imgs_words/en/word_1.png
|
||||
```
|
||||
|
||||
## 4. Inference and Deployment
|
||||
|
||||
### 4.1 Python Inference
|
||||
|
||||
First, the model saved during the RobustScanner text recognition training process is converted into an inference model. you can use the following command to convert:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/export_model.py -c configs/rec/rec_r31_robustscanner.yml -o Global.pretrained_model={path/to/weights}/best_accuracy Global.save_inference_dir=./inference/rec_r31_robustscanner
|
||||
```
|
||||
|
||||
For RobustScanner text recognition model inference, the following commands can be executed:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_rec.py --image_dir="./doc/imgs_words/en/word_1.png" --rec_model_dir="./inference/rec_r31_robustscanner/" --rec_image_shape="3, 48, 48, 160" --rec_algorithm="RobustScanner" --rec_char_dict_path="ppocr/utils/dict90.txt" --use_space_char=False
|
||||
```
|
||||
|
||||
### 4.2 C++ Inference
|
||||
|
||||
Not supported
|
||||
|
||||
### 4.3 Serving
|
||||
|
||||
Not supported
|
||||
|
||||
### 4.4 More
|
||||
|
||||
Not supported
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
## Citation
|
||||
|
||||
```bibtex
|
||||
@article{2020RobustScanner,
|
||||
title={RobustScanner: Dynamically Enhancing Positional Clues for Robust Text Recognition},
|
||||
author={Xiaoyu Yue and Zhanghui Kuang and Chenhao Lin and Hongbin Sun and Wayne Zhang},
|
||||
journal={ECCV2020},
|
||||
year={2020},
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,97 @@
|
||||
---
|
||||
typora-copy-images-to: images
|
||||
comments: true
|
||||
---
|
||||
|
||||
# RobustScanner
|
||||
|
||||
## 1. 算法简介
|
||||
|
||||
论文信息:
|
||||
> [RobustScanner: Dynamically Enhancing Positional Clues for Robust Text Recognition](https://arxiv.org/pdf/2007.07542.pdf)
|
||||
> Xiaoyu Yue, Zhanghui Kuang, Chenhao Lin, Hongbin Sun, Wayne
|
||||
Zhang
|
||||
> ECCV, 2020
|
||||
|
||||
使用MJSynth和SynthText两个合成文字识别数据集训练,在IIIT, SVT, IC13, IC15, SVTP, CUTE数据集上进行评估,算法复现效果如下:
|
||||
|
||||
|模型|骨干网络|配置文件|Acc|下载链接|
|
||||
| --- | --- | --- | --- | --- |
|
||||
|RobustScanner|ResNet31|[rec_r31_robustscanner.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/rec/rec_r31_robustscanner.yml)|87.77%|[训练模型](https://paddleocr.bj.bcebos.com/contribution/rec_r31_robustscanner.tar)|
|
||||
|
||||
注:除了使用MJSynth和SynthText两个文字识别数据集外,还加入了[SynthAdd](https://pan.baidu.com/share/init?surl=uV0LtoNmcxbO-0YA7Ch4dg)数据(提取码:627x),和部分真实数据,具体数据细节可以参考论文。
|
||||
|
||||
## 2. 环境配置
|
||||
|
||||
请先参考[《运行环境准备》](../../ppocr/environment.md)配置PaddleOCR运行环境,参考[《项目克隆》](../../ppocr/blog/clone.md)克隆项目代码。
|
||||
|
||||
## 3. 模型训练、评估、预测
|
||||
|
||||
请参考[文本识别教程](../../ppocr/model_train/recognition.md)。PaddleOCR对代码进行了模块化,训练不同的识别模型只需要**更换配置文件**即可。
|
||||
|
||||
### 训练
|
||||
|
||||
具体地,在完成数据准备后,便可以启动训练,训练命令如下:
|
||||
|
||||
```bash linenums="1"
|
||||
#单卡训练(训练周期长,不建议)
|
||||
python3 tools/train.py -c configs/rec/rec_r31_robustscanner.yml
|
||||
|
||||
# 多卡训练,通过--gpus参数指定卡号
|
||||
python3 -m paddle.distributed.launch --gpus '0,1,2,3' tools/train.py -c configs/rec/rec_r31_robustscanner.yml
|
||||
```
|
||||
|
||||
### 评估
|
||||
|
||||
```bash linenums="1"
|
||||
# GPU 评估, Global.pretrained_model 为待测权重
|
||||
python3 -m paddle.distributed.launch --gpus '0' tools/eval.py -c configs/rec/rec_r31_robustscanner.yml -o Global.pretrained_model={path/to/weights}/best_accuracy
|
||||
```
|
||||
|
||||
### 预测
|
||||
|
||||
```bash linenums="1"
|
||||
# 预测使用的配置文件必须与训练一致
|
||||
python3 tools/infer_rec.py -c configs/rec/rec_r31_robustscanner.yml -o Global.pretrained_model={path/to/weights}/best_accuracy Global.infer_img=doc/imgs_words/en/word_1.png
|
||||
```
|
||||
|
||||
## 4. 推理部署
|
||||
|
||||
### 4.1 Python推理
|
||||
|
||||
首先将RobustScanner文本识别训练过程中保存的模型,转换成inference model。可以使用如下命令进行转换:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/export_model.py -c configs/rec/rec_r31_robustscanner.yml -o Global.pretrained_model={path/to/weights}/best_accuracy Global.save_inference_dir=./inference/rec_r31_robustscanner
|
||||
```
|
||||
|
||||
RobustScanner文本识别模型推理,可以执行如下命令:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_rec.py --image_dir="./doc/imgs_words/en/word_1.png" --rec_model_dir="./inference/rec_r31_robustscanner/" --rec_image_shape="3, 48, 48, 160" --rec_algorithm="RobustScanner" --rec_char_dict_path="ppocr/utils/dict90.txt" --use_space_char=False
|
||||
```
|
||||
|
||||
### 4.2 C++推理
|
||||
|
||||
由于C++预处理后处理还未支持RobustScanner,所以暂未支持
|
||||
|
||||
### 4.3 Serving服务化部署
|
||||
|
||||
暂不支持
|
||||
|
||||
### 4.4 更多推理部署
|
||||
|
||||
暂不支持
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
## 引用
|
||||
|
||||
```bibtex
|
||||
@article{2020RobustScanner,
|
||||
title={RobustScanner: Dynamically Enhancing Positional Clues for Robust Text Recognition},
|
||||
author={Xiaoyu Yue and Zhanghui Kuang and Chenhao Lin and Hongbin Sun and Wayne Zhang},
|
||||
journal={ECCV2020},
|
||||
year={2020},
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,100 @@
|
||||
---
|
||||
comments: true
|
||||
---
|
||||
|
||||
# Rosetta
|
||||
|
||||
## 1. Introduction
|
||||
|
||||
Paper information:
|
||||
> [Rosetta: Large Scale System for Text Detection and Recognition in Images](https://arxiv.org/abs/1910.05085)
|
||||
> Borisyuk F , Gordo A , V Sivakumar
|
||||
> KDD, 2018
|
||||
|
||||
Using MJSynth and SynthText two text recognition datasets for training, and evaluating on IIIT, SVT, IC03, IC13, IC15, SVTP, CUTE datasets, the algorithm reproduction effect is as follows:
|
||||
|
||||
|Models|Backbone Networks|Configuration Files|Avg Accuracy|Download Links|
|
||||
| --- | --- | --- | --- | --- |
|
||||
|Rosetta|Resnet34_vd|[configs/rec/rec_r34_vd_none_none_ctc.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/rec/rec_r34_vd_none_none_ctc.yml)|79.11%|[training model](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_r34_vd_none_none_ctc_v2.0_train.tar)|
|
||||
|Rosetta|MobileNetV3|[configs/rec/rec_mv3_none_none_ctc.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/rec/rec_mv3_none_none_ctc.yml)|75.80%|[training model](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_mv3_none_none_ctc_v2.0_train.tar)|
|
||||
|
||||
## 2. Environment
|
||||
|
||||
Please refer to [Operating Environment Preparation](../../ppocr/environment.en.md) to configure the PaddleOCR operating environment, and refer to [Project Clone](../../ppocr/blog/clone.en.md)to clone the project code.
|
||||
|
||||
## 3. Model Training / Evaluation / Prediction
|
||||
|
||||
Please refer to [Text Recognition Training Tutorial](../../ppocr/model_train/recognition.en.md). PaddleOCR modularizes the code, and training different recognition models only requires **changing the configuration file**. Take the backbone network based on Resnet34_vd as an example:
|
||||
|
||||
### 3.1 Training
|
||||
|
||||
```bash linenums="1"
|
||||
# Single card training (long training period, not recommended)
|
||||
python3 tools/train.py -c configs/rec/rec_r34_vd_none_none_ctc.yml
|
||||
# Multi-card training, specify the card number through the --gpus parameter
|
||||
python3 -m paddle.distributed.launch --gpus '0,1,2,3' tools/train.py -c configs/rec/rec_r34_vd_none_none_ctc.yml
|
||||
```
|
||||
|
||||
### 3.2 Evaluation
|
||||
|
||||
```bash linenums="1"
|
||||
# GPU evaluation, Global.pretrained_model is the model to be evaluated
|
||||
python3 -m paddle.distributed.launch --gpus '0' tools/eval.py -c configs/rec/rec_r34_vd_none_none_ctc.yml -o Global.pretrained_model={path/to/weights}/best_accuracy
|
||||
```
|
||||
|
||||
### 3.3 Prediction
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer_rec.py -c configs/rec/rec_r34_vd_none_none_ctc.yml -o Global.pretrained_model={path/to/weights}/best_accuracy Global.infer_img=doc/imgs_words/en/word_1.png
|
||||
```
|
||||
|
||||
## 4. Inference and Deployment
|
||||
|
||||
### 4.1 Python Inference
|
||||
|
||||
First, convert the model saved during the Rosetta text recognition training process into an inference model. Take the model trained on the MJSynth and SynthText text recognition datasets based on the Resnet34_vd backbone network as an example ( [Model download address](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_r34_vd_none_none_ctc_v2.0_train.tar) ), which can be converted using the following command:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/export_model.py -c configs/rec/rec_r34_vd_none_none_ctc.yml -o Global.pretrained_model=./rec_r34_vd_none_none_ctc_v2.0_train/best_accuracy Global.save_inference_dir=./inference/rec_rosetta
|
||||
```
|
||||
|
||||
Rosetta text recognition model inference, you can execute the following commands:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_rec.py --image_dir="doc/imgs_words/en/word_1.png" --rec_model_dir="./inference/rec_rosetta/" --rec_image_shape="3, 32, 100" --rec_char_dict_path= "./ppocr/utils/ic15_dict.txt"
|
||||
```
|
||||
|
||||
The inference results are as follows:
|
||||
|
||||

|
||||
|
||||
```bash linenums="1"
|
||||
Predicts of doc/imgs_words/en/word_1.png:('joint', 0.9999982714653015)
|
||||
```
|
||||
|
||||
### 4.2 C++ Inference
|
||||
|
||||
Not currently supported
|
||||
|
||||
### 4.3 Serving
|
||||
|
||||
Not currently supported
|
||||
|
||||
### 4.4 More
|
||||
|
||||
The Rosetta model also supports the following inference deployment methods:
|
||||
|
||||
- Paddle2ONNX Inference: After preparing the inference model, refer to the [paddle2onnx](../../../version2.x/legacy/paddle2onnx.en.md) tutorial.
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
## Citation
|
||||
|
||||
```bibtex
|
||||
@inproceedings{2018Rosetta,
|
||||
title={Rosetta: Large Scale System for Text Detection and Recognition in Images},
|
||||
author={ Borisyuk, Fedor and Gordo, Albert and Sivakumar, Viswanath },
|
||||
booktitle={the 24th ACM SIGKDD International Conference},
|
||||
year={2018},
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,101 @@
|
||||
---
|
||||
typora-copy-images-to: images
|
||||
comments: true
|
||||
---
|
||||
|
||||
# Rosetta
|
||||
|
||||
## 1. 算法简介
|
||||
|
||||
论文信息:
|
||||
> [Rosetta: Large Scale System for Text Detection and Recognition in Images](https://arxiv.org/abs/1910.05085)
|
||||
> Borisyuk F , Gordo A , V Sivakumar
|
||||
> KDD, 2018
|
||||
|
||||
使用MJSynth和SynthText两个文字识别数据集训练,在IIIT, SVT, IC03, IC13, IC15, SVTP, CUTE数据集上进行评估, 算法复现效果如下:
|
||||
|
||||
|模型|骨干网络|配置文件|Avg Accuracy|下载链接|
|
||||
| --- | --- | --- | --- | --- |
|
||||
|Rosetta|Resnet34_vd|[configs/rec/rec_r34_vd_none_none_ctc.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/rec/rec_r34_vd_none_none_ctc.yml)|79.11%|[训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_r34_vd_none_none_ctc_v2.0_train.tar)|
|
||||
|Rosetta|MobileNetV3|[configs/rec/rec_mv3_none_none_ctc.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/rec/rec_mv3_none_none_ctc.yml)|75.80%|[训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_mv3_none_none_ctc_v2.0_train.tar)|
|
||||
|
||||
## 2. 环境配置
|
||||
|
||||
请先参考[《运行环境准备》](../../ppocr/environment.md)配置PaddleOCR运行环境,参考[《项目克隆》](../../ppocr/blog/clone.md)克隆项目代码。
|
||||
|
||||
## 3. 模型训练、评估、预测
|
||||
|
||||
请参考[文本识别训练教程](../../ppocr/model_train/recognition.md)。PaddleOCR对代码进行了模块化,训练不同的识别模型只需要**更换配置文件**即可。 以基于Resnet34_vd骨干网络为例:
|
||||
|
||||
### 3.1 训练
|
||||
|
||||
```bash linenums="1"
|
||||
# 单卡训练(训练周期长,不建议)
|
||||
python3 tools/train.py -c configs/rec/rec_r34_vd_none_none_ctc.yml
|
||||
# 多卡训练,通过--gpus参数指定卡号
|
||||
python3 -m paddle.distributed.launch --gpus '0,1,2,3' tools/train.py -c configs/rec/rec_r34_vd_none_none_ctc.yml
|
||||
```
|
||||
|
||||
### 3.2 评估
|
||||
|
||||
```bash linenums="1"
|
||||
# GPU评估, Global.pretrained_model为待评估模型
|
||||
python3 -m paddle.distributed.launch --gpus '0' tools/eval.py -c configs/rec/rec_r34_vd_none_none_ctc.yml -o Global.pretrained_model={path/to/weights}/best_accuracy
|
||||
```
|
||||
|
||||
### 3.3 预测
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer_rec.py -c configs/rec/rec_r34_vd_none_none_ctc.yml -o Global.pretrained_model={path/to/weights}/best_accuracy Global.infer_img=doc/imgs_words/en/word_1.png
|
||||
```
|
||||
|
||||
## 4. 推理部署
|
||||
|
||||
### 4.1 Python推理
|
||||
|
||||
首先将Rosetta文本识别训练过程中保存的模型,转换成inference model。以基于Resnet34_vd骨干网络,在MJSynth和SynthText两个文字识别数据集训练得到的模型为例( [模型下载地址](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_r34_vd_none_none_ctc_v2.0_train.tar) ),可以使用如下命令进行转换:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/export_model.py -c configs/rec/rec_r34_vd_none_none_ctc.yml -o Global.pretrained_model=./rec_r34_vd_none_none_ctc_v2.0_train/best_accuracy Global.save_inference_dir=./inference/rec_rosetta
|
||||
```
|
||||
|
||||
Rosetta文本识别模型推理,可以执行如下命令:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_rec.py --image_dir="doc/imgs_words/en/word_1.png" --rec_model_dir="./inference/rec_rosetta/" --rec_image_shape="3, 32, 100" --rec_char_dict_path="./ppocr/utils/ic15_dict.txt"
|
||||
```
|
||||
|
||||
推理结果如下所示:
|
||||
|
||||

|
||||
|
||||
```bash linenums="1"
|
||||
Predicts of doc/imgs_words/en/word_1.png:('joint', 0.9999982714653015)
|
||||
```
|
||||
|
||||
### 4.2 C++推理
|
||||
|
||||
暂不支持
|
||||
|
||||
### 4.3 Serving服务化部署
|
||||
|
||||
暂不支持
|
||||
|
||||
### 4.4 更多推理部署
|
||||
|
||||
Rosetta模型还支持以下推理部署方式:
|
||||
|
||||
- Paddle2ONNX推理:准备好推理模型后,参考[paddle2onnx](../../../version2.x/legacy/paddle2onnx.md)教程操作。
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
## 引用
|
||||
|
||||
```bibtex
|
||||
@inproceedings{2018Rosetta,
|
||||
title={Rosetta: Large Scale System for Text Detection and Recognition in Images},
|
||||
author={ Borisyuk, Fedor and Gordo, Albert and Sivakumar, Viswanath },
|
||||
booktitle={the 24th ACM SIGKDD International Conference},
|
||||
year={2018},
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,96 @@
|
||||
---
|
||||
comments: true
|
||||
---
|
||||
|
||||
# SAR
|
||||
|
||||
## 1. Introduction
|
||||
|
||||
Paper:
|
||||
> [Show, Attend and Read: A Simple and Strong Baseline for Irregular Text Recognition](https://arxiv.org/abs/1811.00751)
|
||||
> Hui Li, Peng Wang, Chunhua Shen, Guyu Zhang
|
||||
> AAAI, 2019
|
||||
|
||||
Using MJSynth and SynthText two text recognition datasets for training, and evaluating on IIIT, SVT, IC03, IC13, IC15, SVTP, CUTE datasets, the algorithm reproduction effect is as follows:
|
||||
|
||||
|Model|Backbone|config|Acc|Download link|
|
||||
| --- | --- | --- | --- | --- |
|
||||
|SAR|ResNet31|[rec_r31_sar.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/rec/rec_r31_sar.yml)|87.20%|[train model](https://paddleocr.bj.bcebos.com/dygraph_v2.1/rec/rec_r31_sar_train.tar)|
|
||||
|
||||
Note:In addition to using the two text recognition datasets MJSynth and SynthText, [SynthAdd](https://pan.baidu.com/share/init?surl=uV0LtoNmcxbO-0YA7Ch4dg) data (extraction code: 627x), and some real data are used in training, the specific data details can refer to the paper.
|
||||
|
||||
## 2. Environment
|
||||
|
||||
Please refer to ["Environment Preparation"](../../ppocr/environment.en.md) to configure the PaddleOCR environment, and refer to ["Project Clone"](../../ppocr/blog/clone.en.md)to clone the project code.
|
||||
|
||||
## 3. Model Training / Evaluation / Prediction
|
||||
|
||||
Please refer to [Text Recognition Tutorial](../../ppocr/model_train/recognition.en.md). PaddleOCR modularizes the code, and training different recognition models only requires **changing the configuration file**.
|
||||
|
||||
### Training
|
||||
|
||||
Specifically, after the data preparation is completed, the training can be started. The training command is as follows:
|
||||
|
||||
```bash linenums="1"
|
||||
# Single GPU training (long training period, not recommended)
|
||||
python3 tools/train.py -c configs/rec/rec_r31_sar.yml
|
||||
|
||||
# Multi GPU training, specify the gpu number through the --gpus parameter
|
||||
python3 -m paddle.distributed.launch --gpus '0,1,2,3' tools/train.py -c configs/rec/rec_r31_sar.yml
|
||||
```
|
||||
|
||||
### Evaluation
|
||||
|
||||
```bash linenums="1"
|
||||
# GPU evaluation
|
||||
python3 -m paddle.distributed.launch --gpus '0' tools/eval.py -c configs/rec/rec_r31_sar.yml -o Global.pretrained_model={path/to/weights}/best_accuracy
|
||||
```
|
||||
|
||||
### Prediction
|
||||
|
||||
```bash linenums="1"
|
||||
# The configuration file used for prediction must match the training
|
||||
python3 tools/infer_rec.py -c configs/rec/rec_r31_sar.yml -o Global.pretrained_model={path/to/weights}/best_accuracy Global.infer_img=doc/imgs_words/en/word_1.png
|
||||
```
|
||||
|
||||
## 4. Inference and Deployment
|
||||
|
||||
### 4.1 Python Inference
|
||||
|
||||
First, the model saved during the SAR text recognition training process is converted into an inference model. ( [Model download link](https://paddleocr.bj.bcebos.com/dygraph_v2.1/rec/rec_r31_sar_train.tar) ), you can use the following command to convert:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/export_model.py -c configs/rec/rec_r31_sar.yml -o Global.pretrained_model=./rec_r31_sar_train/best_accuracy Global.save_inference_dir=./inference/rec_sar
|
||||
```
|
||||
|
||||
For SAR text recognition model inference, the following commands can be executed:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_rec.py --image_dir="./doc/imgs_words/en/word_1.png" --rec_model_dir="./inference/rec_sar/" --rec_image_shape="3, 48, 48, 160" --rec_algorithm="SAR" --rec_char_dict_path="ppocr/utils/dict90.txt" --max_text_length=30 --use_space_char=False
|
||||
```
|
||||
|
||||
### 4.2 C++ Inference
|
||||
|
||||
Not supported
|
||||
|
||||
### 4.3 Serving
|
||||
|
||||
Not supported
|
||||
|
||||
### 4.4 More
|
||||
|
||||
Not supported
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
## Citation
|
||||
|
||||
```bibtex
|
||||
@article{Li2019ShowAA,
|
||||
title={Show, Attend and Read: A Simple and Strong Baseline for Irregular Text Recognition},
|
||||
author={Hui Li and Peng Wang and Chunhua Shen and Guyu Zhang},
|
||||
journal={ArXiv},
|
||||
year={2019},
|
||||
volume={abs/1811.00751}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,96 @@
|
||||
---
|
||||
comments: true
|
||||
---
|
||||
|
||||
# SAR
|
||||
|
||||
## 1. 算法简介
|
||||
|
||||
论文信息:
|
||||
> [Show, Attend and Read: A Simple and Strong Baseline for Irregular Text Recognition](https://arxiv.org/abs/1811.00751)
|
||||
> Hui Li, Peng Wang, Chunhua Shen, Guyu Zhang
|
||||
> AAAI, 2019
|
||||
|
||||
使用MJSynth和SynthText两个文字识别数据集训练,在IIIT, SVT, IC03, IC13, IC15, SVTP, CUTE数据集上进行评估,算法复现效果如下:
|
||||
|
||||
|模型|骨干网络|配置文件|Acc|下载链接|
|
||||
| --- | --- | --- | --- | --- |
|
||||
|SAR|ResNet31|[rec_r31_sar.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/rec/rec_r31_sar.yml)|87.20%|[训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.1/rec/rec_r31_sar_train.tar)|
|
||||
|
||||
注:除了使用MJSynth和SynthText两个文字识别数据集外,还加入了[SynthAdd](https://pan.baidu.com/share/init?surl=uV0LtoNmcxbO-0YA7Ch4dg)数据(提取码:627x),和部分真实数据,具体数据细节可以参考论文。
|
||||
|
||||
## 2. 环境配置
|
||||
|
||||
请先参考[《运行环境准备》](../../ppocr/environment.md)配置PaddleOCR运行环境,参考[《项目克隆》](../../ppocr/blog/clone.md)克隆项目代码。
|
||||
|
||||
## 3. 模型训练、评估、预测
|
||||
|
||||
请参考[文本识别教程](../../ppocr/model_train/recognition.md)。PaddleOCR对代码进行了模块化,训练不同的识别模型只需要**更换配置文件**即可。
|
||||
|
||||
### 训练
|
||||
|
||||
具体地,在完成数据准备后,便可以启动训练,训练命令如下:
|
||||
|
||||
```bash linenums="1"
|
||||
#单卡训练(训练周期长,不建议)
|
||||
python3 tools/train.py -c configs/rec/rec_r31_sar.yml
|
||||
|
||||
# 多卡训练,通过--gpus参数指定卡号
|
||||
python3 -m paddle.distributed.launch --gpus '0,1,2,3' tools/train.py -c configs/rec/rec_r31_sar.yml
|
||||
```
|
||||
|
||||
### 评估
|
||||
|
||||
```bash linenums="1"
|
||||
# GPU 评估, Global.pretrained_model 为待测权重
|
||||
python3 -m paddle.distributed.launch --gpus '0' tools/eval.py -c configs/rec/rec_r31_sar.yml -o Global.pretrained_model={path/to/weights}/best_accuracy
|
||||
```
|
||||
|
||||
### 预测
|
||||
|
||||
```bash linenums="1"
|
||||
# 预测使用的配置文件必须与训练一致
|
||||
python3 tools/infer_rec.py -c configs/rec/rec_r31_sar.yml -o Global.pretrained_model={path/to/weights}/best_accuracy Global.infer_img=doc/imgs_words/en/word_1.png
|
||||
```
|
||||
|
||||
## 4. 推理部署
|
||||
|
||||
### 4.1 Python推理
|
||||
|
||||
首先将SAR文本识别训练过程中保存的模型,转换成inference model。( [模型下载地址](https://paddleocr.bj.bcebos.com/dygraph_v2.1/rec/rec_r31_sar_train.tar) ),可以使用如下命令进行转换:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/export_model.py -c configs/rec/rec_r31_sar.yml -o Global.pretrained_model=./rec_r31_sar_train/best_accuracy Global.save_inference_dir=./inference/rec_sar
|
||||
```
|
||||
|
||||
SAR文本识别模型推理,可以执行如下命令:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_rec.py --image_dir="./doc/imgs_words/en/word_1.png" --rec_model_dir="./inference/rec_sar/" --rec_image_shape="3, 48, 48, 160" --rec_algorithm="SAR" --rec_char_dict_path="ppocr/utils/dict90.txt" --max_text_length=30 --use_space_char=False
|
||||
```
|
||||
|
||||
### 4.2 C++推理
|
||||
|
||||
由于C++预处理后处理还未支持SAR,所以暂未支持
|
||||
|
||||
### 4.3 Serving服务化部署
|
||||
|
||||
暂不支持
|
||||
|
||||
### 4.4 更多推理部署
|
||||
|
||||
暂不支持
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
## 引用
|
||||
|
||||
```bibtex
|
||||
@article{Li2019ShowAA,
|
||||
title={Show, Attend and Read: A Simple and Strong Baseline for Irregular Text Recognition},
|
||||
author={Hui Li and Peng Wang and Chunhua Shen and Guyu Zhang},
|
||||
journal={ArXiv},
|
||||
year={2019},
|
||||
volume={abs/1811.00751}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,93 @@
|
||||
---
|
||||
comments: true
|
||||
---
|
||||
|
||||
# SATRN
|
||||
|
||||
## 1. Introduction
|
||||
|
||||
论文信息:
|
||||
> [On Recognizing Texts of Arbitrary Shapes with 2D Self-Attention](https://arxiv.org/abs/1910.04396)
|
||||
> Junyeop Lee, Sungrae Park, Jeonghun Baek, Seong Joon Oh, Seonghyeon Kim, Hwalsuk Lee
|
||||
> CVPR, 2020
|
||||
Using MJSynth and SynthText two text recognition datasets for training, and evaluating on IIIT, SVT, IC03, IC13, IC15, SVTP, CUTE datasets, the algorithm reproduction effect is as follows:
|
||||
|
||||
|Model|Backbone|config|Acc|Download link|
|
||||
| --- | --- | --- | --- | --- |
|
||||
|SATRN|ShallowCNN|88.05%|[configs/rec/rec_satrn.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/rec/rec_satrn.yml)|[训练模型](https://pan.baidu.com/s/10J-Bsd881bimKaclKszlaQ?pwd=lk8a)|
|
||||
|
||||
## 2. Environment
|
||||
|
||||
Please refer to ["Environment Preparation"](../../ppocr/environment.en.md) to configure the PaddleOCR environment, and refer to ["Project Clone"](../../ppocr/blog/clone.en.md)to clone the project code.
|
||||
|
||||
## 3. Model Training / Evaluation / Prediction
|
||||
|
||||
Please refer to [Text Recognition Tutorial](../../ppocr/model_train/recognition.en.md). PaddleOCR modularizes the code, and training different recognition models only requires **changing the configuration file**.
|
||||
|
||||
### Training
|
||||
|
||||
Specifically, after the data preparation is completed, the training can be started. The training command is as follows:
|
||||
|
||||
```bash linenums="1"
|
||||
# Single GPU training (long training period, not recommended)
|
||||
python3 tools/train.py -c configs/rec/rec_satrn.yml
|
||||
# Multi GPU training, specify the gpu number through the --gpus parameter
|
||||
python3 -m paddle.distributed.launch --gpus '0,1,2,3' tools/train.py -c configs/rec/rec_satrn.yml
|
||||
```
|
||||
|
||||
### Evaluation
|
||||
|
||||
```bash linenums="1"
|
||||
# GPU evaluation
|
||||
python3 -m paddle.distributed.launch --gpus '0' tools/eval.py -c configs/rec/rec_satrn.yml -o Global.pretrained_model={path/to/weights}/best_accuracy
|
||||
```
|
||||
|
||||
### Prediction
|
||||
|
||||
```bash linenums="1"
|
||||
# The configuration file used for prediction must match the training
|
||||
python3 tools/infer_rec.py -c configs/rec/rec_satrn.yml -o Global.pretrained_model={path/to/weights}/best_accuracy Global.infer_img=doc/imgs_words/en/word_1.png
|
||||
```
|
||||
|
||||
## 4. Inference and Deployment
|
||||
|
||||
### 4.1 Python Inference
|
||||
|
||||
First, the model saved during the SATRN text recognition training process is converted into an inference model. ( [Model download link](https://pan.baidu.com/s/10J-Bsd881bimKaclKszlaQ?pwd=lk8a) ), you can use the following command to convert:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/export_model.py -c configs/rec/rec_satrn.yml -o Global.pretrained_model=./rec_satrn_train/best_accuracy Global.save_inference_dir=./inference/rec_satrn
|
||||
```
|
||||
|
||||
For SATRN text recognition model inference, the following commands can be executed:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_rec.py --image_dir="./doc/imgs_words/en/word_1.png" --rec_model_dir="./inference/rec_satrn/" --rec_image_shape="3, 48, 48, 160" --rec_algorithm="SATRN" --rec_char_dict_path="ppocr/utils/dict90.txt" --max_text_length=30 --use_space_char=False
|
||||
```
|
||||
|
||||
### 4.2 C++ Inference
|
||||
|
||||
Not supported
|
||||
|
||||
### 4.3 Serving
|
||||
|
||||
Not supported
|
||||
|
||||
### 4.4 More
|
||||
|
||||
Not supported
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
## Citation
|
||||
|
||||
```bibtex
|
||||
@article{lee2019recognizing,
|
||||
title={On Recognizing Texts of Arbitrary Shapes with 2D Self-Attention},
|
||||
author={Junyeop Lee and Sungrae Park and Jeonghun Baek and Seong Joon Oh and Seonghyeon Kim and Hwalsuk Lee},
|
||||
year={2019},
|
||||
eprint={1910.04396},
|
||||
archivePrefix={arXiv},
|
||||
primaryClass={cs.CV}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,93 @@
|
||||
---
|
||||
comments: true
|
||||
---
|
||||
|
||||
# SATRN
|
||||
|
||||
## 1. 算法简介
|
||||
|
||||
论文信息:
|
||||
> [On Recognizing Texts of Arbitrary Shapes with 2D Self-Attention](https://arxiv.org/abs/1910.04396)
|
||||
> Junyeop Lee, Sungrae Park, Jeonghun Baek, Seong Joon Oh, Seonghyeon Kim, Hwalsuk Lee
|
||||
> CVPR, 2020
|
||||
参考[DTRB](https://arxiv.org/abs/1904.01906) 文字识别训练和评估流程,使用MJSynth和SynthText两个文字识别数据集训练,在IIIT, SVT, IC03, IC13, IC15, SVTP, CUTE数据集上进行评估,算法效果如下:
|
||||
|
||||
|模型|骨干网络|Avg Accuracy|配置文件|下载链接|
|
||||
|---|---|---|---|---|
|
||||
|SATRN|ShallowCNN|88.05%|[configs/rec/rec_satrn.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/rec/rec_satrn.yml)|[训练模型](https://pan.baidu.com/s/10J-Bsd881bimKaclKszlaQ?pwd=lk8a)|
|
||||
|
||||
## 2. 环境配置
|
||||
|
||||
请先参考[《运行环境准备》](../../ppocr/environment.md)配置PaddleOCR运行环境,参考[《项目克隆》](../../ppocr/blog/clone.md)克隆项目代码。
|
||||
|
||||
## 3. 模型训练、评估、预测
|
||||
|
||||
请参考[文本识别训练教程](../../ppocr/model_train/recognition.md)。PaddleOCR对代码进行了模块化,训练不同的识别模型只需要**更换配置文件**即可。
|
||||
|
||||
### 训练
|
||||
|
||||
在完成数据准备后,便可以启动训练,训练命令如下:
|
||||
|
||||
```bash linenums="1"
|
||||
# 单卡训练(训练周期长,不建议)
|
||||
python3 tools/train.py -c configs/rec/rec_satrn.yml
|
||||
# 多卡训练,通过--gpus参数指定卡号
|
||||
python3 -m paddle.distributed.launch --gpus '0,1,2,3' tools/train.py -c rec_satrn.yml
|
||||
```
|
||||
|
||||
### 评估
|
||||
|
||||
```bash linenums="1"
|
||||
# GPU 评估, Global.pretrained_model 为待测权重
|
||||
python3 -m paddle.distributed.launch --gpus '0' tools/eval.py -c configs/rec/rec_satrn.yml -o Global.pretrained_model={path/to/weights}/best_accuracy
|
||||
```
|
||||
|
||||
### 预测
|
||||
|
||||
```bash linenums="1"
|
||||
# 预测使用的配置文件必须与训练一致
|
||||
python3 tools/infer_rec.py -c configs/rec/rec_satrn.yml -o Global.pretrained_model={path/to/weights}/best_accuracy Global.infer_img=doc/imgs_words/en/word_1.png
|
||||
```
|
||||
|
||||
## 4. 推理部署
|
||||
|
||||
### 4.1 Python推理
|
||||
|
||||
首先将SATRN文本识别训练过程中保存的模型,转换成inference model。( [模型下载地址](https://pan.baidu.com/s/10J-Bsd881bimKaclKszlaQ?pwd=lk8a) ),可以使用如下命令进行转换:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/export_model.py -c configs/rec/rec_satrn.yml -o Global.pretrained_model=./rec_satrn/best_accuracy Global.save_inference_dir=./inference/rec_satrn
|
||||
```
|
||||
|
||||
SATRN文本识别模型推理,可以执行如下命令:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_rec.py --image_dir="./doc/imgs_words/en/word_1.png" --rec_model_dir="./inference/rec_satrn/" --rec_image_shape="3, 48, 48, 160" --rec_algorithm="SATRN" --rec_char_dict_path="ppocr/utils/dict90.txt" --max_text_length=30 --use_space_char=False
|
||||
```
|
||||
|
||||
### 4.2 C++推理
|
||||
|
||||
由于C++预处理后处理还未支持SATRN,所以暂未支持
|
||||
|
||||
### 4.3 Serving服务化部署
|
||||
|
||||
暂不支持
|
||||
|
||||
### 4.4 更多推理部署
|
||||
|
||||
暂不支持
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
## 引用
|
||||
|
||||
```bibtex
|
||||
@article{lee2019recognizing,
|
||||
title={On Recognizing Texts of Arbitrary Shapes with 2D Self-Attention},
|
||||
author={Junyeop Lee and Sungrae Park and Jeonghun Baek and Seong Joon Oh and Seonghyeon Kim and Hwalsuk Lee},
|
||||
year={2019},
|
||||
eprint={1910.04396},
|
||||
archivePrefix={arXiv},
|
||||
primaryClass={cs.CV}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,92 @@
|
||||
---
|
||||
comments: true
|
||||
---
|
||||
|
||||
# SEED
|
||||
|
||||
## 1. Introduction
|
||||
|
||||
Paper:
|
||||
> [SEED: Semantics Enhanced Encoder-Decoder Framework for Scene Text Recognition](https://arxiv.org/pdf/2005.10977.pdf)
|
||||
|
||||
> Qiao, Zhi and Zhou, Yu and Yang, Dongbao and Zhou, Yucan and Wang, Weiping
|
||||
|
||||
> CVPR, 2020
|
||||
|
||||
Using MJSynth and SynthText two text recognition datasets for training, and evaluating on IIIT, SVT, IC03, IC13, IC15, SVTP, CUTE datasets, the algorithm reproduction effect is as follows:
|
||||
|
||||
|Model|Backbone|ACC|config|Download link|
|
||||
| --- | --- | --- | --- | --- |
|
||||
|SEED|Aster_Resnet| 85.20% | [configs/rec/rec_resnet_stn_bilstm_att.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/rec/rec_resnet_stn_bilstm_att.yml) | [训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.1/rec/rec_resnet_stn_bilstm_att.tar) |
|
||||
|
||||
## 2. Environment
|
||||
|
||||
Please refer to ["Environment Preparation"](../../ppocr/environment.en.md) to configure the PaddleOCR environment, and refer to ["Project Clone"](../../ppocr/blog/clone.en.md)to clone the project code.
|
||||
|
||||
## 3. Model Training / Evaluation / Prediction
|
||||
|
||||
Please refer to [Text Recognition Tutorial](../../ppocr/model_train/recognition.en.md). PaddleOCR modularizes the code, and training different recognition models only requires **changing the configuration file**.
|
||||
|
||||
### Training
|
||||
|
||||
The SEED model needs to additionally load the [language model](https://dl.fbaipublicfiles.com/fasttext/vectors-crawl/cc.en.300.bin.gz) trained by FastText, and install the fasttext dependencies:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 -m pip install fasttext==0.9.1
|
||||
```
|
||||
|
||||
Specifically, after the data preparation is completed, the training can be started. The training command is as follows:
|
||||
|
||||
```bash linenums="1"
|
||||
# Single GPU training (long training period, not recommended)
|
||||
python3 tools/train.py -c configs/rec/rec_resnet_stn_bilstm_att.yml
|
||||
|
||||
# Multi GPU training, specify the gpu number through the --gpus parameter
|
||||
python3 -m paddle.distributed.launch --gpus '0,1,2,3' tools/train.py -c rec_resnet_stn_bilstm_att.yml
|
||||
```
|
||||
|
||||
### Evaluation
|
||||
|
||||
```bash linenums="1"
|
||||
# GPU evaluation
|
||||
python3 -m paddle.distributed.launch --gpus '0' tools/eval.py -c configs/rec/rec_resnet_stn_bilstm_att.yml -o Global.pretrained_model={path/to/weights}/best_accuracy
|
||||
```
|
||||
|
||||
### Prediction
|
||||
|
||||
```bash linenums="1"
|
||||
# The configuration file used for prediction must match the training
|
||||
python3 tools/infer_rec.py -c configs/rec/rec_resnet_stn_bilstm_att.yml -o Global.pretrained_model={path/to/weights}/best_accuracy Global.infer_img=doc/imgs_words/en/word_1.png
|
||||
```
|
||||
|
||||
## 4. Inference and Deployment
|
||||
|
||||
### 4.1 Python Inference
|
||||
|
||||
Not support
|
||||
|
||||
### 4.2 C++ Inference
|
||||
|
||||
Not support
|
||||
|
||||
### 4.3 Serving
|
||||
|
||||
Not support
|
||||
|
||||
### 4.4 More
|
||||
|
||||
Not support
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
## Citation
|
||||
|
||||
```bibtex
|
||||
@inproceedings{qiao2020seed,
|
||||
title={Seed: Semantics enhanced encoder-decoder framework for scene text recognition},
|
||||
author={Qiao, Zhi and Zhou, Yu and Yang, Dongbao and Zhou, Yucan and Wang, Weiping},
|
||||
booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},
|
||||
pages={13528--13537},
|
||||
year={2020}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,91 @@
|
||||
---
|
||||
comments: true
|
||||
---
|
||||
|
||||
# SEED
|
||||
|
||||
## 1. 算法简介
|
||||
|
||||
论文信息:
|
||||
> [SEED: Semantics Enhanced Encoder-Decoder Framework for Scene Text Recognition](https://arxiv.org/pdf/2005.10977.pdf)
|
||||
> Qiao, Zhi and Zhou, Yu and Yang, Dongbao and Zhou, Yucan and Wang, Weiping
|
||||
> CVPR, 2020
|
||||
|
||||
参考[DTRB](https://arxiv.org/abs/1904.01906) 文字识别训练和评估流程,使用MJSynth和SynthText两个文字识别数据集训练,在IIIT, SVT, IC03, IC13, IC15, SVTP, CUTE数据集上进行评估,算法效果如下:
|
||||
|
||||
|模型|骨干网络|Avg Accuracy|配置文件|下载链接|
|
||||
|---|---|---|---|---|
|
||||
|SEED|Aster_Resnet| 85.20% | [configs/rec/rec_resnet_stn_bilstm_att.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/rec/rec_resnet_stn_bilstm_att.yml) | [训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.1/rec/rec_resnet_stn_bilstm_att.tar) |
|
||||
|
||||
## 2. 环境配置
|
||||
|
||||
请先参考[《运行环境准备》](../../ppocr/environment.md)配置PaddleOCR运行环境,参考[《项目克隆》](../../ppocr/blog/clone.md)克隆项目代码。
|
||||
|
||||
## 3. 模型训练、评估、预测
|
||||
|
||||
请参考[文本识别训练教程](../../ppocr/model_train/recognition.md)。PaddleOCR对代码进行了模块化,训练不同的识别模型只需要**更换配置文件**即可。
|
||||
|
||||
### 训练
|
||||
|
||||
SEED模型需要额外加载FastText训练好的[语言模型](https://dl.fbaipublicfiles.com/fasttext/vectors-crawl/cc.en.300.bin.gz) ,并且安装 fasttext 依赖:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 -m pip install fasttext==0.9.1
|
||||
```
|
||||
|
||||
然后,在完成数据准备后,便可以启动训练,训练命令如下:
|
||||
|
||||
```bash linenums="1"
|
||||
# 单卡训练(训练周期长,不建议)
|
||||
python3 tools/train.py -c configs/rec/rec_resnet_stn_bilstm_att.yml
|
||||
|
||||
# 多卡训练,通过--gpus参数指定卡号
|
||||
python3 -m paddle.distributed.launch --gpus '0,1,2,3' tools/train.py -c rec_resnet_stn_bilstm_att.yml
|
||||
|
||||
```
|
||||
|
||||
### 评估
|
||||
|
||||
```bash linenums="1"
|
||||
# GPU 评估, Global.pretrained_model 为待测权重
|
||||
python3 -m paddle.distributed.launch --gpus '0' tools/eval.py -c configs/rec/rec_resnet_stn_bilstm_att.yml -o Global.pretrained_model={path/to/weights}/best_accuracy
|
||||
```
|
||||
|
||||
### 预测
|
||||
|
||||
```bash linenums="1"
|
||||
# 预测使用的配置文件必须与训练一致
|
||||
python3 tools/infer_rec.py -c configs/rec/rec_resnet_stn_bilstm_att.yml -o Global.pretrained_model={path/to/weights}/best_accuracy Global.infer_img=doc/imgs_words/en/word_1.png
|
||||
```
|
||||
|
||||
## 4. 推理部署
|
||||
|
||||
### 4.1 Python推理
|
||||
|
||||
coming soon
|
||||
|
||||
### 4.2 C++推理
|
||||
|
||||
coming soon
|
||||
|
||||
### 4.3 Serving服务化部署
|
||||
|
||||
coming soon
|
||||
|
||||
### 4.4 更多推理部署
|
||||
|
||||
coming soon
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
## 引用
|
||||
|
||||
```bibtex
|
||||
@inproceedings{qiao2020seed,
|
||||
title={Seed: Semantics enhanced encoder-decoder framework for scene text recognition},
|
||||
author={Qiao, Zhi and Zhou, Yu and Yang, Dongbao and Zhou, Yucan and Wang, Weiping},
|
||||
booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},
|
||||
pages={13528--13537},
|
||||
year={2020}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,93 @@
|
||||
---
|
||||
comments: true
|
||||
---
|
||||
|
||||
# SPIN: Structure-Preserving Inner Offset Network for Scene Text Recognition
|
||||
|
||||
## 1. Introduction
|
||||
|
||||
Paper:
|
||||
> [SPIN: Structure-Preserving Inner Offset Network for Scene Text Recognition](https://arxiv.org/abs/2005.13117)
|
||||
> Chengwei Zhang, Yunlu Xu, Zhanzhan Cheng, Shiliang Pu, Yi Niu, Fei Wu, Futai Zou
|
||||
> AAAI, 2020
|
||||
|
||||
Using MJSynth and SynthText two text recognition datasets for training, and evaluating on IIIT, SVT, IC03, IC13, IC15, SVTP, CUTE datasets. The algorithm reproduction effect is as follows:
|
||||
|
||||
|Model|Backbone|config|Acc|Download link|
|
||||
| --- | --- | --- | --- | --- |
|
||||
|SPIN|ResNet32|[rec_r32_gaspin_bilstm_att.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/rec/rec_r32_gaspin_bilstm_att.yml)|90.00%|[trained model](https://paddleocr.bj.bcebos.com/contribution/rec_r32_gaspin_bilstm_att.tar) |
|
||||
|
||||
## 2. Environment
|
||||
|
||||
Please refer to ["Environment Preparation"](../../ppocr/environment.en.md) to configure the PaddleOCR environment, and refer to ["Project Clone"](../../ppocr/blog/clone.en.md)to clone the project code.
|
||||
|
||||
## 3. Model Training / Evaluation / Prediction
|
||||
|
||||
Please refer to [Text Recognition Tutorial](../../ppocr/model_train/recognition.en.md). PaddleOCR modularizes the code, and training different recognition models only requires **changing the configuration file**.
|
||||
|
||||
### Training
|
||||
|
||||
Specifically, after the data preparation is completed, the training can be started. The training command is as follows:
|
||||
|
||||
```bash linenums="1"
|
||||
# Single GPU training (long training period, not recommended)
|
||||
python3 tools/train.py -c configs/rec/rec_r32_gaspin_bilstm_att.yml
|
||||
|
||||
# Multi GPU training, specify the gpu number through the --gpus parameter
|
||||
python3 -m paddle.distributed.launch --gpus '0,1,2,3' tools/train.py -c configs/rec/rec_r32_gaspin_bilstm_att.yml
|
||||
```
|
||||
|
||||
### Evaluation
|
||||
|
||||
```bash linenums="1"
|
||||
# GPU evaluation
|
||||
python3 -m paddle.distributed.launch --gpus '0' tools/eval.py -c configs/rec/rec_r32_gaspin_bilstm_att.yml -o Global.pretrained_model={path/to/weights}/best_accuracy
|
||||
```
|
||||
|
||||
### Prediction
|
||||
|
||||
```bash linenums="1"
|
||||
# The configuration file used for prediction must match the training
|
||||
python3 tools/infer_rec.py -c configs/rec/rec_r32_gaspin_bilstm_att.yml -o Global.pretrained_model={path/to/weights}/best_accuracy Global.infer_img=doc/imgs_words/en/word_1.png
|
||||
```
|
||||
|
||||
## 4. Inference and Deployment
|
||||
|
||||
### 4.1 Python Inference
|
||||
|
||||
First, the model saved during the SPIN text recognition training process is converted into an inference model. you can use the following command to convert:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/export_model.py -c configs/rec/rec_r32_gaspin_bilstm_att.yml -o Global.pretrained_model={path/to/weights}/best_accuracy Global.save_inference_dir=./inference/rec_r32_gaspin_bilstm_att
|
||||
```
|
||||
|
||||
For SPIN text recognition model inference, the following commands can be executed:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_rec.py --image_dir="./doc/imgs_words/en/word_1.png" --rec_model_dir="./inference/rec_r32_gaspin_bilstm_att/" --rec_image_shape="3, 32, 100" --rec_algorithm="SPIN" --rec_char_dict_path="/ppocr/utils/dict/spin_dict.txt" --use_space_char=False
|
||||
```
|
||||
|
||||
### 4.2 C++ Inference
|
||||
|
||||
Not supported
|
||||
|
||||
### 4.3 Serving
|
||||
|
||||
Not supported
|
||||
|
||||
### 4.4 More
|
||||
|
||||
Not supported
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
## Citation
|
||||
|
||||
```bibtex
|
||||
@article{2020SPIN,
|
||||
title={SPIN: Structure-Preserving Inner Offset Network for Scene Text Recognition},
|
||||
author={Chengwei Zhang and Yunlu Xu and Zhanzhan Cheng and Shiliang Pu and Yi Niu and Fei Wu and Futai Zou},
|
||||
journal={AAAI2020},
|
||||
year={2020},
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,94 @@
|
||||
---
|
||||
comments: true
|
||||
---
|
||||
|
||||
# SPIN: Structure-Preserving Inner Offset Network for Scene Text Recognition
|
||||
|
||||
## 1. 算法简介
|
||||
|
||||
论文信息:
|
||||
> [SPIN: Structure-Preserving Inner Offset Network for Scene Text Recognition](https://arxiv.org/abs/2005.13117)
|
||||
> Chengwei Zhang, Yunlu Xu, Zhanzhan Cheng, Shiliang Pu, Yi Niu, Fei Wu, Futai Zou
|
||||
> AAAI, 2020
|
||||
|
||||
SPIN收录于AAAI2020。主要用于OCR识别任务。在任意形状文本识别中,矫正网络是一种较为常见的前置处理模块,但诸如RARE\ASTER\ESIR等只考虑了空间变换,并没有考虑色度变换。本文提出了一种结构Structure-Preserving Inner Offset Network (SPIN),可以在色彩空间上进行变换。该模块是可微分的,可以加入到任意识别器中。
|
||||
使用MJSynth和SynthText两个合成文字识别数据集训练,在IIIT, SVT, IC03, IC13, IC15, SVTP, CUTE数据集上进行评估,算法复现效果如下:
|
||||
|
||||
|模型|骨干网络|配置文件|Acc|下载链接|
|
||||
| --- | --- | --- | --- | --- |
|
||||
|SPIN|ResNet32|[rec_r32_gaspin_bilstm_att.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/rec/rec_r32_gaspin_bilstm_att.yml)|90.00%|[训练模型](https://paddleocr.bj.bcebos.com/contribution/rec_r32_gaspin_bilstm_att.tar)|
|
||||
|
||||
## 2. 环境配置
|
||||
|
||||
请先参考[《运行环境准备》](../../ppocr/environment.md)配置PaddleOCR运行环境,参考[《项目克隆》](../../ppocr/blog/clone.md)克隆项目代码。
|
||||
|
||||
## 3. 模型训练、评估、预测
|
||||
|
||||
请参考[文本识别教程](../../ppocr/model_train/recognition.md)。PaddleOCR对代码进行了模块化,训练不同的识别模型只需要**更换配置文件**即可。
|
||||
|
||||
### 训练
|
||||
|
||||
具体地,在完成数据准备后,便可以启动训练,训练命令如下:
|
||||
|
||||
```bash linenums="1"
|
||||
#单卡训练(训练周期长,不建议)
|
||||
python3 tools/train.py -c configs/rec/rec_r32_gaspin_bilstm_att.yml
|
||||
|
||||
# 多卡训练,通过--gpus参数指定卡号
|
||||
python3 -m paddle.distributed.launch --gpus '0,1,2,3' tools/train.py -c configs/rec/rec_r32_gaspin_bilstm_att.yml
|
||||
```
|
||||
|
||||
### 评估
|
||||
|
||||
```bash linenums="1"
|
||||
# GPU 评估, Global.pretrained_model 为待测权重
|
||||
python3 -m paddle.distributed.launch --gpus '0' tools/eval.py -c configs/rec/rec_r32_gaspin_bilstm_att.yml -o Global.pretrained_model={path/to/weights}/best_accuracy
|
||||
```
|
||||
|
||||
### 预测
|
||||
|
||||
```bash linenums="1"
|
||||
# 预测使用的配置文件必须与训练一致
|
||||
python3 tools/infer_rec.py -c configs/rec/rec_r32_gaspin_bilstm_att.yml -o Global.pretrained_model={path/to/weights}/best_accuracy Global.infer_img=doc/imgs_words/en/word_1.png
|
||||
```
|
||||
|
||||
## 4. 推理部署
|
||||
|
||||
### 4.1 Python推理
|
||||
|
||||
首先将SPIN文本识别训练过程中保存的模型,转换成inference model。可以使用如下命令进行转换:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/export_model.py -c configs/rec/rec_r32_gaspin_bilstm_att.yml -o Global.pretrained_model={path/to/weights}/best_accuracy Global.save_inference_dir=./inference/rec_r32_gaspin_bilstm_att
|
||||
```
|
||||
|
||||
SPIN文本识别模型推理,可以执行如下命令:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_rec.py --image_dir="./doc/imgs_words/en/word_1.png" --rec_model_dir="./inference/rec_r32_gaspin_bilstm_att/" --rec_image_shape="3, 32, 100" --rec_algorithm="SPIN" --rec_char_dict_path="/ppocr/utils/dict/spin_dict.txt" --use_space_char=Falsee
|
||||
```
|
||||
|
||||
### 4.2 C++推理
|
||||
|
||||
由于C++预处理后处理还未支持SPIN,所以暂未支持
|
||||
|
||||
### 4.3 Serving服务化部署
|
||||
|
||||
暂不支持
|
||||
|
||||
### 4.4 更多推理部署
|
||||
|
||||
暂不支持
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
## 引用
|
||||
|
||||
```bibtex
|
||||
@article{2020SPIN,
|
||||
title={SPIN: Structure-Preserving Inner Offset Network for Scene Text Recognition},
|
||||
author={Chengwei Zhang and Yunlu Xu and Zhanzhan Cheng and Shiliang Pu and Yi Niu and Fei Wu and Futai Zou},
|
||||
journal={AAAI2020},
|
||||
year={2020},
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,94 @@
|
||||
---
|
||||
comments: true
|
||||
---
|
||||
|
||||
# SRN
|
||||
|
||||
## 1. Introduction
|
||||
|
||||
Paper:
|
||||
> [Towards Accurate Scene Text Recognition with Semantic Reasoning Networks](https://arxiv.org/abs/2003.12294#)
|
||||
> Deli Yu, Xuan Li, Chengquan Zhang, Junyu Han, Jingtuo Liu, Errui Ding
|
||||
> CVPR,2020
|
||||
|
||||
Using MJSynth and SynthText two text recognition datasets for training, and evaluating on IIIT, SVT, IC03, IC13, IC15, SVTP, CUTE datasets, the algorithm reproduction effect is as follows:
|
||||
|
||||
|Model|Backbone|config|Acc|Download link|
|
||||
| --- | --- | --- | --- | --- |
|
||||
|SRN|Resnet50_vd_fpn|[rec_r50_fpn_srn.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/rec/rec_r50_fpn_srn.yml)|86.31%|[train model](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_r50_vd_srn_train.tar)|
|
||||
|
||||
## 2. Environment
|
||||
|
||||
Please refer to ["Environment Preparation"](../../ppocr/environment.en.md) to configure the PaddleOCR environment, and refer to ["Project Clone"](../../ppocr/blog/clone.en.md)to clone the project code.
|
||||
|
||||
## 3. Model Training / Evaluation / Prediction
|
||||
|
||||
Please refer to [Text Recognition Tutorial](../../ppocr/model_train/recognition.en.md). PaddleOCR modularizes the code, and training different recognition models only requires **changing the configuration file**.
|
||||
|
||||
### Training
|
||||
|
||||
Specifically, after the data preparation is completed, the training can be started. The training command is as follows:
|
||||
|
||||
```bash linenums="1"
|
||||
# Single GPU training (long training period, not recommended)
|
||||
python3 tools/train.py -c configs/rec/rec_r50_fpn_srn.yml
|
||||
|
||||
# Multi GPU training, specify the gpu number through the --gpus parameter
|
||||
python3 -m paddle.distributed.launch --gpus '0,1,2,3' tools/train.py -c configs/rec/rec_r50_fpn_srn.yml
|
||||
```
|
||||
|
||||
### Evaluation
|
||||
|
||||
```bash linenums="1"
|
||||
# GPU evaluation
|
||||
python3 -m paddle.distributed.launch --gpus '0' tools/eval.py -c configs/rec/rec_r50_fpn_srn.yml -o Global.pretrained_model={path/to/weights}/best_accuracy
|
||||
```
|
||||
|
||||
### Prediction
|
||||
|
||||
```bash linenums="1"
|
||||
# The configuration file used for prediction must match the training
|
||||
python3 tools/infer_rec.py -c configs/rec/rec_r50_fpn_srn.yml -o Global.pretrained_model={path/to/weights}/best_accuracy Global.infer_img=doc/imgs_words/en/word_1.png
|
||||
```
|
||||
|
||||
## 4. Inference and Deployment
|
||||
|
||||
### 4.1 Python Inference
|
||||
|
||||
First, the model saved during the SRN text recognition training process is converted into an inference model. ( [Model download link](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_r50_vd_srn_train.tar) ), you can use the following command to convert:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/export_model.py -c configs/rec/rec_r50_fpn_srn.yml -o Global.pretrained_model=./rec_r50_vd_srn_train/best_accuracy Global.save_inference_dir=./inference/rec_srn
|
||||
```
|
||||
|
||||
For SRN text recognition model inference, the following commands can be executed:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_rec.py --image_dir="./doc/imgs_words/en/word_1.png" --rec_model_dir="./inference/rec_srn/" --rec_image_shape="1,64,256" --rec_char_type="ch" --rec_algorithm="SRN" --rec_char_dict_path="ppocr/utils/ic15_dict.txt" --use_space_char=False
|
||||
```
|
||||
|
||||
### 4.2 C++ Inference
|
||||
|
||||
Not supported
|
||||
|
||||
### 4.3 Serving
|
||||
|
||||
Not supported
|
||||
|
||||
### 4.4 More
|
||||
|
||||
Not supported
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
## Citation
|
||||
|
||||
```bibtex
|
||||
@article{Yu2020TowardsAS,
|
||||
title={Towards Accurate Scene Text Recognition With Semantic Reasoning Networks},
|
||||
author={Deli Yu and Xuan Li and Chengquan Zhang and Junyu Han and Jingtuo Liu and Errui Ding},
|
||||
journal={2020 IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
|
||||
year={2020},
|
||||
pages={12110-12119}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,94 @@
|
||||
---
|
||||
comments: true
|
||||
---
|
||||
|
||||
# SRN
|
||||
|
||||
## 1. 算法简介
|
||||
|
||||
论文信息:
|
||||
> [Towards Accurate Scene Text Recognition with Semantic Reasoning Networks](https://arxiv.org/abs/2003.12294#)
|
||||
> Deli Yu, Xuan Li, Chengquan Zhang, Junyu Han, Jingtuo Liu, Errui Ding
|
||||
> CVPR,2020
|
||||
|
||||
使用MJSynth和SynthText两个文字识别数据集训练,在IIIT, SVT, IC03, IC13, IC15, SVTP, CUTE数据集上进行评估,算法复现效果如下:
|
||||
|
||||
|模型|骨干网络|配置文件|Acc|下载链接|
|
||||
| --- | --- | --- | --- | --- |
|
||||
|SRN|Resnet50_vd_fpn|[rec_r50_fpn_srn.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/rec/rec_r50_fpn_srn.yml)|86.31%|[训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_r50_vd_srn_train.tar)|
|
||||
|
||||
## 2. 环境配置
|
||||
|
||||
请先参考[《运行环境准备》](../../ppocr/environment.md)配置PaddleOCR运行环境,参考[《项目克隆》](../../ppocr/blog/clone.md)克隆项目代码。
|
||||
|
||||
## 3. 模型训练、评估、预测
|
||||
|
||||
请参考[文本识别教程](../../ppocr/model_train/recognition.md)。PaddleOCR对代码进行了模块化,训练不同的识别模型只需要**更换配置文件**即可。
|
||||
|
||||
### 训练
|
||||
|
||||
具体地,在完成数据准备后,便可以启动训练,训练命令如下:
|
||||
|
||||
```bash linenums="1"
|
||||
#单卡训练(训练周期长,不建议)
|
||||
python3 tools/train.py -c configs/rec/rec_r50_fpn_srn.yml
|
||||
|
||||
# 多卡训练,通过--gpus参数指定卡号
|
||||
python3 -m paddle.distributed.launch --gpus '0,1,2,3' tools/train.py -c configs/rec/rec_r50_fpn_srn.yml
|
||||
```
|
||||
|
||||
### 评估
|
||||
|
||||
```bash linenums="1"
|
||||
# GPU 评估, Global.pretrained_model 为待测权重
|
||||
python3 -m paddle.distributed.launch --gpus '0' tools/eval.py -c configs/rec/rec_r50_fpn_srn.yml -o Global.pretrained_model={path/to/weights}/best_accuracy
|
||||
```
|
||||
|
||||
### 预测
|
||||
|
||||
```bash linenums="1"
|
||||
# 预测使用的配置文件必须与训练一致
|
||||
python3 tools/infer_rec.py -c configs/rec/rec_r50_fpn_srn.yml -o Global.pretrained_model={path/to/weights}/best_accuracy Global.infer_img=doc/imgs_words/en/word_1.png
|
||||
```
|
||||
|
||||
## 4. 推理部署
|
||||
|
||||
### 4.1 Python推理
|
||||
|
||||
首先将SRN文本识别训练过程中保存的模型,转换成inference model。( [模型下载地址](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_r50_vd_srn_train.tar) ),可以使用如下命令进行转换:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/export_model.py -c configs/rec/rec_r50_fpn_srn.yml -o Global.pretrained_model=./rec_r50_vd_srn_train/best_accuracy Global.save_inference_dir=./inference/rec_srn
|
||||
```
|
||||
|
||||
SRN文本识别模型推理,可以执行如下命令:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_rec.py --image_dir="./doc/imgs_words/en/word_1.png" --rec_model_dir="./inference/rec_srn/" --rec_image_shape="1,64,256" --rec_algorithm="SRN" --rec_char_dict_path=./ppocr/utils/ic15_dict.txt --use_space_char=False
|
||||
```
|
||||
|
||||
### 4.2 C++推理
|
||||
|
||||
由于C++预处理后处理还未支持SRN,所以暂未支持
|
||||
|
||||
### 4.3 Serving服务化部署
|
||||
|
||||
暂不支持
|
||||
|
||||
### 4.4 更多推理部署
|
||||
|
||||
暂不支持
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
## 引用
|
||||
|
||||
```bibtex
|
||||
@article{Yu2020TowardsAS,
|
||||
title={Towards Accurate Scene Text Recognition With Semantic Reasoning Networks},
|
||||
author={Deli Yu and Xuan Li and Chengquan Zhang and Junyu Han and Jingtuo Liu and Errui Ding},
|
||||
journal={2020 IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
|
||||
year={2020},
|
||||
pages={12110-12119}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,115 @@
|
||||
---
|
||||
comments: true
|
||||
---
|
||||
|
||||
# STAR-Net
|
||||
|
||||
## 1. Introduction
|
||||
|
||||
Paper information:
|
||||
> [STAR-Net: a spatial attention residue network for scene text recognition.](https://www.bmva-archive.org.uk/bmvc/2016/papers/paper043/paper043.pdf)
|
||||
> Wei Liu, Chaofeng Chen, Kwan-Yee K. Wong, Zhizhong Su and Junyu Han.
|
||||
> BMVC, pages 43.1-43.13, 2016
|
||||
|
||||
Refer to [DTRB](https://arxiv.org/abs/1904.01906) text Recognition Training and Evaluation Process . Using MJSynth and SynthText two text recognition datasets for training, and evaluating on IIIT, SVT, IC03, IC13, IC15, SVTP, CUTE datasets, the algorithm reproduction effect is as follows:
|
||||
|
||||
|Models|Backbone Networks|Avg Accuracy|Configuration Files|Download Links|
|
||||
| --- | --- | --- | --- | --- |
|
||||
|StarNet|Resnet34_vd|84.44%|[configs/rec/rec_r34_vd_tps_bilstm_ctc.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/rec/rec_r34_vd_tps_bilstm_ctc.yml)|[trained model](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_r34_vd_tps_bilstm_ctc_v2.0_train.tar)|
|
||||
|StarNet|MobileNetV3|81.42%|[configs/rec/rec_mv3_tps_bilstm_ctc.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/rec/rec_mv3_tps_bilstm_ctc.yml)|[trained model](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_mv3_tps_bilstm_ctc_v2.0_train.tar)|
|
||||
|
||||
## 2. Environment
|
||||
|
||||
Please refer to [Operating Environment Preparation](../../ppocr/environment.en.md) to configure the PaddleOCR operating environment, and refer to [Project Clone](../../ppocr/blog/clone.en.md)to clone the project code.
|
||||
|
||||
## 3. Model Training / Evaluation / Prediction
|
||||
|
||||
Please refer to [Text Recognition Training Tutorial](../../ppocr/model_train/recognition.en.md). PaddleOCR modularizes the code, and training different recognition models only requires **changing the configuration file**. Take the backbone network based on Resnet34_vd as an example:
|
||||
|
||||
### 3.1 Training
|
||||
|
||||
After the data preparation is complete, the training can be started. The training command is as follows:
|
||||
|
||||
````bash linenums="1"
|
||||
# Single card training (long training period, not recommended)
|
||||
python3 tools/train.py -c configs/rec/rec_r34_vd_tps_bilstm_ctc.yml # Multi-card training, specify the card number through the --gpus parameter
|
||||
python3 -m paddle.distributed.launch --gpus '0,1,2,3' tools/train.py -c rec_r34_vd_tps_bilstm_ctc.yml
|
||||
````
|
||||
|
||||
### 3.2 Evaluation
|
||||
|
||||
````bash linenums="1"
|
||||
# GPU evaluation, Global.pretrained_model is the model to be evaluated
|
||||
python3 -m paddle.distributed.launch --gpus '0' tools/eval.py -c configs/rec/rec_r34_vd_tps_bilstm_ctc.yml -o Global.pretrained_model={path/to/weights}/best_accuracy
|
||||
````
|
||||
|
||||
### 3.3 Prediction
|
||||
|
||||
````bash linenums="1"
|
||||
# The configuration file used for prediction must match the training
|
||||
python3 tools/infer_rec.py -c configs/rec/rec_r34_vd_tps_bilstm_ctc.yml -o Global.pretrained_model={path/to/weights}/best_accuracy Global.infer_img=doc/imgs_words/en/word_1.png
|
||||
````
|
||||
|
||||
## 4. Inference
|
||||
|
||||
### 4.1 Python Inference
|
||||
|
||||
First, convert the model saved during the STAR-Net text recognition training process into an inference model. Take the model trained on the MJSynth and SynthText text recognition datasets based on the Resnet34_vd backbone network as an example [Model download address]( https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_r34_vd_none_bilstm_ctc_v2.0_train.tar) , which can be converted using the following command:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/export_model.py -c configs/rec/rec_r34_vd_tps_bilstm_ctc.yml -o Global.pretrained_model=./rec_r34_vd_tps_bilstm_ctc_v2.0_train/best_accuracy Global.save_inference_dir=./inference/rec_starnet
|
||||
```
|
||||
|
||||
STAR-Net text recognition model inference, you can execute the following commands:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_rec.py --image_dir="./doc/imgs_words_en/word_336.png" --rec_model_dir="./inference/rec_starnet/" --rec_image_shape="3, 32, 100" --rec_char_dict_path="./ppocr/utils/ic15_dict.txt"
|
||||
```
|
||||
|
||||

|
||||
|
||||
The inference results are as follows:
|
||||
|
||||
```bash linenums="1"
|
||||
Predicts of ./doc/imgs_words_en/word_336.png:('super', 0.9999073)
|
||||
```
|
||||
|
||||
**Attention** Since the above model refers to the [DTRB](https://arxiv.org/abs/1904.01906) text recognition training and evaluation process, it is different from the ultra-lightweight Chinese recognition model training in two aspects:
|
||||
|
||||
- The image resolutions used during training are different. The image resolutions used for training the above models are [3, 32, 100], while for Chinese model training, in order to ensure the recognition effect of long texts, the image resolutions used during training are [ 3, 32, 320]. The default shape parameter of the predictive inference program is the image resolution used for training Chinese, i.e. [3, 32, 320]. Therefore, when inferring the above English model here, it is necessary to set the shape of the recognized image through the parameter rec_image_shape.
|
||||
|
||||
- Character list, the experiment in the DTRB paper is only for 26 lowercase English letters and 10 numbers, a total of 36 characters. All uppercase and lowercase characters are converted to lowercase characters, and characters not listed above are ignored and considered spaces. Therefore, there is no input character dictionary here, but a dictionary is generated by the following command. Therefore, the parameter rec_char_dict_path needs to be set during inference, which is specified as an English dictionary "./ppocr/utils/ic15_dict.txt".
|
||||
|
||||
```python linenums="1"
|
||||
self.character_str = "0123456789abcdefghijklmnopqrstuvwxyz"
|
||||
dict_character = list(self.character_str)
|
||||
```
|
||||
|
||||
### 4.2 C++ Inference
|
||||
|
||||
After preparing the inference model, refer to the [cpp infer](../../../version2.x/legacy/cpp_infer.en.md) tutorial to operate.
|
||||
|
||||
### 4.3 Serving
|
||||
|
||||
After preparing the inference model, refer to the [pdserving](../../../version2.x/legacy/paddle_server.en.md) tutorial for Serving deployment, including two modes: Python Serving and C++ Serving.
|
||||
|
||||
### 4.4 More
|
||||
|
||||
The STAR-Net model also supports the following inference deployment methods:
|
||||
|
||||
- Paddle2ONNX Inference: After preparing the inference model, refer to the [paddle2onnx](../../../version2.x/legacy/paddle2onnx.en.md) tutorial.
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
## Citation
|
||||
|
||||
```bibtex
|
||||
@inproceedings{liu2016star,
|
||||
title={STAR-Net: a spatial attention residue network for scene text recognition.},
|
||||
author={Liu, Wei and Chen, Chaofeng and Wong, Kwan-Yee K and Su, Zhizhong and Han, Junyu},
|
||||
booktitle={BMVC},
|
||||
volume={2},
|
||||
pages={7},
|
||||
year={2016}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,118 @@
|
||||
---
|
||||
typora-copy-images-to: images
|
||||
comments: true
|
||||
---
|
||||
|
||||
# STAR-Net
|
||||
|
||||
## 1. 算法简介
|
||||
|
||||
论文信息:
|
||||
> [STAR-Net: a spatial attention residue network for scene text recognition.](https://www.bmva-archive.org.uk/bmvc/2016/papers/paper043/paper043.pdf)
|
||||
> Wei Liu, Chaofeng Chen, Kwan-Yee K. Wong, Zhizhong Su and Junyu Han.
|
||||
> BMVC, pages 43.1-43.13, 2016
|
||||
|
||||
参考[DTRB](https://arxiv.org/abs/1904.01906) 文字识别训练和评估流程,使用MJSynth和SynthText两个文字识别数据集训练,在IIIT, SVT, IC03, IC13, IC15, SVTP, CUTE数据集上进行评估,算法效果如下:
|
||||
|
||||
|模型|骨干网络|Avg Accuracy|配置文件|下载链接|
|
||||
|---|---|---|---|---|
|
||||
|StarNet|Resnet34_vd|84.44%|[configs/rec/rec_r34_vd_tps_bilstm_ctc.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/rec/rec_r34_vd_tps_bilstm_ctc.yml)|[训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_r34_vd_tps_bilstm_ctc_v2.0_train.tar)|
|
||||
|StarNet|MobileNetV3|81.42%|[configs/rec/rec_mv3_tps_bilstm_ctc.yml](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/rec/rec_mv3_tps_bilstm_ctc.yml)|[训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_mv3_tps_bilstm_ctc_v2.0_train.tar)|
|
||||
|
||||
## 2. 环境配置
|
||||
|
||||
请先参考[《运行环境准备》](../../ppocr/environment.md)配置PaddleOCR运行环境,参考[《项目克隆》](../../ppocr/blog/clone.md)克隆项目代码。
|
||||
|
||||
## 3. 模型训练、评估、预测
|
||||
|
||||
请参考[文本识别训练教程](../../ppocr/model_train/recognition.md)。PaddleOCR对代码进行了模块化,训练不同的识别模型只需要**更换配置文件**即可。
|
||||
|
||||
### 训练
|
||||
|
||||
在完成数据准备后,便可以启动训练,训练命令如下:
|
||||
|
||||
```bash linenums="1"
|
||||
# 单卡训练(训练周期长,不建议)
|
||||
python3 tools/train.py -c configs/rec/rec_r34_vd_tps_bilstm_ctc.yml
|
||||
|
||||
# 多卡训练,通过--gpus参数指定卡号
|
||||
python3 -m paddle.distributed.launch --gpus '0,1,2,3' tools/train.py -c rec_r34_vd_tps_bilstm_ctc.yml
|
||||
```
|
||||
|
||||
### 评估
|
||||
|
||||
```bash linenums="1"
|
||||
# GPU 评估, Global.pretrained_model 为待测权重
|
||||
python3 -m paddle.distributed.launch --gpus '0' tools/eval.py -c configs/rec/rec_r34_vd_tps_bilstm_ctc.yml -o Global.pretrained_model={path/to/weights}/best_accuracy
|
||||
```
|
||||
|
||||
### 预测
|
||||
|
||||
```bash linenums="1"
|
||||
# 预测使用的配置文件必须与训练一致
|
||||
python3 tools/infer_rec.py -c configs/rec/rec_r34_vd_tps_bilstm_ctc.yml -o Global.pretrained_model={path/to/weights}/best_accuracy Global.infer_img=doc/imgs_words/en/word_1.png
|
||||
```
|
||||
|
||||
## 4. 推理部署
|
||||
|
||||
### 4.1 Python推理
|
||||
|
||||
首先将 STAR-Net 文本识别训练过程中保存的模型,转换成inference model。以基于Resnet34_vd骨干网络,使用MJSynth和SynthText两个英文文本识别合成数据集训练的[模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_r34_vd_none_bilstm_ctc_v2.0_train.tar) 为例,可以使用如下命令进行转换:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/export_model.py -c configs/rec/rec_r34_vd_tps_bilstm_ctc.yml -o Global.pretrained_model=./rec_r34_vd_tps_bilstm_ctc_v2.0_train/best_accuracy Global.save_inference_dir=./inference/rec_starnet
|
||||
```
|
||||
|
||||
STAR-Net 文本识别模型推理,可以执行如下命令:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_rec.py --image_dir="./doc/imgs_words_en/word_336.png" --rec_model_dir="./inference/rec_starnet/" --rec_image_shape="3, 32, 100" --rec_char_dict_path="./ppocr/utils/ic15_dict.txt"
|
||||
```
|
||||
|
||||

|
||||
|
||||
执行命令后,上面图像的识别结果如下:
|
||||
|
||||
```bash linenums="1"
|
||||
Predicts of ./doc/imgs_words_en/word_336.png:('super', 0.9999073)
|
||||
```
|
||||
|
||||
**注意**:由于上述模型是参考[DTRB](https://arxiv.org/abs/1904.01906)文本识别训练和评估流程,与超轻量级中文识别模型训练有两方面不同:
|
||||
|
||||
- 训练时采用的图像分辨率不同,训练上述模型采用的图像分辨率是[3,32,100],而中文模型训练时,为了保证长文本的识别效果,训练时采用的图像分辨率是[3, 32, 320]。预测推理程序默认的形状参数是训练中文采用的图像分辨率,即[3, 32, 320]。因此,这里推理上述英文模型时,需要通过参数rec_image_shape设置识别图像的形状。
|
||||
|
||||
- 字符列表,DTRB论文中实验只是针对26个小写英文本母和10个数字进行实验,总共36个字符。所有大小字符都转成了小写字符,不在上面列表的字符都忽略,认为是空格。因此这里没有输入字符字典,而是通过如下命令生成字典.因此在推理时需要设置参数rec_char_dict_path,指定为英文字典"./ppocr/utils/ic15_dict.txt"。
|
||||
|
||||
```python linenums="1"
|
||||
self.character_str = "0123456789abcdefghijklmnopqrstuvwxyz"
|
||||
dict_character = list(self.character_str)
|
||||
```
|
||||
|
||||
### 4.2 C++推理
|
||||
|
||||
准备好推理模型后,参考[cpp infer](../../../version2.x/legacy/cpp_infer.md)教程进行操作即可。
|
||||
|
||||
### 4.3 Serving服务化部署
|
||||
|
||||
准备好推理模型后,参考[pdserving](../../../version2.x/legacy/paddle_server.md)教程进行Serving服务化部署,包括Python Serving和C++ Serving两种模式。
|
||||
|
||||
### 4.4 更多推理部署
|
||||
|
||||
STAR-Net模型还支持以下推理部署方式:
|
||||
|
||||
- Paddle2ONNX推理:准备好推理模型后,参考[paddle2onnx](../../../version2.x/legacy/paddle2onnx.md)教程操作。
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
## 引用
|
||||
|
||||
```bibtex
|
||||
@inproceedings{liu2016star,
|
||||
title={STAR-Net: a spatial attention residue network for scene text recognition.},
|
||||
author={Liu, Wei and Chen, Chaofeng and Wong, Kwan-Yee K and Su, Zhizhong and Han, Junyu},
|
||||
booktitle={BMVC},
|
||||
volume={2},
|
||||
pages={7},
|
||||
year={2016}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,144 @@
|
||||
---
|
||||
comments: true
|
||||
---
|
||||
|
||||
# SVTR
|
||||
|
||||
## 1. Introduction
|
||||
|
||||
Paper:
|
||||
> [SVTR: Scene Text Recognition with a Single Visual Model](https://arxiv.org/abs/2205.00159)
|
||||
> Yongkun Du and Zhineng Chen and Caiyan Jia Xiaoting Yin and Tianlun Zheng and Chenxia Li and Yuning Du and Yu-Gang Jiang
|
||||
> IJCAI, 2022
|
||||
|
||||
The accuracy (%) and model files of SVTR on the public dataset of scene text recognition are as follows:
|
||||
|
||||
* Chinese dataset from [Chinese Benchmark](https://arxiv.org/abs/2112.15093) , and the Chinese training evaluation strategy of SVTR follows the paper.
|
||||
|
||||
| Model |IC13<br/>857 | SVT |IIIT5k<br/>3000 |IC15<br/>1811| SVTP |CUTE80 | Avg_6 |IC15<br/>2077 |IC13<br/>1015 |IC03<br/>867|IC03<br/>860|Avg_10 | Chinese<br/>scene_test| Download link |
|
||||
|:----------:|:------:|:-----:|:---------:|:------:|:-----:|:-----:|:-----:|:-------:|:-------:|:-----:|:-----:|:---------------------------------------------:|:-----:|:------:|
|
||||
| SVTR Tiny | 96.85 | 91.34 | 94.53 | 83.99 | 85.43 | 89.24 | 90.87 | 80.55 | 95.37 | 95.27 | 95.70 | 90.13 | 67.90 | [English](https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/rec_svtr_tiny_none_ctc_en_train.tar) / [Chinese](https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/rec_svtr_tiny_none_ctc_ch_train.tar) |
|
||||
| SVTR Small | 95.92 | 93.04 | 95.03 | 84.70 | 87.91 | 92.01 | 91.63 | 82.72 | 94.88 | 96.08 | 96.28 | 91.02 | 69.00 | [English](https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/rec_svtr_small_none_ctc_en_train.tar) / [Chinese](https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/rec_svtr_small_none_ctc_ch_train.tar) |
|
||||
| SVTR Base | 97.08 | 91.50 | 96.03 | 85.20 | 89.92 | 91.67 | 92.33 | 83.73 | 95.66 | 95.62 | 95.81 | 91.61 | 71.40 | [English](https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/rec_svtr_base_none_ctc_en_train.tar) / - |
|
||||
| SVTR Large | 97.20 | 91.65 | 96.30 | 86.58 | 88.37 | 95.14 | 92.82 | 84.54 | 96.35 | 96.54 | 96.74 | 92.24 | 72.10 | [English](https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/rec_svtr_large_none_ctc_en_train.tar) / [Chinese](https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/rec_svtr_large_none_ctc_ch_train.tar) |
|
||||
|
||||
## 2. Environment
|
||||
|
||||
Please refer to ["Environment Preparation"](../../ppocr/environment.en.md) to configure the PaddleOCR environment, and refer to ["Project Clone"](../../ppocr/blog/clone.en.md)to clone the project code.
|
||||
|
||||
### Dataset Preparation
|
||||
|
||||
[English dataset download](https://github.com/clovaai/deep-text-recognition-benchmark#download-lmdb-dataset-for-traininig-and-evaluation-from-here)
|
||||
[Chinese dataset download](https://github.com/fudanvi/benchmarking-chinese-text-recognition#download)
|
||||
|
||||
## 3. Model Training / Evaluation / Prediction
|
||||
|
||||
Please refer to [Text Recognition Tutorial](../../ppocr/model_train/recognition.en.md). PaddleOCR modularizes the code, and training different recognition models only requires **changing the configuration file**.
|
||||
|
||||
### Training
|
||||
|
||||
Specifically, after the data preparation is completed, the training can be started. The training command is as follows:
|
||||
|
||||
```bash linenums="1"
|
||||
# Single GPU training (long training period, not recommended)
|
||||
python3 tools/train.py -c configs/rec/rec_svtrnet.yml
|
||||
|
||||
# Multi GPU training, specify the gpu number through the --gpus parameter
|
||||
python3 -m paddle.distributed.launch --gpus '0,1,2,3' tools/train.py -c configs/rec/rec_svtrnet.yml
|
||||
```
|
||||
|
||||
### Evaluation
|
||||
|
||||
You can download the model files and configuration files provided by `SVTR`: [download link](https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/rec_svtr_tiny_none_ctc_en_train.tar), take `SVTR-T` as an example, using the following command to evaluate:
|
||||
|
||||
```bash linenums="1"
|
||||
# Download the tar archive containing the model files and configuration files of SVTR-T and extract it
|
||||
wget https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/rec_svtr_tiny_none_ctc_en_train.tar && tar xf rec_svtr_tiny_none_ctc_en_train.tar
|
||||
# GPU evaluation
|
||||
python3 -m paddle.distributed.launch --gpus '0' tools/eval.py -c ./rec_svtr_tiny_none_ctc_en_train/rec_svtr_tiny_6local_6global_stn_en.yml -o Global.pretrained_model=./rec_svtr_tiny_none_ctc_en_train/best_accuracy
|
||||
```
|
||||
|
||||
### Prediction
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer_rec.py -c ./rec_svtr_tiny_none_ctc_en_train/rec_svtr_tiny_6local_6global_stn_en.yml -o Global.infer_img='./doc/imgs_words_en/word_10.png' Global.pretrained_model=./rec_svtr_tiny_none_ctc_en_train/best_accuracy
|
||||
```
|
||||
|
||||
## 4. Inference and Deployment
|
||||
|
||||
### 4.1 Python Inference
|
||||
|
||||
First, the model saved during the SVTR text recognition training process is converted into an inference model. ( [Model download link](https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/rec_svtr_tiny_none_ctc_en_train.tar) ), you can use the following command to convert:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/export_model.py -c configs/rec/rec_svtrnet.yml -o Global.pretrained_model=./rec_svtr_tiny_none_ctc_en_train/best_accuracy Global.save_inference_dir=./inference/rec_svtr_tiny_stn_en
|
||||
```
|
||||
|
||||
**Note:** If you are training the model on your own dataset and have modified the dictionary file, please pay attention to modify the `character_dict_path` in the configuration file to the modified dictionary file.
|
||||
|
||||
After the conversion is successful, there are three files in the directory:
|
||||
|
||||
```text linenums="1"
|
||||
/inference/rec_svtr_tiny_stn_en/
|
||||
├── inference.pdiparams
|
||||
├── inference.pdiparams.info
|
||||
└── inference.pdmodel
|
||||
```
|
||||
|
||||
For SVTR text recognition model inference, the following commands can be executed:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_rec.py --image_dir='./doc/imgs_words_en/word_10.png' --rec_model_dir='./inference/rec_svtr_tiny_stn_en/' --rec_algorithm='SVTR' --rec_image_shape='3,64,256' --rec_char_dict_path='./ppocr/utils/ic15_dict.txt'
|
||||
```
|
||||
|
||||

|
||||
|
||||
After executing the command, the prediction result (recognized text and score) of the image above is printed to the screen, an example is as follows:
|
||||
|
||||
```bash linenums="1"
|
||||
Predicts of ./doc/imgs_words_en/word_10.png:('pain', 0.9999998807907104)
|
||||
```
|
||||
|
||||
### 4.2 C++ Inference
|
||||
|
||||
Not supported
|
||||
|
||||
### 4.3 Serving
|
||||
|
||||
Not supported
|
||||
|
||||
### 4.4 More
|
||||
|
||||
Not supported
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
* 1. Speed situation on CPU and GPU
|
||||
* Since most of the operators used by `SVTR` are matrix multiplication, in the GPU environment, the speed has an advantage, but in the environment where mkldnn is enabled on the CPU, `SVTR` has no advantage over the optimized convolutional network.
|
||||
* 2. SVTR model convert to ONNX failed
|
||||
* Ensure `paddle2onnx` and `onnxruntime` versions are up to date, refer to [SVTR model to onnx step-by-step example](https://github.com/PaddlePaddle/PaddleOCR/issues/7821#issuecomment-) for the convert onnx command. 1271214273).
|
||||
* 3. SVTR model convert to ONNX is successful but the inference result is incorrect
|
||||
* The possible reason is that the model parameter `out_char_num` is not set correctly, it should be set to W//4, W//8 or W//12, please refer to [Section 3.3.3 of SVTR, a high-precision Chinese scene text recognition model](https://aistudio.baidu.com/aistudio/) projectdetail/5073182?contributionType=1).
|
||||
* 4. Optimization of long text recognition
|
||||
* Refer to [Section 3.3 of SVTR, a high-precision Chinese scene text recognition model](https://aistudio.baidu.com/aistudio/projectdetail/5073182?contributionType=1).
|
||||
* 5. Notes on the reproduction of the paper results
|
||||
* Dataset using provided by [ABINet](https://github.com/FangShancheng/ABINet).
|
||||
* By default, 4 cards of GPUs are used for training, the default Batchsize of a single card is 512, and the total Batchsize is 2048, corresponding to a learning rate of 0.0005. When modifying the Batchsize or changing the number of GPU cards, the learning rate should be modified in equal proportion.
|
||||
* 6. Exploration Directions for further optimization
|
||||
* Learning rate adjustment: adjusting to twice the default to keep Batchsize unchanged; or reducing Batchsize to 1/2 the default to keep the learning rate unchanged.
|
||||
* Data augmentation strategies: optionally `RecConAug` and `RecAug`.
|
||||
* If STN is not used, `Local` of `mixer` can be replaced by `Conv` and `local_mixer` can all be modified to `[5, 5]`.
|
||||
* Grid search for optimal `embed_dim`, `depth`, `num_heads` configurations.
|
||||
* Use the `Post-Normalization strategy`, which is to modify the model configuration `prenorm` to `True`.
|
||||
|
||||
## Citation
|
||||
|
||||
```bibtex
|
||||
@article{Du2022SVTR,
|
||||
title = {SVTR: Scene Text Recognition with a Single Visual Model},
|
||||
author = {Du, Yongkun and Chen, Zhineng and Jia, Caiyan and Yin, Xiaoting and Zheng, Tianlun and Li, Chenxia and Du, Yuning and Jiang, Yu-Gang},
|
||||
booktitle = {IJCAI},
|
||||
year = {2022},
|
||||
url = {https://arxiv.org/abs/2205.00159}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,170 @@
|
||||
---
|
||||
comments: true
|
||||
---
|
||||
|
||||
# 场景文本识别算法-SVTR
|
||||
|
||||
## 1. 算法简介
|
||||
|
||||
论文信息:
|
||||
> [SVTR: Scene Text Recognition with a Single Visual Model](https://arxiv.org/abs/2205.00159)
|
||||
> Yongkun Du and Zhineng Chen and Caiyan Jia and Xiaoting Yin and Tianlun Zheng and Chenxia Li and Yuning Du and Yu-Gang Jiang
|
||||
> IJCAI, 2022
|
||||
|
||||
场景文本识别旨在将自然图像中的文本转录为数字字符序列,从而传达对场景理解至关重要的高级语义。这项任务由于文本变形、字体、遮挡、杂乱背景等方面的变化具有一定的挑战性。先前的方法为提高识别精度做出了许多工作。然而文本识别器除了准确度外,还因为实际需求需要考虑推理速度等因素。
|
||||
|
||||
### SVTR算法简介
|
||||
|
||||
主流的场景文本识别模型通常包含两个模块:用于特征提取的视觉模型和用于文本转录的序列模型。这种架构虽然准确,但复杂且效率较低,限制了在实际场景中的应用。SVTR提出了一种用于场景文本识别的单视觉模型,该模型在patch-wise image tokenization框架内,完全摒弃了序列建模,在精度具有竞争力的前提下,模型参数量更少,速度更快,主要有以下几点贡献:
|
||||
|
||||
1. 首次发现单视觉模型可以达到与视觉语言模型相媲美甚至更高的准确率,并且其具有效率高和适应多语言的优点,在实际应用中很有前景。
|
||||
2. SVTR从字符组件的角度出发,逐渐的合并字符组件,自下而上地完成字符的识别。
|
||||
3. SVTR引入了局部和全局Mixing,分别用于提取字符组件特征和字符间依赖关系,与多尺度的特征一起,形成多粒度特征描述。
|
||||
|
||||
SVTR在场景文本识别公开数据集上的精度(%)和模型文件如下:
|
||||
|
||||
* 中文数据集来自于[Chinese Benchmark](https://arxiv.org/abs/2112.15093) ,SVTR的中文训练评估策略遵循该论文。
|
||||
|
||||
| 模型 |IC13<br/>857 | SVT |IIIT5k<br/>3000 |IC15<br/>1811| SVTP |CUTE80 | Avg_6 |IC15<br/>2077 |IC13<br/>1015 |IC03<br/>867|IC03<br/>860|Avg_10 | Chinese<br/>scene_test| 下载链接 |
|
||||
|:----------:|:------:|:-----:|:---------:|:------:|:-----:|:-----:|:-----:|:-------:|:-------:|:-----:|:-----:|:------:|:-----:|:-----:|
|
||||
| SVTR Tiny | 96.85 | 91.34 | 94.53 | 83.99 | 85.43 | 89.24 | 90.87 | 80.55 | 95.37 | 95.27 | 95.70 | 90.13 | 67.90 | [英文](https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/rec_svtr_tiny_none_ctc_en_train.tar) / [中文](https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/rec_svtr_tiny_none_ctc_ch_train.tar) |
|
||||
| SVTR Small | 95.92 | 93.04 | 95.03 | 84.70 | 87.91 | 92.01 | 91.63 | 82.72 | 94.88 | 96.08 | 96.28 | 91.02 | 69.00 | [英文](https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/rec_svtr_small_none_ctc_en_train.tar) / [中文](https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/rec_svtr_small_none_ctc_ch_train.tar) |
|
||||
| SVTR Base | 97.08 | 91.50 | 96.03 | 85.20 | 89.92 | 91.67 | 92.33 | 83.73 | 95.66 | 95.62 | 95.81 | 91.61 | 71.40 | [英文](https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/rec_svtr_base_none_ctc_en_train.tar) / - |
|
||||
| SVTR Large | 97.20 | 91.65 | 96.30 | 86.58 | 88.37 | 95.14 | 92.82 | 84.54 | 96.35 | 96.54 | 96.74 | 92.24 | 72.10 | [英文](https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/rec_svtr_large_none_ctc_en_train.tar) / [中文](https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/rec_svtr_large_none_ctc_ch_train.tar) |
|
||||
|
||||
## 2. 环境配置
|
||||
|
||||
请先参考[《运行环境准备》](../../ppocr/environment.md)配置PaddleOCR运行环境,参考[《项目克隆》](../../ppocr/blog/clone.md)克隆项目代码。
|
||||
|
||||
## 3. 模型训练、评估、预测
|
||||
|
||||
### 3.1 模型训练
|
||||
|
||||
#### 数据集准备
|
||||
|
||||
[英文数据集下载](https://github.com/clovaai/deep-text-recognition-benchmark#download-lmdb-dataset-for-traininig-and-evaluation-from-here)
|
||||
[中文数据集下载](https://github.com/fudanvi/benchmarking-chinese-text-recognition#download)
|
||||
|
||||
#### 启动训练
|
||||
|
||||
请参考[文本识别训练教程](../../ppocr/model_train/recognition.md)。PaddleOCR对代码进行了模块化,训练`SVTR`识别模型时需要**更换配置文件**为`SVTR`的[配置文件](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/configs/rec/rec_svtrnet.yml)。
|
||||
|
||||
具体地,在完成数据准备后,便可以启动训练,训练命令如下:
|
||||
|
||||
```bash linenums="1"
|
||||
#单卡训练(训练周期长,不建议)
|
||||
python3 tools/train.py -c configs/rec/rec_svtrnet.yml
|
||||
|
||||
# 多卡训练,通过--gpus参数指定卡号
|
||||
python3 -m paddle.distributed.launch --gpus '0,1,2,3' tools/train.py -c configs/rec/rec_svtrnet.yml
|
||||
```
|
||||
|
||||
### 3.2 评估
|
||||
|
||||
可下载`SVTR`提供的模型文件和配置文件:[下载地址](https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/rec_svtr_tiny_none_ctc_en_train.tar) ,以`SVTR-T`为例,使用如下命令进行评估:
|
||||
|
||||
```bash linenums="1"
|
||||
# 下载包含SVTR-T的模型文件和配置文件的tar压缩包并解压
|
||||
wget https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/rec_svtr_tiny_none_ctc_en_train.tar && tar xf rec_svtr_tiny_none_ctc_en_train.tar
|
||||
# 注意将pretrained_model的路径设置为本地路径。
|
||||
python3 -m paddle.distributed.launch --gpus '0' tools/eval.py -c ./rec_svtr_tiny_none_ctc_en_train/rec_svtr_tiny_6local_6global_stn_en.yml -o Global.pretrained_model=./rec_svtr_tiny_none_ctc_en_train/best_accuracy
|
||||
```
|
||||
|
||||
### 3.3 预测
|
||||
|
||||
使用如下命令进行单张图片预测:
|
||||
|
||||
```bash linenums="1"
|
||||
# 注意将pretrained_model的路径设置为本地路径。
|
||||
python3 tools/infer_rec.py -c ./rec_svtr_tiny_none_ctc_en_train/rec_svtr_tiny_6local_6global_stn_en.yml -o Global.infer_img='./doc/imgs_words_en/word_10.png' Global.pretrained_model=./rec_svtr_tiny_none_ctc_en_train/best_accuracy
|
||||
# 预测文件夹下所有图像时,可修改infer_img为文件夹,如 Global.infer_img='./doc/imgs_words_en/'。
|
||||
```
|
||||
|
||||
## 4. 推理部署
|
||||
|
||||
### 4.1 Python推理
|
||||
|
||||
首先将训练得到best模型,转换成inference model。下面以`SVTR-T`在英文数据集训练的模型为例([模型和配置文件下载地址](https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/rec_svtr_tiny_none_ctc_en_train.tar) ),可以使用如下命令进行转换:
|
||||
|
||||
```bash linenums="1"
|
||||
# 注意将pretrained_model的路径设置为本地路径。
|
||||
python3 tools/export_model.py -c ./rec_svtr_tiny_none_ctc_en_train/rec_svtr_tiny_6local_6global_stn_en.yml -o Global.pretrained_model=./rec_svtr_tiny_none_ctc_en_train/best_accuracy Global.save_inference_dir=./inference/rec_svtr_tiny_stn_en
|
||||
```
|
||||
|
||||
**注意:** 如果您是在自己的数据集上训练的模型,并且调整了字典文件,请注意修改配置文件中的`character_dict_path`是否为所正确的字典文件。
|
||||
|
||||
转换成功后,在目录下有三个文件:
|
||||
|
||||
```text linenums="1"
|
||||
/inference/rec_svtr_tiny_stn_en/
|
||||
├── inference.pdiparams # 识别inference模型的参数文件
|
||||
├── inference.pdiparams.info # 识别inference模型的参数信息,可忽略
|
||||
└── inference.pdmodel # 识别inference模型的program文件
|
||||
```
|
||||
|
||||
执行如下命令进行模型推理:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_rec.py --image_dir='./doc/imgs_words_en/word_10.png' --rec_model_dir='./inference/rec_svtr_tiny_stn_en/' --rec_algorithm='SVTR' --rec_image_shape='3,64,256' --rec_char_dict_path='./ppocr/utils/ic15_dict.txt'
|
||||
# 预测文件夹下所有图像时,可修改image_dir为文件夹,如 --image_dir='./doc/imgs_words_en/'。
|
||||
```
|
||||
|
||||

|
||||
|
||||
执行命令后,上面图像的预测结果(识别的文本和得分)会打印到屏幕上,示例如下:
|
||||
结果如下:
|
||||
|
||||
```bash linenums="1"
|
||||
Predicts of ./doc/imgs_words_en/word_10.png:('pain', 0.9999998807907104)
|
||||
```
|
||||
|
||||
**注意**:
|
||||
|
||||
* 如果您调整了训练时的输入分辨率,需要通过参数`rec_image_shape`设置为您需要的识别图像形状。
|
||||
* 在推理时需要设置参数`rec_char_dict_path`指定字典,如果您修改了字典,请修改该参数为您的字典文件。
|
||||
* 如果您修改了预处理方法,需修改`tools/infer/predict_rec.py`中SVTR的预处理为您的预处理方法。
|
||||
|
||||
### 4.2 C++推理部署
|
||||
|
||||
由于C++预处理后处理还未支持SVTR,所以暂未支持
|
||||
|
||||
### 4.3 Serving服务化部署
|
||||
|
||||
暂不支持
|
||||
|
||||
### 4.4 更多推理部署
|
||||
|
||||
暂不支持
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
* 1. GPU和CPU速度对比
|
||||
* 由于`SVTR`使用的算子大多为矩阵相乘,在GPU环境下,速度具有优势,但在CPU开启mkldnn加速环境下,`SVTR`相比于被优化的卷积网络没有优势。
|
||||
|
||||
* 2. SVTR模型转ONNX失败
|
||||
* 保证`paddle2onnx`和`onnxruntime`版本最新,转onnx命令参考[SVTR模型转onnx步骤实例](https://github.com/PaddlePaddle/PaddleOCR/issues/7821#issuecomment-1271214273)。
|
||||
* 3. SVTR转ONNX成功但是推理结果不正确
|
||||
* 可能的原因模型参数`out_char_num`设置不正确,应设置为W//4、W//8或者W//12,可以参考[高精度中文场景文本识别模型SVTR的3.3.3章节](https://aistudio.baidu.com/aistudio/projectdetail/5073182?contributionType=1)。
|
||||
* 4. 长文本识别优化
|
||||
* 参考[高精度中文场景文本识别模型SVTR的3.3章节](https://aistudio.baidu.com/aistudio/projectdetail/5073182?contributionType=1)。
|
||||
* 5. 论文结果复现注意事项
|
||||
* 数据集使用[ABINet](https://github.com/FangShancheng/ABINet)提供的数据集;
|
||||
* 默认使用4卡GPU训练,单卡Batchsize默认为512,总Batchsize为2048,对应的学习率为0.0005,当修改Batchsize或者改变GPU卡数,学习率应等比例修改。
|
||||
* 6. 进一步优化的探索点
|
||||
* 学习率调整:可以调整为默认的两倍保持Batchsize不变;或者将Batchsize减小为默认的1/2,保持学习率不变;
|
||||
* 数据增强策略:可选`RecConAug`和`RecAug`;
|
||||
* 如果不使用STN时,可以将`mixer`的`Local`替换为`Conv`、`local_mixer`全部修改为`[5, 5]`;
|
||||
* 网格搜索最优的`embed_dim`、`depth`、`num_heads`配置;
|
||||
* 使用`后Normalization策略`,即是将模型配置`prenorm`修改为`True`。
|
||||
|
||||
## 引用
|
||||
|
||||
```bibtex
|
||||
@article{Du2022SVTR,
|
||||
title = {SVTR: Scene Text Recognition with a Single Visual Model},
|
||||
author = {Du, Yongkun and Chen, Zhineng and Jia, Caiyan and Yin, Xiaoting and Zheng, Tianlun and Li, Chenxia and Du, Yuning and Jiang, Yu-Gang},
|
||||
booktitle = {IJCAI},
|
||||
year = {2022},
|
||||
url = {https://arxiv.org/abs/2205.00159}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,129 @@
|
||||
---
|
||||
comments: true
|
||||
---
|
||||
|
||||
# 场景文本识别算法-SVTRv2
|
||||
|
||||
## 1. 算法简介
|
||||
|
||||
### SVTRv2算法简介
|
||||
|
||||
🔥 该算法由来自复旦大学视觉与学习实验室([FVL](https://fvl.fudan.edu.cn))的[OpenOCR](https://github.com/Topdu/OpenOCR)团队研发,其在[PaddleOCR算法模型挑战赛 - 赛题一:OCR端到端识别任务](https://aistudio.baidu.com/competition/detail/1131/0/introduction)中荣获一等奖,B榜端到端识别精度相比PP-OCRv4提升2.5%,推理速度持平。主要思路:1、检测和识别模型的Backbone升级为RepSVTR;2、识别教师模型升级为SVTRv2,可识别长文本。
|
||||
|
||||
|模型|配置文件|端到端|下载链接|
|
||||
| --- | --- | --- | --- |
|
||||
|PP-OCRv4| |A榜 62.77% <br> B榜 62.51%| [Model List](../../ppocr/model_list.md) |
|
||||
|SVTRv2(Rec Sever)|[configs/rec/SVTRv2/ch_SVTRv2_rec.yml](../../../../configs/rec/SVTRv2/ch_SVTRv2_rec.yml)|A榜 68.81% (使用PP-OCRv4检测模型)| [训练模型](https://paddleocr.bj.bcebos.com/openatom/openatom_rec_svtrv2_ch_train.tar) / [推理模型](https://paddleocr.bj.bcebos.com/openatom/openatom_rec_svtrv2_ch_infer.tar) |
|
||||
|RepSVTR(Mobile)|[识别](../../../../configs/rec/SVTRv2/ch_RepSVTR_rec.yml) <br> [识别蒸馏](../../../../configs/rec/SVTRv2/ch_SVTRv2_rec_distillation.yml) <br> [检测](../../../../configs/det/det_repsvtr_db.yml)|B榜 65.07%| 识别: [训练模型](https://paddleocr.bj.bcebos.com/openatom/openatom_rec_repsvtr_ch_train.tar) / [推理模型](https://paddleocr.bj.bcebos.com/openatom/openatom_rec_repsvtr_ch_infer.tar) <br> 识别蒸馏: [训练模型](https://paddleocr.bj.bcebos.com/openatom/openatom_rec_svtrv2_distill_ch_train.tar) / [推理模型](https://paddleocr.bj.bcebos.com/openatom/openatom_rec_svtrv2_distill_ch_infer.tar) <br> 检测: [训练模型](https://paddleocr.bj.bcebos.com/openatom/openatom_det_repsvtr_ch_train.tar) / [推理模型](https://paddleocr.bj.bcebos.com/openatom/openatom_det_repsvtr_ch_infer.tar) |
|
||||
|
||||
🚀 快速使用:参考PP-OCR推理[说明文档](../../legacy/python_infer.md),将检测和识别模型替换为上表中对应的RepSVTR或SVTRv2推理模型即可使用。
|
||||
|
||||
## 2. 环境配置
|
||||
|
||||
请先参考[《运行环境准备》](../../ppocr/environment.md)配置PaddleOCR运行环境,参考[《项目克隆》](../../ppocr/blog/clone.md)克隆项目代码。
|
||||
|
||||
## 3. 模型训练、评估、预测
|
||||
|
||||
### 3.1 模型训练
|
||||
|
||||
训练命令:
|
||||
|
||||
```bash linenums="1"
|
||||
#单卡训练(训练周期长,不建议)
|
||||
python3 tools/train.py -c configs/rec/SVTRv2/ch_RepSVTR_rec_gtc.yml
|
||||
|
||||
# 多卡训练,通过--gpus参数指定卡号
|
||||
# Rec 学生模型
|
||||
python -m paddle.distributed.launch --gpus '0,1,2,3,4,5,6,7' tools/train.py -c configs/rec/SVTRv2/ch_RepSVTR_rec_gtc.yml
|
||||
# Rec 教师模型
|
||||
python -m paddle.distributed.launch --gpus '0,1,2,3,4,5,6,7' tools/train.py -c configs/rec/SVTRv2/ch_SVTRv2_rec_gtc.yml
|
||||
# Rec 蒸馏训练
|
||||
python -m paddle.distributed.launch --gpus '0,1,2,3,4,5,6,7' tools/train.py -c configs/rec/SVTRv2/ch_SVTRv2_rec_gtc_distill.yml
|
||||
```
|
||||
|
||||
### 3.2 评估
|
||||
|
||||
```bash linenums="1"
|
||||
# 注意将pretrained_model的路径设置为本地路径。
|
||||
python3 -m paddle.distributed.launch --gpus '0' tools/eval.py -c configs/rec/SVTRv2/ch_RepSVTR_rec_gtc.yml -o Global.pretrained_model=output/ch_RepSVTR_rec_gtc/best_accuracy
|
||||
```
|
||||
|
||||
### 3.3 预测
|
||||
|
||||
使用如下命令进行单张图片预测:
|
||||
|
||||
```bash linenums="1"
|
||||
# 注意将pretrained_model的路径设置为本地路径。
|
||||
python3 tools/infer_rec.py -c tools/eval.py -c configs/rec/SVTRv2/ch_RepSVTR_rec_gtc.yml -o Global.pretrained_model=output/ch_RepSVTR_rec_gtc/best_accuracy Global.infer_img='./doc/imgs_words_en/word_10.png'
|
||||
# 预测文件夹下所有图像时,可修改infer_img为文件夹,如 Global.infer_img='./doc/imgs_words_en/'。
|
||||
```
|
||||
|
||||
## 4. 推理部署
|
||||
|
||||
### 4.1 Python推理
|
||||
|
||||
首先将训练得到best模型,转换成inference model,以RepSVTR为例,可以使用如下命令进行转换:
|
||||
|
||||
```bash linenums="1"
|
||||
# 注意将pretrained_model的路径设置为本地路径。
|
||||
python3 tools/export_model.py -c configs/rec/SVTRv2/ch_RepSVTR_rec_gtc.yml -o Global.pretrained_model=output/ch_RepSVTR_rec_gtc/best_accuracy Global.save_inference_dir=./inference/rec_repsvtr_infer
|
||||
```
|
||||
|
||||
**注意:** 如果您是在自己的数据集上训练的模型,并且调整了字典文件,请注意修改配置文件中的`character_dict_path`是否为所正确的字典文件。
|
||||
|
||||
转换成功后,在目录下有三个文件:
|
||||
|
||||
```text linenums="1"
|
||||
./inference/rec_repsvtr_infer/
|
||||
├── inference.pdiparams # 识别inference模型的参数文件
|
||||
├── inference.pdiparams.info # 识别inference模型的参数信息,可忽略
|
||||
└── inference.pdmodel # 识别inference模型的program文件
|
||||
```
|
||||
|
||||
执行如下命令进行模型推理:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_rec.py --image_dir='./doc/imgs_words_en/word_10.png' --rec_model_dir='./inference/rec_repsvtr_infer/'
|
||||
# 预测文件夹下所有图像时,可修改image_dir为文件夹,如 --image_dir='./doc/imgs_words_en/'。
|
||||
```
|
||||
|
||||

|
||||
|
||||
执行命令后,上面图像的预测结果(识别的文本和得分)会打印到屏幕上,示例如下:
|
||||
结果如下:
|
||||
|
||||
```bash linenums="1"
|
||||
Predicts of ./doc/imgs_words_en/word_10.png:('pain', 0.9999998807907104)
|
||||
```
|
||||
|
||||
**注意**:
|
||||
|
||||
- 如果您调整了训练时的输入分辨率,需要通过参数`rec_image_shape`设置为您需要的识别图像形状。
|
||||
- 在推理时需要设置参数`rec_char_dict_path`指定字典,如果您修改了字典,请修改该参数为您的字典文件。
|
||||
- 如果您修改了预处理方法,需修改`tools/infer/predict_rec.py`中SVTR的预处理为您的预处理方法。
|
||||
|
||||
### 4.2 C++推理部署
|
||||
|
||||
准备好推理模型后,参考[cpp infer](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/deploy/cpp_infer)教程进行操作即可。
|
||||
|
||||
### 4.3 Serving服务化部署
|
||||
|
||||
暂不支持
|
||||
|
||||
### 4.4 更多推理部署
|
||||
|
||||
- Paddle2ONNX推理:准备好推理模型后,参考[paddle2onnx](https://github.com/PaddlePaddle/PaddleOCR/tree/{{PADDLEOCR_GITHUB_REF}}/deploy/paddle2onnx)教程操作。
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
## 引用
|
||||
|
||||
```bibtex
|
||||
@article{Du2022SVTR,
|
||||
title = {SVTR: Scene Text Recognition with a Single Visual Model},
|
||||
author = {Du, Yongkun and Chen, Zhineng and Jia, Caiyan and Yin, Xiaoting and Zheng, Tianlun and Li, Chenxia and Du, Yuning and Jiang, Yu-Gang},
|
||||
booktitle = {IJCAI},
|
||||
year = {2022},
|
||||
url = {https://arxiv.org/abs/2205.00159}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,120 @@
|
||||
---
|
||||
comments: true
|
||||
---
|
||||
|
||||
# VisionLAN
|
||||
|
||||
## 1. Introduction
|
||||
|
||||
Paper:
|
||||
> [From Two to One: A New Scene Text Recognizer with Visual Language Modeling Network](https://arxiv.org/abs/2108.09661)
|
||||
> Yuxin Wang, Hongtao Xie, Shancheng Fang, Jing Wang, Shenggao Zhu, Yongdong Zhang
|
||||
> ICCV, 2021
|
||||
|
||||
Using MJSynth and SynthText two text recognition datasets for training, and evaluating on IIIT, SVT, IC13, IC15, SVTP, CUTE datasets, the algorithm reproduction effect is as follows:
|
||||
|
||||
|Model|Backbone|config|Acc|Download link|
|
||||
| --- | --- | --- | --- | --- |
|
||||
|VisionLAN|ResNet45|[rec_r45_visionlan.yml](../../../../configs/rec/rec_r45_visionlan.yml)|90.30%|[model link](https://paddleocr.bj.bcebos.com/VisionLAN/rec_r45_visionlan_train.tar)|
|
||||
|
||||
## 2. Environment
|
||||
|
||||
Please refer to ["Environment Preparation"](../../ppocr/environment.en.md) to configure the PaddleOCR environment, and refer to ["Project Clone"](../../ppocr/blog/clone.en.md)to clone the project code.
|
||||
|
||||
## 3. Model Training / Evaluation / Prediction
|
||||
|
||||
Please refer to [Text Recognition Tutorial](../../ppocr/model_train/recognition.en.md). PaddleOCR modularizes the code, and training different recognition models only requires **changing the configuration file**.
|
||||
|
||||
### Training
|
||||
|
||||
Specifically, after the data preparation is completed, the training can be started. The training command is as follows:
|
||||
|
||||
```bash linenums="1"
|
||||
# Single GPU training (long training period, not recommended)
|
||||
python3 tools/train.py -c configs/rec/rec_r45_visionlan.yml
|
||||
|
||||
# Multi GPU training, specify the gpu number through the --gpus parameter
|
||||
python3 -m paddle.distributed.launch --gpus '0,1,2,3' tools/train.py -c configs/rec/rec_r45_visionlan.yml
|
||||
```
|
||||
|
||||
### Evaluation
|
||||
|
||||
```bash linenums="1"
|
||||
# GPU evaluation
|
||||
python3 tools/eval.py -c configs/rec/rec_r45_visionlan.yml -o Global.pretrained_model={path/to/weights}/best_accuracy
|
||||
```
|
||||
|
||||
### Prediction
|
||||
|
||||
```bash linenums="1"
|
||||
# The configuration file used for prediction must match the training
|
||||
python3 tools/infer_rec.py -c configs/rec/rec_r45_visionlan.yml -o Global.infer_img='./doc/imgs_words/en/word_2.png' Global.pretrained_model=./rec_r45_visionlan_train/best_accuracy
|
||||
```
|
||||
|
||||
## 4. Inference and Deployment
|
||||
|
||||
### 4.1 Python Inference
|
||||
|
||||
First, the model saved during the VisionLAN text recognition training process is converted into an inference model. ( [Model download link](https://paddleocr.bj.bcebos.com/VisionLAN/rec_r45_visionlan_train.tar)) ), you can use the following command to convert:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/export_model.py -c configs/rec/rec_r45_visionlan.yml -o Global.pretrained_model=./rec_r45_visionlan_train/best_accuracy Global.save_inference_dir=./inference/rec_r45_visionlan/
|
||||
```
|
||||
|
||||
**Note:**
|
||||
|
||||
- If you are training the model on your own dataset and have modified the dictionary file, please pay attention to modify the `character_dict_path` in the configuration file to the modified dictionary file.
|
||||
- If you modified the input size during training, please modify the `infer_shape` corresponding to VisionLAN in the `tools/export_model.py` file.
|
||||
|
||||
After the conversion is successful, there are three files in the directory:
|
||||
|
||||
```text linenums="1"
|
||||
./inference/rec_r45_visionlan/
|
||||
├── inference.pdiparams
|
||||
├── inference.pdiparams.info
|
||||
└── inference.pdmodel
|
||||
```
|
||||
|
||||
For VisionLAN text recognition model inference, the following commands can be executed:
|
||||
|
||||
```bash linenums="1"
|
||||
python3 tools/infer/predict_rec.py --image_dir='./doc/imgs_words/en/word_2.png' --rec_model_dir='./inference/rec_r45_visionlan/' --rec_algorithm='VisionLAN' --rec_image_shape='3,64,256' --rec_char_dict_path='./ppocr/utils/ic15_dict.txt' --use_space_char=False
|
||||
```
|
||||
|
||||

|
||||
|
||||
After executing the command, the prediction result (recognized text and score) of the image above is printed to the screen, an example is as follows:
|
||||
The result is as follows:
|
||||
|
||||
```bash linenums="1"
|
||||
Predicts of ./doc/imgs_words/en/word_2.png:('yourself', 0.9999493)
|
||||
```
|
||||
|
||||
### 4.2 C++ Inference
|
||||
|
||||
Not supported
|
||||
|
||||
### 4.3 Serving
|
||||
|
||||
Not supported
|
||||
|
||||
### 4.4 More
|
||||
|
||||
Not supported
|
||||
|
||||
## 5. FAQ
|
||||
|
||||
1. Note that the MJSynth and SynthText datasets come from [VisionLAN repo](https://github.com/wangyuxin87/VisionLAN).
|
||||
2. We use the pre-trained model provided by the VisionLAN authors for finetune training. The dictionary for the pre-trained model is 'ppocr/utils/ic15_dict.txt'.
|
||||
|
||||
## Citation
|
||||
|
||||
```bibtex
|
||||
@inproceedings{wang2021two,
|
||||
title={From Two to One: A New Scene Text Recognizer with Visual Language Modeling Network},
|
||||
author={Wang, Yuxin and Xie, Hongtao and Fang, Shancheng and Wang, Jing and Zhu, Shenggao and Zhang, Yongdong},
|
||||
booktitle={Proceedings of the IEEE/CVF International Conference on Computer Vision},
|
||||
pages={14194--14203},
|
||||
year={2021}
|
||||
}
|
||||
```
|
||||