English | 中文
DBNet: Real-time Scene Text Detection with Differentiable Binarization
DBNet++: Real-Time Scene Text Detection with Differentiable Binarization and Adaptive Scale Fusion
DBNet是一种基于分割的场景文本检测算法。在场景文本检测中,基于分割这类算法可以更加准确的描述各种形状的场景文本(比如弯曲形状的文本),而变得越来越流行。现有的基于分割的业界领先算法存在的缺陷是,概率图转化为文本框的二值化后处理过程通常需要人为设置一个阈值,而且后处理的聚合像素点的操作非常复杂且费时。
为了避免上述问题,DBNet在网络架构中集成了一个叫作“可微分二值化(Differentiable Binarization)”的自适应阈值。可微分二值化简化了后处理过程,增强了文本检测的性能。此外,在推理阶段移除该部分不会使性能降低[1]。
图 1. DBNet整体架构图
DBNet的整体架构图如图1所示,包含以下阶段:
DBNet++架构与DBNet相似,是DBNet的延伸。两者唯一的区别是,DBNet直接拼接从主干网络中提取和缩放的特征,而DBNet++使用一个自适应的模块(Adaptive Scale Fusion, ASF)来融合这些特征,如图2所示。
该模块可以自适应地融合不同尺寸的特征,有更好的尺寸(scale)鲁棒性。因此,DBNet++检测不同尺寸的文本的能力有显著提升。[2]
图 2. DBNet++整体架构图
图 3. Adaptive Scale Fusion模块架构图
ASF由两个注意力模块组成——阶段注意力模块(stage-wise attention)和空间注意力模块(spatial attention),后者集成在前者中,如图3所示。
阶段注意模块学习不同尺寸的特征图的权重,而空间注意力模块学习跨空间维度的attention。这两个模块的组合使得模型可以获得尺寸(scale)鲁棒性很好的特征融合。
DBNet++在检测不同尺寸的文本方面表现更好,尤其是对于尺寸较大的文本;然而,DBNet在检测尺寸较大的文本时可能会生成不准确或分离的检测框。
本节提供了一些通过泛化模型,该模型使用中文和英文两种语言训练,针对各种不同的任务和挑战,包括真实世界图片,街景图片,文档,弯曲文本,长文本等。这些模型可直接用于下游任务,也可直接作为预训练权重。
这些模型在12个公开数据集上训练,包括CTW,LSVT,RCTW-17,TextOCR等,其中训练集包含153511张图片,验证集包含9786张图片。
从上述数据集中手动选择598张未被训练集和验证集使用的图片构成测试集。
模型 | 环境配置 | 骨干网络 | 语言 | F-score | 吞吐量 | 模型权重下载 |
---|---|---|---|---|---|---|
DBNet | D910x8-MS2.0-G | ResNet-50 | Chinese + English | 83.41% | 256 img/s | ckpt | mindir |
DBNet++ | D910x4-MS2.0-G | ResNet-50 | Chinese + English | 84.30% | 104 img/s | ckpt | mindir |
链接中模型DBNet的MindIR导出时的输入Shape为
(1,3,736,1280)
,模型DBNet++的MindIR导出时的输入Shape为(1,3,1152,2048)
。
DBNet和DBNet++在ICDAR2015,MSRA-TD500,SCUT-CTW1500,Total-Text和MLT2017数据集上训练。另外,我们在SynthText数据集上进行了预训练,并提供预训练权重下载链接。所有训练结果如下:
模型 | 环境配置 | 骨干网络 | 预训练数据集 | Recall | Precision | F-score | 训练时间 | 吞吐量 | 配置文件 | 模型权重下载 |
---|---|---|---|---|---|---|---|---|---|---|
DBNet | D910x1-MS2.0-G | MobileNetV3 | ImageNet | 76.26% | 78.22% | 77.28% | 10 s/epoch | 100 img/s | yaml | ckpt | mindir |
DBNet | D910x1-MS2.0-G | ResNet-18 | ImageNet | 80.12% | 83.41% | 81.73% | 9.3 s/epoch | 108 img/s | yaml | ckpt | mindir |
DBNet | D910x1-MS2.0-G | ResNet-50 | ImageNet | 83.53% | 86.62% | 85.05% | 13.3 s/epoch | 75.2 img/s | yaml | ckpt | mindir |
DBNet++ | D910x1-MS2.0-G | ResNet-50 | SynthText | 85.70% | 87.81% | 86.74% | 17.7 s/epoch | 56 img/s | yaml | ckpt | mindir |
链接中模型DBNet的MindIR导出时的输入Shape为
(1,3,736,1280)
,模型DBNet++的MindIR导出时的输入Shape为(1,3,1152,2048)
。
模型 | 环境配置 | 骨干网络 | 预训练数据集 | Recall | Precision | F-score | 训练时间 | 吞吐量 | 配置文件 | 模型权重下载 |
---|---|---|---|---|---|---|---|---|---|---|
DBNet | D910x1-MS2.0-G | ResNet-18 | SynthText | 79.90% | 88.07% | 83.78% | 5.6 s/epoch | 121.7 img/s | yaml | ckpt |
DBNet | D910x1-MS2.0-G | ResNet-50 | SynthText | 84.02% | 87.48% | 85.71% | 9.6 s/epoch | 71.2 img/s | yaml | ckpt |
MSRA-TD500数据集有300训练集图片和200测试集图片,参考论文Real-time Scene Text Detection with Differentiable Binarization,我们训练此权重额外使用了来自HUST-TR400数据集的400训练集图片。可以在此下载全部数据集用于训练。
模型 | 环境配置 | 骨干网络 | 预训练数据集 | Recall | Precision | F-score | 训练时间 | 吞吐量 | 配置文件 | 模型权重下载 |
---|---|---|---|---|---|---|---|---|---|---|
DBNet | D910x1-MS2.0-G | ResNet-18 | SynthText | 85.68% | 85.33% | 85.50% | 8.2 s/epoch | 122.1 img/s | yaml | ckpt |
DBNet | D910x1-MS2.0-G | ResNet-50 | SynthText | 87.83% | 84.71% | 86.25% | 14.0 s/epoch | 71.4 img/s | yaml | ckpt |
模型 | 环境配置 | 骨干网络 | 预训练数据集 | Recall | Precision | F-score | 训练时间 | 吞吐量 | 配置文件 | 模型权重下载 |
---|---|---|---|---|---|---|---|---|---|---|
DBNet | D910x1-MS2.0-G | ResNet-18 | SynthText | 83.66% | 87.61% | 85.59% | 12.9 s/epoch | 96.9 img/s | yaml | ckpt |
DBNet | D910x1-MS2.0-G | ResNet-50 | SynthText | 84.79% | 87.07% | 85.91% | 18.0 s/epoch | 69.1 img/s | yaml | ckpt |
模型 | 环境配置 | 骨干网络 | 预训练数据集 | Recall | Precision | F-score | 训练时间 | 吞吐量 | 配置文件 | 模型权重下载 |
---|---|---|---|---|---|---|---|---|---|---|
DBNet | D910x8-MS2.0-G | ResNet-18 | SynthText | 73.62% | 83.93% | 78.44% | 20.9 s/epoch | 344.8 img/s | yaml | ckpt |
DBNet | D910x8-MS2.0-G | ResNet-50 | SynthText | 76.04% | 84.51% | 80.05% | 23.6 s/epoch | 305.6 img/s | yaml | ckpt |
模型 | 环境配置 | 骨干网络 | 预训练数据集 | 训练Loss | 训练时间 | 吞吐量 | 配置文件 | 模型权重下载 |
---|---|---|---|---|---|---|---|---|
DBNet | D910x1-MS2.0-G | ResNet-18 | ImageNet | 2.41 | 7075 s/epoch | 121.37 img/s | yaml | ckpt |
DBNet | D910x1-MS2.0-G | ResNet-50 | ImageNet | 2.25 | 10470 s/epoch | 82.02 img/s | yaml | ckpt |
请参考MindOCR套件的安装指南 。
请从该网址下载ICDAR2015数据集,然后参考数据转换对数据集标注进行格式转换。
完成数据准备工作后,数据的目录结构应该如下所示:
.
├── test
│ ├── images
│ │ ├── img_1.jpg
│ │ ├── img_2.jpg
│ │ └── ...
│ └── test_det_gt.txt
└── train
├── images
│ ├── img_1.jpg
│ ├── img_2.jpg
│ └── ....jpg
└── train_det_gt.txt
请从该网址下载MSRA-TD500数据集,然后参考数据转换对数据集标注进行格式转换。
完成数据准备工作后,数据的目录结构应该如下所示:
MSRA-TD500
├── test
│ ├── IMG_0059.gt
│ ├── IMG_0059.JPG
│ ├── IMG_0080.gt
│ ├── IMG_0080.JPG
│ ├── ...
│ ├── train_det_gt.txt
├── train
│ ├── IMG_0030.gt
│ ├── IMG_0030.JPG
│ ├── IMG_0063.gt
│ ├── IMG_0063.JPG
│ ├── ...
│ ├── test_det_gt.txt
请从该网址下载SCUT-CTW1500数据集,然后参考数据转换对数据集标注进行格式转换。
完成数据准备工作后,数据的目录结构应该如下所示:
ctw1500
├── test_images
│ ├── 1001.jpg
│ ├── 1002.jpg
│ ├── ...
├── train_images
│ ├── 0001.jpg
│ ├── 0002.jpg
│ ├── ...
├── test_det_gt.txt
├── train_det_gt.txt
请从该网址下载Total-Text数据集,然后参考数据转换对数据集标注进行格式转换。
完成数据准备工作后,数据的目录结构应该如下所示:
totaltext
├── Images
│ ├── Train
│ │ ├── img1001.jpg
│ │ ├── img1002.jpg
│ │ ├── ...
│ ├── Test
│ │ ├── img1.jpg
│ │ ├── img2.jpg
│ │ ├── ...
├── test_det_gt.txt
├── train_det_gt.txt
MLT2017数据集是一个多语言文本检测识别数据集,包含中文、日文、韩文、英文、法文、阿拉伯文、意大利文、德文和印度文共9种语言。请从该网址下载MLT2017数据集,解压后请将数据中格式为.gif的图像转化为.jpg或.png格式。然后参考数据转换对数据集标注进行格式转换。
完成数据准备工作后,数据的目录结构应该如下所示:
MLT_2017
├── train
│ ├── img_1.png
│ ├── img_2.png
│ ├── img_3.jpg
│ ├── img_4.jpg
│ ├── ...
├── validation
│ ├── img_1.jpg
│ ├── img_2.jpg
│ ├── ...
├── train_det_gt.txt
├── validation_det_gt.txt
用户如果想要使用自己的数据集进行训练,请参考数据转换对数据集标注进行格式转换。并配置yaml文件,然后使用单卡或者多卡运行train.py进行训练即可,详细信息可参考下面几节教程。
请从该网址下载SynthText数据集,解压后的数据的目录结构应该如下所示:
.
├── SynthText
│ ├── 1
│ │ ├── img_1.jpg
│ │ ├── img_2.jpg
│ │ └── ...
│ ├── 2
│ │ ├── img_1.jpg
│ │ ├── img_2.jpg
│ │ └── ...
│ ├── ...
│ ├── 200
│ │ ├── img_1.jpg
│ │ ├── img_2.jpg
│ │ └── ...
│ └── gt.mat
⚠️ 另外, 我们强烈建议在使用
SynthText
数据集之前先进行预处理,因为它包含一些错误的数据。可以使用下列的方式进行校正:python tools/dataset_converters/convert.py --dataset_name=synthtext --task=det --label_dir=/path-to-data-dir/SynthText/gt.mat --output_path=/path-to-data-dir/SynthText/gt_processed.mat
以上的操作会产生与
SynthText
原始标注格式相同但是是经过过滤后的标注数据.
在配置文件configs/det/dbnet/db_r50_icdar15.yaml
中更新如下文件路径。其中dataset_root
会分别和data_dir
以及label_file
拼接构成完整的数据集目录和标签文件路径。
...
train:
ckpt_save_dir: './tmp_det'
dataset_sink_mode: False
dataset:
type: DetDataset
dataset_root: dir/to/dataset <--- 更新
data_dir: train/images <--- 更新
label_file: train/train_det_gt.txt <--- 更新
...
eval:
dataset_sink_mode: False
dataset:
type: DetDataset
dataset_root: dir/to/dataset <--- 更新
data_dir: test/images <--- 更新
label_file: test/test_det_gt.txt <--- 更新
...
【可选】可以根据CPU核的数量设置
num_workers
参数的值。
DBNet由3个部分组成:backbone
、neck
和head
。具体来说:
model:
type: det
transform: null
backbone:
name: det_resnet50 # 暂时只支持ResNet50
pretrained: True # 是否使用ImageNet数据集上的预训练权重
neck:
name: DBFPN # DBNet的特征金字塔网络
out_channels: 256
bias: False
use_asf: False # DBNet++的自适应尺度融合模块 (仅供DBNet++使用)
head:
name: DBHead
k: 50 # 可微分二值化的放大因子
bias: False
adaptive: True # 训练时设置为True, 推理时设置为False
请确保yaml文件中的distribute
参数为False。
# train dbnet on ic15 dataset
python tools/train.py --config configs/det/dbnet/db_r50_icdar15.yaml
请确保yaml文件中的distribute
参数为True。
# n is the number of GPUs/NPUs
mpirun --allow-run-as-root -n 2 python tools/train.py --config configs/det/dbnet/db_r50_icdar15.yaml
训练结果(包括checkpoint、每个epoch的性能和曲线图)将被保存在yaml配置文件的ckpt_save_dir
参数配置的路径下,默认为./tmp_det
。
评估环节,在yaml配置文件中将ckpt_load_path
参数配置为checkpoint文件的路径,设置distribute
为False,然后运行:
python tools/eval.py --config configs/det/dbnet/db_r50_icdar15.yaml
请参考MindOCR 推理教程,基于MindSpore Lite在Ascend 310上进行模型的推理,包括以下步骤:
请先下载已导出的MindIR文件,或者参考模型导出教程,使用以下命令将训练完成的ckpt导出为MindIR文件:
python tools/export.py --model_name_or_config dbnet_resnet50 --data_shape 736 1280 --local_ckpt_path /path/to/local_ckpt.ckpt
# or
python tools/export.py --model_name_or_config configs/det/dbnet/db_r50_icdar15.yaml --data_shape 736 1280 --local_ckpt_path /path/to/local_ckpt.ckpt
其中,data_shape
是导出MindIR时的模型输入Shape的height和width,下载链接中MindIR对应的shape值见ICDAR2015注释。
请参考环境安装教程,配置MindSpore Lite推理运行环境。
请参考模型转换教程,使用converter_lite
工具对MindIR模型进行离线转换。
假设在模型转换后得到output.mindir文件,在deploy/py_infer
目录下使用以下命令进行推理:
python infer.py \
--input_images_dir=/your_path_to/test_images \
--det_model_path=your_path_to/output.mindir \
--det_model_name_or_config=../../configs/det/dbnet/db_r50_icdar15.yaml \
--res_save_dir=results_dir
[1] Minghui Liao, Zhaoyi Wan, Cong Yao, Kai Chen, Xiang Bai. Real-time Scene Text Detection with Differentiable
Binarization. arXiv:1911.08947, 2019
[2] Minghui Liao, Zhisheng Zou, Zhaoyi Wan, Cong Yao, Xiang Bai. Real-Time Scene Text Detection with Differentiable
Binarization and Adaptive Scale Fusion. arXiv:2202.10304, 2022
Dear OpenI User
Thank you for your continuous support to the Openl Qizhi Community AI Collaboration Platform. In order to protect your usage rights and ensure network security, we updated the Openl Qizhi Community AI Collaboration Platform Usage Agreement in January 2024. The updated agreement specifies that users are prohibited from using intranet penetration tools. After you click "Agree and continue", you can continue to use our services. Thank you for your cooperation and understanding.
For more agreement content, please refer to the《Openl Qizhi Community AI Collaboration Platform Usage Agreement》