论文解读系列二十:自然场景文字检测与识别系列--再探DB文字检测算法
博文论文解读系列二:AAAI2020 基于Differentiable Binarization分割方法的文字检测算法-云社区-华为云 (huaweicloud.com) 已经介绍过了DB文字检测算法。本文将更加细致地再探DB文字检测算法,尤其关注可微分二值化模块的理论分析。
1. 引言
基于分割的自然场景文字检测算法目前获得了大量的关注。得益于像素级别精确的预测结果,基于分割的自然场景文字检测算法对各种形状的文字的更够进行精确的表示。但是,大多数基于分割的自然场景文字检测方法并不直接预测文字包围框,因此通常需要复杂的后处理步 骤将分割网络产生的概率图转化为文字区域,导致了推理阶段的巨大时间消耗。以最近的两个基于分割的自然场景文字检测算法为例: PSENet [86] 提出了一个渐进的尺度膨胀后处理算法来提升检测精度; Tian 等人 [87] 提出了需要计算像素间特征距离的像素嵌入( Pixel Embedding )算法来对分割结果中的像素进行分组。
大多数已有的基于分割的自然场景文字检测方法使用如图 1(蓝色箭头)所示的相似的后处理流程:首先,设定一个固定的阈值来将分割网络产生的分割概率图转换为二值图;然后,使用一些启发式的技术比如像素聚类来将像素分组为文字实例区域。 该方法 提出的后处理流程(图 1中红色箭头)将二值化步骤嵌入到分割网络中进行联合训练。这样,可以在图上每个位置的动态地预测阈值,以区分前景和背景像素。然而,由于标准二值化函数不是完全可导的, 该方法提出了一个近似函数,名为可微分二值化( Differentiable Binarization )。这使得其与分割网络一起训练时是完全可导的。
该方法 的主要贡献是可微分二值化模块。它使得二值化过程能够在基于分割的卷积神经网络中进行联合优化。通过结合一个简单的分割网络和可微分二值化,本节提出了一个鲁棒和快速的场景文字检测器。 该方法 及其提出的可微分二值化具有以下优势:( 1 ) 该方法 在 5 个标准数据集上(包括水平的、多方向的和不规则形状的文字数据集)取得了一致的最好的精度;( 2 ) 该方法 的推理速度比之前的领先的方法快很多,得益于可微分二值化提供了高度鲁棒的二值图,极大地化简了后处理;( 3 )当使用一个轻量级的骨架网络比如 ResNet -18 [88] 时,可微分二值化能显著地提高检测精度;( 4 )可微分二值化可以在推理阶段被移除而不损失精度,因此它在推理阶段不带来额外的内存消耗和时间消耗。
图 1 后处理流程示意图
蓝色箭头表示传统流程;红色箭头表示该方法的流程。虚线箭头表示只出现在推理阶段的流程;实线箭头表示出现在训练阶段和推理阶段的流程。
2. 相关工作
当前的自然场景文字检测方法可以大致分为基于回归的方法和基于分割的方法。
2.1 基于回归的方法
该类方法直接回归文字实例的包围框。TextBoxes ++ 算法和 DMPNet [49] 通过回归四边形来检测多方向文字。 SSTD [89] 提出了一个注意力机制以粗略地区分文字区域。 RRD [90] 将通过使用旋转不变的特征进行分类,使用旋转敏感的特征进行回归,从而将分类和回归进行了解耦,以达到更好地检测多方向文字和极端长宽比文字。 EAST [46] 和 DeepReg [91] 是无默认框的多方向文字回归算法。 SegLink [45] 回归文字片段的包围框以及它们的连接关系以处理极端长宽比文字。 DeRPN [92] 提出了一个维度分解区域候选网络来处理文字检测中的尺度问题。基于回归的方法通常拥有简单的后处理算法(比如非最大值抑制)。然而,它们大多数都受限于包围框的表示,难以精确表示不规则形状文字,比如曲型文字。
2.2 基于分割的方法
该类方法通常结合一个像素级别的预测网络和一个后处理算法来得到文字实例的包围框。 Zhang 等人 [44] 通过结合语义分割和基于 MSER [33] 的算法进行多方向文字检测。 Xue 等人 [93] 使用文字边界来分离文字实例。 PSENet [86] 提出了渐进的尺度膨胀来处理不同尺度的分割结果。 Tian 等人 [87] 提出了像素嵌入从分割结果中聚类像素。最后两种方法均提出了新的后处理算法,但是它们的后处理算法在提升结果的同时,大大降低了推理速度。 该方法 侧重在通过将二值化过程引入训练阶段,在不带来额外推理速度消耗的情况下提升分割结果。
3. 可微分二值化网络( DBNet )
图 2 DBNet 的框架图
该方法 的框架图如 图 2 所示。首先,将输入图片输入到一个金字塔结构的骨架网络中;其次,金字塔结构的特征被上采样到相同的尺度并且串联起来生成融合后的特征;然后,该特征用来预测概率图 和阈值图 ;之后,利用可微分二值化将概率图和阈值图计算为近似二值图。在训练阶段,概率图、阈值图、近似二值图都加了监督,其中概率图和近似二值图共用相同的监督。在推理阶段,可以通过一个框生成算法从近似二值图或者概率图很容易地得到文字的包围框。
3.1 二值化
( 1 ) 标准二值化 ( Standard Binarization, SB )
给定一个由分割网络产生的概率图 ,将其转化为二值图 的二值化过程是非常关键的。标准的二值化过程如下:
其中 t 是预先定义的阈值。
图 3 可微分二值化函数( DB )与标准二值化函数( SB )的示意图
( 2 ) 可微分二值化 ( Di fferentiable Binarization, DB )
标准二值化函数不是完全可微分的,它无法在训练过程中很好地与分割网络联合优化。为了解决这个问题, 该方法提出了使用一个近似的阶跃函数来进行近似的二值化:
其中k表示放大因子,根据经验设置为 50 。如图 3 所示,近似的二值化函数与标准的二值化函数在数值上非常接近,但是前者是完全可导的。因此,它可以在训练阶段与分割网络一起联合优化。结合动态阈值的可微分二值化不仅能够帮助区分文字区域和背景,还能够更好地分离相邻的文字实例。
( 3 )可微分二值化模块的理论分析
可微分二值化可以提升文字检测精度的原因可以通过反向传播的梯度的取值范围来解释。以二分类交叉熵损失函数为例,该损失函数可以表示为:
于是,在一个分割任务中,正样本的损失和负样本的损失分别为:
正样本和负样本的损失函数的微分可以使用链式法则计算如下:
定义x_i,j = P_i,j - T_i,j ,可微分二值化函数可以表示为
类似地,正样本和负样本的损失可以表示为:
使用可微分二值化的正样本和负样本的损失函数的微分可以表示为:
使用可微分二值化和不使用可微分二值化的损失函数的微分的数值在 图 4 中展示,从中可以得知:
( 1 )分类边界值附近的微分值的幅度。对于标准二分类交叉熵损失函数(左图),其微分值在正样本值( > 0.5 )和负样本值( < 0.5 )中间的分类边界值( 0 .5 )附近的幅度是非常小的 。因此,当预测值模棱两可时(比如 0 .4 或者 0 .6 )时,对应的反向传播或者反馈可能不够显著;对于带有可微分二值化的二分类交叉熵损失函数(右图),其微分值在正样本值( > 0 )和负样本值( < 0 )中间的分类边界值( 0 )附近的幅度是非常大的,其放大因子为 。因此, 该方法 所提出的可微分二值化能够帮助模型在分类边界值附近产生更具区分性的预测。
( 2 ) 下确界和上确界。 对于标准二分类交叉熵损失函数(左图), 其微分值没有下确界或者没有上确界 ;对于带有可微分二值化的二分类交叉熵损失函数(右图), 其下确界或者上确界是由放大因子k决定的。因此, 该方法所提出的可微分二值化倾向于在极大或者极小的预测值的情况下表现地更稳定。
综上所述,可微分二值化模块增强了模型在分类边界值附近的错误预测的反向传播的反馈,减弱了极大或者极小的错误预测值带来的反向传播的反馈。这能够让模型侧重于优化那些难以预测 / 模棱两可的区域的预测。
图 4 损失函数分的数值比较
左图表示无可微分二值化时;右图表示有可微分二值化时。
3.2. 动态阈值
如图 1 所示的阈值图视觉外观与文字边界图 [93] 非常接近。然而,阈值图的动机和用法与文字边界图是截然不同的。 图 5 展示了在有监督和无监督情形下的阈值图。在没有阈值监督的情况下,阈值图倾向于突显文字的边界区域。这说明文字边界型的阈值图对最终的结果更有好处。因此,阈值图采用了形似文字边界的监督以实现更好的引导。实验部分讨论了有监督和无监督下的检测精度的变化。对于用法, Xue 等人 [93] 的文字边界图是用来分离邻近的文字区域,而阈值图则被用作二值化过程的阈值。
图 5 有监督和无监督的阈值图
( a )输入图片;( b )概率图;( c )无监督的阈值图;( d )有监督的阈值图。
3.3. 可变形卷积
可变形卷积 [94,95] 能够给网络模型提供一个灵活的感受野,对检测极端长宽比的文字实例有很大好处。遵循 Zhu 等人 [95] , 该方法 在 ResNet-18 和 ResNet -50 骨架网络中的 conv 3 、 conv 4 和 conv 5 中所有的卷积使用了已调制的可变形卷积。
3.4. 标签生成
标签生成的示意图如图 6 所示。概率图的标签生成是受 PSENet [86] 启发。给定一个文字图片,文字区域的每个多边形可以表示为一系列片段:
其中 n 是多边形顶点的数量。然后,使用 Vatti clipping 算法 [96] 收缩多边形。收缩的偏移量由原多边形的周长和面积计算得到:
其中r是收缩比例,根据经验设置为 0.4 。
阈值图的生成也是类似的流程。首先对文字区域的多边形使用相同的偏移量进行膨胀;然后将两个多边形之间的区域设置为边界,其中的标签通过计算其到文字区域多边形的距离来生成。
图 6 标签生成示意图
红色的包围框表示文字的多边形标注。收缩和膨胀的包围框分别使用蓝色和绿色表示。
3.5. 优化
损失函数可以表示为概率图损失函数 、二值图损失函数和阈值图损失函数多个损失函数的加权和:
概率图损失函数和二值图损失函数采用的是二分类交叉熵损失函数。为了克服正负样本数量的不平衡, 该方法 在二分类交叉熵损失函数中采用了困难负样本挖掘,计算方式如下:
阈值损失函数是由膨胀文字区域 内部预测值和标签值之间的距离之和计算得到:
在推理阶段, 该方法既可以使用概率图也可以使用近似二值图来生成文字的包围框。两者产生的结果非常接近。为了更高的效率, 该方法使用概率图从而可以移除动态阈值分支。框生成算法由三个步骤组成:( 1 ) 概率图或者近似二值图通过一个常量阈值进行二值化;( 2 )从二值图得到连通区域(收缩的文字区域);( 3 )收缩文字区域使用 Vatti clipping算法按照一个偏移量进行膨胀。 计算如下:
4. 实验
该方法在多个标准的文字检测数据集均取得了SOTA的精度和极具竞争力的推理速度,详见论文,在此不再赘述。
5. 方法局限性
该方法的一个局限性是它无法处理“文字中的文字”的情况,即一个文字实例在另一个文字实例的内部,如图 7 所示。虽然收缩的文字区域对文字实例不在另一 个文字实例的中心区域的这种情况有一定的帮助,但是当文字实例恰好落在另一个文字区域的中心区域时仍然会检测失败。这对于基于分割的场景文字检测算法是一个通用的局限性。
图 7 “文字中的文字”样例
5. 小结
本文介绍的算法提出的可微分二值化模块和动态阈值模块能够让二值化步骤融入到分割网络的联合优化中,既简化了后处理算法,又提升了文字检测的精度。实验表明该方法在 5 个标准数据集上推理速度和检测精度一致地超过了之前领先的方法,在推理速度和检测精度上取得了非常好的平衡。同时,作为一个任意形状文字检测算法, 该方法 可以检测 各种复杂形状的文字,包括多方向、极端长宽比、不规则形状等 。
[45] Shi B, Bai X, Belongie S. Detecting Oriented Text in Natural Images by Linking Segments[C]//Proceedings of the IEEE Computer Society Conference on Computer Vision and Pattern Recognition. 2017: 3482–3490.
[46] Zhou X, Yao C, Wen H, et al. EAST: An Efficient and Accurate Scene Text Detector[C]//Proceedings of the IEEE Computer Society Conference on Computer Vision and Pattern Recognition. 2017: 2642–2651.
[47] Ronneberger O, Fischer P, Brox T. U-Net: Convolutional Networks for Biomedical Image Segmentation[C]//Medical Image Computing and Computer-Assisted Intervention. Springer, Cham, 2015, 9351: 234–241.
[48] Hong S, Roh B, Kim K-H, et al. PVANet: Lightweight Deep Neural Networks for Real-time Object Detection[J]. CoRR, 2016: abs/1611.08588.
[49] Liu Y, Jin L. Deep Matching Prior Network: Toward Tighter Multi-Oriented Text Detection[C]//Proceedings of the IEEE Computer Society Conference on Computer Vision and Pattern Recognition. 2017: 3454–3461.
[50] Jaderberg M, Simonyan K, Vedaldi A, et al. Synthetic Data and Artificial Neural Networks for Natural Scene Text Recognition[J]. CoRR, 2014, abs/1406.2.
[51] Shi B, Bai X, Yao C. An End-to-End Trainable Neural Network for Image-Based Sequence Recognition and Its Application to Scene Text Recognition[J]. IEEE Transactions on Pattern Analysis and Machine Intelligence, 2017, 39(11): 2298–2304.
[52] Graves A, Fernández S, Gomez F, et al. Connectionist Temporal Classification: Labelling Unsegmented Sequence Data with Recurrent Neural Networks[C]//ACM International Conference Proceeding Series. 2006, 148: 369–376.
[53] Shi B, Wang X, Lyu P, et al. Robust Scene Text Recognition with Automatic Rectification[C]//Proceedings of the IEEE Computer Society Conference on Computer Vision and Pattern Recognition. 2016: 4168–4176.
[54] Jaderberg M, Simonyan K, Zisserman A, et al. Spatial Transformer Networks[C]//Advances in Neural Information Processing Systems. 2015: 2017–2025.
[55] Bai F, Cheng Z, Niu Y, et al. Edit probability for scene text recognition[C]//Proceedings of the IEEE Computer Society Conference on Computer Vision and Pattern Recognition. 2018: 1508–1516.
[56] Cheng Z, Xu Y, Bai F, et al. AON: Towards Arbitrarily-Oriented Text Recognition[C]//Proceedings of the IEEE Computer Society Conference on Computer Vision and Pattern Recognition. 2018: 5571–5579.
[57] Neumann L, Matas J. Real-Time Lexicon-Free Scene Text Localization and Recognition[C]//IEEE Transactions on Pattern Analysis and Machine Intelligence. 2016, 38(9): 1872–1885.
[58] Yao C, Bai X, Liu W. A Unified Framework for Multioriented Text Detection and Recognition[J]. IEEE Transactions on Image Processing, IEEE, 2014, 23(11): 4737–4749.
[59] Liao M, Shi B, Bai X, et al. TextBoxes: A Fast Text Detector with a Single Deep Neural Network[C]//Proceedings of the Association for the Advance of Artificial Intelligence. 2017: 4161–4167.
[60] Li H, Wang P, Shen C. Towards End-to-End Text Spotting with Convolutional Recurrent Neural Networks[C]//Proceedings of the IEEE International Conference on Computer Vision. 2017(2): 5248–5256.
[61] Busta M, Neumann L, Matas J. Deep TextSpotter: An End-to-End Trainable Scene Text Localization and Recognition Framework[C]//Proceedings of the IEEE International Conference on Computer Vision. 2017, 2017-Octob: 2223–2231.
[62] He T, Tian Z, Huang W, et al. An End-to-End Textspotter with Explicit Alignment and Attention[C]//Proceedings of the IEEE Computer Society Conference on Computer Vision and Pattern Recognition. 2018: 5020–5029.
[63] Liu X, Liang D, Yan S, et al. FOTS: Fast Oriented Text Spotting with a Unified Network[C]//Proceedings of the IEEE Computer Society Conference on Computer Vision and Pattern Recognition. 2018: 5676–5685.
[64] Veit A, Matera T, Neumann L, et al. COCO-Text: Dataset and Benchmark for Text Detection and Recognition in Natural Images[J]. CoRR, 2016, abs/1601.0.
[65] Lin T Y, Maire M, Belongie S, et al. Microsoft COCO: Common Objects in Context[C]//Proceedings of the European Conference on Computer Vision. 2014: 740–755.
[66] Ch’Ng C K, Chan C S. Total-Text: A Comprehensive Dataset for Scene Text Detection and Recognition[C]//Proceedings of the International Conference on Document Analysis and Recognition. 2017, 1: 935–942.
[67] Liu Y, Jin L, Zhang S, et al. Curved Scene Text Detection via Transverse and Longitudinal Sequence Connection[J]. Pattern Recognition, Elsevier, 2019, 90: 337–345.
[68] Phan T Q, Shivakumara P, Tian S, et al. Recognizing Text with Perspective Distortion in Natural Scenes[C]//Proceedings of the IEEE International Conference on Computer Vision. 2013: 569–576.
[69] Risnumawan A, Shivakumara P, Chan C S, et al. A Robust Arbitrary Text Detection System for Natural Scene Images[J]. Expert Systems with Applications, 2014, 41(18): 8027–8048.
[70] Pan Y F, Hou X, Liu C L. A Hybrid Approach to Detect and Localize Texts in Natural Scene Images[J]. IEEE Transactions on Image Processing, 2011, 20(3): 800–813.
[71] Bai B, Yin F, Liu C L. Scene Text Localization Using Gradient Local Correlation[C]//Proceedings of the International Conference on Document Analysis and Recognition, ICDAR. IEEE, 2013: 1380–1384.
[72] Liu W, Anguelov D, Erhan D, et al. SSD: Single Shot Multibox Detector[C]//Proceedings of the European Conference on Computer Vision. 2016: 21–37.
[73] Girshick R, Donahue J, Darrell T, et al. Rich Feature Hierarchies for Accurate Object Detection and Semantic Segmentation[C]//Proceedings of the IEEE Computer Society Conference on Computer Vision and Pattern Recognition. 2014: 580–587.
[74] Uijlings J R R, Van de Sande K E A, Gevers T, et al. Selective Search for Object Recognition[J]. International Journal of Computer Vision, Springer, 2013, 104(2): 154–171.
[75] Girshick R B. Fast R-CNN[C]//Proceedings of the IEEE International Conference on Computer Vision. 2015: 1440–1448.
[76] Ren S, He K, Girshick R B, et al. Faster R-CNN: Towards Real-Time Object Detection with Region Proposal Networks[C]//Advances in Neural Information Processing Systems. 2015, 39(6): 1–10.
[77] Kingma D P, Ba J L. Adam: A Method for Stochastic Optimization[J]. Proceedings of the International Conference on Learning Representations, 2015.
[78] Tang Y, Wu X. Scene Text Detection and Segmentation Based on Cascaded Convolution Neural Networks[J]. IEEE Transactions on Image Processing, 2017, 26(3): 1509–1520.
[79] Buta M, Neumann L, Matas J. FASText: Efficient Unconstrained Scene Text Detector[C]//Proceedings of the IEEE International Conference on Computer Vision. 2015: 1206–1214.
[80] Zamberletti A, Noce L, Gallo I. Text Localization Based on Fast Feature Pyramids and Multi-Resolution Maximally Stable Extremal Regions[C]//Proceedings of the Asian Conference on Computer Vision Workshops. Springer, Cham, 2015, 2: 91–105.
[81] Lu S, Chen T, Tian S, et al. Scene Text Extraction Based on Edges and Support Vector Regression[J]. International Journal on Document Analysis and Recognition, 2015, 18(2): 125–135.
[82] Tian S, Pan Y, Huang C, et al. Text Flow: A Unified Text Detection System in Natural Scene Images[C]//Proceedings of the IEEE International Conference on Computer Vision. 2015: 4651–4659.
[83] He T, Huang W, Qiao Y, et al. Text-Attentional Convolutional Neural Network for Scene Text Detection[J]. IEEE Transactions on Image Processing, IEEE, 2016, 25(6): 2529–2541.
[84] Qin S, Manduchi R. A Fast and Robust Text Spotter[C]//2016 IEEE Winter Conference on Applications of Computer Vision, WACV 2016. 2016: 1–8.
[85] Yao C, Bai X, Sang N, et al. Scene Text Detection via Holistic, Multi-Channel Prediction[J]. CoRR, 2016, abs/1606.0: 1–10.
[86] Li X, W. W W, Hou W, et al. Shape Robust Text Detection with Progressive Scale Expansion Network[C]//Proceedings of the IEEE Computer Society Conference on Computer Vision and Pattern Recognition. 2019: 9336–9345.
[87] Tian Z, Shu M, Lyu P, et al. Learning Shape-Aware Embedding for Scene Text Detection[C]//Proceedings of the IEEE Computer Society Conference on Computer Vision and Pattern Recognition. 2019: 4229–4238.
[88] He K, Zhang X, Ren S, et al. Deep Residual Learning for Image Recognition[C]//Proceedings of the IEEE Computer Society Conference on Computer Vision and Pattern Recognition. IEEE, 2016: 770–778.
[89] He P, Huang W, He T, et al. Single Shot Text Detector with Regional Attention[C]//Proceedings of the IEEE International Conference on Computer Vision. 2017: 3047–3055.
[90] Liao M, Zhu Z, Shi B, et al. Rotation-Sensitive Regression for Oriented Scene Text Detection[C]//Proceedings of the IEEE Computer Society Conference on Computer Vision and Pattern Recognition. 2018: 5909–5918.
[91] He W, Zhang X Y, Yin F, et al. Deep Direct Regression for Multi-Oriented Scene Text Detection[C]//Proceedings of the IEEE International Conference on Computer Vision. 2017: 745–753.
[92] Xie L, Liu Y, Jin L, et al. DeRPN: Taking a Further Step toward More General Object Detection[C]//Proceedings of the Association for the Advance of Artificial Intelligence. 2019, 33: 9046–9053.
[93] Xue C, Lu S, Zhan F. Accurate Scene Text Detection Through Border Semantics Awareness and Bootstrapping[C]//Proceedings of the European conference on computer vision, ECCV. 2018: 370–387.
[94] Dai J, Qi H, Xiong Y, et al. Deformable Convolutional Networks[C]//Proceedings of the IEEE International Conference on Computer Vision. 2017: 764–773.
[95] Zhu X, Hu H, Lin S, et al. Deformable Convnets V2: More Deformable, Better Results[C]//Proceedings of the IEEE Computer Society Conference on Computer Vision and Pattern Recognition. 2019: 9300–9308.
[96] Vatti B R. A Generic Solution to Polygon Clipping[J]. Communications of the ACM, Association for Computing Machinery, Inc., 1992, 35(7): 56–63.
想了解更多的AI技术干货,欢迎上华为云的AI专区,目前有AI编程Python等六大实战营(http://su.modelarts.club/qQB9)供大家免费学习。
- 点赞
- 收藏
- 关注作者
评论(0)