English | 中文
EAST (Efficient and Accurate Scene Text Detection)是一种高效、准确且轻量级的OCR检测算法,主要用于在自然场景下的文本检测。该算法使用深度残差网络提取文本特征,在特征金字塔网络中进行特征融合,并采用二分类和定位两个分支来检测文本。EAST在文本检测的准确性和鲁棒性方面取得了显著的成果。
图 1. EAST整体架构图(我们使用ResNet50取代图中的PVANet)
EAST的整体架构图如图1所示,包含以下阶段:
1.特征提取:
使用Resnet-50作为骨干网络,从2,3,4,5阶段进行不同层级的特征提取;
2.特征融合:
采用特征融合的方式,将骨干网络中不同层级的特征进行放大,并和更大的特征图沿通道轴进行连接,如此反复。使得模型可以对不同大小的文本区域进行处理,并提高检测的精度。
3.边界框回归:
对文本框的位置以及旋转角进行回归,使得EAST能够检测倾斜文本,完成自然场景下文本检测的任务。目前支持检测旋转矩形文本区域的文本框。
4.文本分支:
在确定了文本区域的位置和大小后,EAST模型会进一步将这些区域分类为文本或非文本区域。为此,模型采用了一条全卷积的文本分支,对文本区域进行二分类。
模型 | 环境配置 | 骨干网络 | 预训练数据集 | Recall | Precision | F-score | 训练时间 | 每步耗时 | 吞吐量 | 配置文件 | 模型权重下载 |
---|---|---|---|---|---|---|---|---|---|---|---|
EAST | D910x8-MS1.9-G | ResNet-50 | ImageNet | 82.23% | 87.68% | 84.87% | 1.6 s/epoch | 256 ms/step | 625 img/s | yaml | ckpt | mindir |
EAST | D910x8-MS1.9-G | MobileNetV3 | ImageNet | 73.47% | 77.27% | 75.32% | 0.79 s/epoch | 138 ms/step | 1185 img/s | yaml | ckpt | mindir |
(1,3,720,1280)
。请参考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
在配置文件configs/det/east/east_r50_icdar15.yaml
中更新如下文件路径。其中dataset_root
会分别和dataset_root
以及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
参数的值。
EAST由3个部分组成:backbone
、neck
和head
。具体来说:
model:
type: det
transform: null
backbone:
name: det_resnet50
pretrained: True # 是否使用ImageNet数据集上的预训练权重
neck:
name: EASTFPN # EAST的特征金字塔网络
out_channels: 128
head:
name: EASTHead
请确保yaml文件中的distribute
参数为False。
# train east on ic15 dataset
python tools/train.py --config configs/det/east/east_r50_icdar15.yaml
请确保yaml文件中的distribute
参数为True。
# n is the number of GPUs/NPUs
mpirun --allow-run-as-root -n 8 python tools/train.py --config configs/det/east/east_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/east/east_r50_icdar15.yaml
请参考MindOCR 推理教程,基于MindSpore Lite在Ascend 310上进行模型的推理,包括以下步骤:
请先下载已导出的MindIR文件,或者参考模型导出教程,使用以下命令将训练完成的ckpt导出为MindIR文件:
python tools/export.py --model_name_or_config east_resnet50 --data_shape 720 1280 --local_ckpt_path /path/to/local_ckpt.ckpt
# or
python tools/export.py --model_name_or_config configs/det/east/east_r50_icdar15.yaml --data_shape 720 1280 --local_ckpt_path /path/to/local_ckpt.ckpt
其中,data_shape
是导出MindIR时的模型输入Shape的height和width,下载链接中MindIR对应的shape值见注释。
请参考环境安装教程,配置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/east/east_r50_icdar15.yaml \
--res_save_dir=results_dir
[1] Xinyu Zhou, Cong Yao, He Wen, Yuzhi Wang, Shuchang Zhou, Weiran He, Jiajun Liang. EAST: An Efficient and Accurate Scene Text Detector. arXiv:1704.03155, 2017
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》