-
针对小目标人脸特征较少,以及在图像获取中因采集设备等因素导致的图片精度不高的小目标难以检测的问题,提出基于S3FD网络结构的人脸检测方法。采用VGG16网络作为检测主体,强化针对人脸的特征提取力,引入CBAM注意力机制建立时间和空间的依赖关系;使用RFB来获得较大的感受野,让网络结构对目标图片的感受野扩大从而能获得更多的信息,而且在此基础之上还使用FPN网络结构,使得网络结构在不同尺度下都可以扩大感受野和在不大量增加额外参数量的情况之下网络能够保留更多的图像细节特征。基于S3FD网络结构的人脸检测算法模型S3FD-CBAM-RFB如图 1所示,其中conv表示卷积层,convfc表示全连接层,up表示上采样过程。
-
RFB网络模块是2018年由LIU等人[27]提出,仿照人类的视觉增大在神经网络训练中的感受野,从而获得更多的信息提高检测效果。RFB由不同尺寸卷积核的卷积层构成多分支结构, 类似于SZEGEDY等人在2014年提出的inception结构[28],并在此基础之上加入空洞卷积层,使得RFB的感受野进一步扩大, 获取的特征信息更多,如图 2所示。
在RFB的基础之上LIU等人还改进出RFB-s,RFB-s于RFB相比主要存在两个方面的改进,一方面是将3×3的卷积层代替5×5的卷积层,另一方面是将3×3的卷积层改换为1×3和3×1卷积层,主要目的应该是减少计算量,RFB-s网络结构如图 3所示。
-
CBAM是由WOO等人[25]在2018年提出的网络结构,目的是对训练过程中的特征进行干预,将更多训练时的注意力分配到更能够区分图片特征的地方。CBAM与BA等人[29]提出的注意力机制不同,其中包含通道注意力机制和空间注意力机制,CBAM总体结构如图 4所示。
特征图F在通道注意力中计算过程如下式所示:
$ \begin{array}{c} {\mathit{M}_{\rm{c}}}(\mathit{\boldsymbol{F}}) = \\ \mathit{\sigma }{\rm{(MLP(avgpool(}}\mathit{\boldsymbol{F}}{\rm{))}}\;{\rm{ + }}\;{\rm{MLP(maxpool(}}\mathit{\boldsymbol{F}}{\rm{))}} \end{array} $
(1) 式中,Mc(F)表示经过通道注意力后的特征图,avgpool和maxpool分别表示均值池化和最大值池化运算。(1)式经过计算后得到下式:
$ \begin{array}{c} {\mathit{M}_{\rm{c}}}(\mathit{\boldsymbol{F}}) = \mathit{\sigma }({\mathit{W}_1}({\mathit{W}_0}({\mathit{\boldsymbol{F}}_{{\rm{c, avg}}}})) + {\mathit{W}_1}({\mathit{W}_0}({\mathit{\boldsymbol{F}}_{{\rm{c, max}}}}))), \\ ({\mathit{W}_0} \in {\mathit{R}^{\mathit{C}/\mathit{r} \times \mathit{C}}}, {\mathit{W}_1} \in {\mathit{R}^{\mathit{C} \times \mathit{C}/\mathit{r}}}) \end{array} $
(2) 式中,σ为sigmoid操作,r表示减少率,C表示通道数,R表示下降率,Fc, avg, Fc, max以及Fs, avg, Fs, max表示特征图F分别在通道注意力和空间注意力两个模块中经过均值池化和最大值池化后的特征图。W0, W1是多层感知器(multi-layer perceptron,MLP)运算中的权重,共享输入和W0的线性整流函数(rectified linear unit, ReLU)激活函数。通道注意力产生的特征图通过空间注意力的过程如下所示:
$ \begin{array}{c} {\mathit{M}_{\rm{s}}}(\mathit{\boldsymbol{F}}) = \\ \mathit{\sigma }({\mathit{f}_{7 \times 7}}(\left[ {{\rm{avgpool}}(\mathit{\boldsymbol{F}}){\bf{;}}{\rm{maxpool}}(\mathit{\boldsymbol{F}})} \right])) \end{array} $
(3) $ {\mathit{M}_{\rm{s}}}(\mathit{\boldsymbol{F}}) = \mathit{\sigma }({\mathit{f}_{7 \times 7}}({\mathit{\boldsymbol{F}}_{{\rm{s, avg}}}}{\bf{;}}{\mathit{\boldsymbol{F}}_{{\rm{s, max}}}})) $
(4) 式中,Ms(F)表示通过空间注意力之后的特征图,f7×7表示卷积核大小为7×7的卷积层。
-
数据集采用widerface数据集[30],widerface数据集分为easy,medium和hard 3种不同难度的图像,widerface数据集包含32203个图像,其中有393703个人脸,而这些人脸在尺度、姿态、遮挡方面都有很大的变化范围,存在大量的小目标人脸。本模型使用widerface数据集中的训练集作为模型的训练集,验证集作为最后模型检测的测试集。widerface数据集如图 5所示,在实验中将widerface数据集的图像进行颜色扭曲,将图片裁剪到640×640大小, 且以0.5的概率进行左右翻转进行数据增强。
-
本文中的模型是采取pytorch框架进行实现,实验平台是基于系统Ubuntu18.04,GPU为TeslaV100。实验中的训练迭代次数为300次,学习率是跟随着迭代次数的不断进行而逐渐减小的,从初始学习率0.001~ 0.00001变化3次,实验中批次样本数设置为18,优化器选择随机梯度下降法(stochastic gradient descent,SGD)。
-
为了评价人脸检测性能,本文中主要采取精准率-召回率(precision-recall,PR)曲线来进行评价,精准率P指在以预测成为正样本的结果中实际为正样本的概率,召回率R指在实际上应为正样本的样本被预测成为正样本的概率。在预测的结果中预测为正样本的且与实际相符的样本数用真正例Tp表示,在预测的结果中预测为负样本的且与实际相符的样本数用假正例Fp表示;相反,在某一类中预测为正样本但与实际不符则用假负例Fn表示,预测为负样本且与实际相符则用真负例Tn表示。PR曲线所覆盖的面积称为平均精准率(average precision,AP),AP值越高则分类器的效果越好,其计算方式是将PR曲线所覆盖的面积分解成矩形进行计算面积。准确率P和召回率R的计算公式如下所示:
$ \mathit{P} = \frac{{{\mathit{T}_{\rm{p}}}}}{{{\mathit{T}_{\rm{p}}} + {\mathit{F}_{\rm{p}}}}} $
(5) $ R = \frac{{{\mathit{T}_{\rm{p}}}}}{{{\mathit{T}_{\rm{p}}} + {\mathit{F}_{\rm{n}}}}} $
(6) -
本文中损失函数分为两部分,分类损失选用交叉熵损失,用于判断分类类别是否准确,如下式所示:
$ \begin{array}{c} \mathit{L} = \frac{1}{\mathit{N}}\sum\limits_\mathit{i} {{\mathit{L}_\mathit{i}} = \frac{1}{\mathit{N}}} \sum\limits_\mathit{i} - \left[ {{\mathit{y}_\mathit{i}} \times {\rm{ln}}\;{\mathit{p}_\mathit{i}}} \right. +\\ \left. {(1 - {\mathit{y}_\mathit{i}}) \times {\rm{ln}}(1 - {\mathit{p}_\mathit{i}})} \right] \end{array} $
(7) 式中,L表示交叉熵损失的值,N表示样本总数,i表示第几个样本,Li表示每一个样本的损失,yi表示样本i的标签,pi表示样本i预测为正的概率,选取平滑最小绝对值偏差损失L1来判断当前锚点是否合适,回归损失SL1如下式所示:
$ {\mathit{S}_{{\mathit{L}_1}}}(\mathit{x}) = \left\{ {\begin{array}{*{20}{l}} {0.5{\mathit{x}^2}, (\left| \mathit{x} \right| < 1)}\\ {\left| \mathit{x} \right| - 0.5, ({\rm{otherwise}})} \end{array}} \right. $
(8) 式中,x表示预测框与真实值之间的差异。
-
S3FD-CBAM结构是在VGG16网络与extra conversion结构连接处添加CBAM结构以此来调整空间和通道的特征比重,如图 6所示。S3FD-double-stage-max则是在原有双通路基础上全面加入max-out结构使得负样本比例减少,如图 7所示。S3FD-double-stage结构是在原本S3FD-CBAM的基础上,将输入变为双通道,一条为VGG16, 另一条是由RFB模块构成,利用两条不同的网络结构来构建不同的特征图,然后进行叠加使网络整体能够获得的特征变多,如图 8所示。图 7与图 8中的concat表示为数据的拼接,S3FD-CBAM-RFB结构如图 1所示。
-
3种不同结构网络在widerface数据集上的表现如图 9所示。图 9a表示4种不同网络结构在easy难度数据集下的模型表现,图 9b表示4种不同网络结构在medium难度下的模型表现,图 9c表示4种不同网络结构在hard难度下的模型表现情况。
通过图 9和表 1可以看出, S3FD-CBAM-RFB在widerface数据集上的表现在3个不同难度的分类都有一定程度的提高,S3FD-CBAM网络结构体现出CBAM在网络结构中的正向作用,使得网络精确度在3种不同难度下均有了一定程度的提高,在此基础之上将此网络结构修改为以RFB为第2条通路的双通路网络结构,但由于此结构无法减少在卷积过程中对小目标特征信息的丢失,所以效果反而有一定程度的下降,S3FD-CBAM-RFB则是仿照FPN网络模块,将FPN中的卷积层变为RFB之后进行上采样,在使用RFB扩充感受野的同时将小目标的信息尽可能地保留,使得在人脸预测上S3FD-CBAM-RFB的结果有了一定程度的提高,但是在难度较高且人脸数量较多的hard难度下的图像中该网络结构没有在S3FD-CBAM原有的基础上改善。本文中的模型在widerface数据集的检测效果如图 10所示。正如图 10a~图 10d中所示,本文中算法对小型、密集、难度较大的人脸检测效果较好,但是图 10b中有部分人脸由于人脸角度以及人脸遮挡导致存在漏检情况,图 10e中存在一定的误检,将原本的手检测成为人脸,主要原因是图片本身在较远的部分相对模糊,所以将手误检成为人脸。
Table 1. Results of three methods
methods AP/% easy medium hard S3FD 93.7 92.5 85.9 S3FD-CBAM 93.8 92.7 86.4 S3FD-double-stage 92.9 91.3 82.1 S3FD-double-stage-max 92.8 91.1 82.6 S3FD-CBAM-RFBNet 95.0 93.7 86.4 -
为了说明本文中方法的有效性,选取了在widerface数据集上的其它方法进行比较,如表 2所示。IS3FD和IS3FD-fast这两种网络结构[31]与本文中模型是同种数据集且是同种骨干网络模型S3FD,IS3FD是采取上下文特征关系,采取局部特征金字塔网络(local feature pyramid networks, LFPN)以及将max-out扩展至所有特征预测层,IS3FD-fast是将激活函数改用ReLU的变形函数CRelU,将本文方法以及上述两种方法与原网络S3FD进行比较,从表 2可以看出, 本文中方法在hard难度下AP值介于IS3FD和IS3FD-fast两者之间,但是优于S3FD,在easy以及medium两个难度下本文算法均优于其它3种同类型的算法,与原S3FD相比分别提高了1.3%,1.2%,0.5%。
Table 2. Comparison of face detection results with the relevant methods
本文中算法在3种不同难度下的人脸检测中均优于WANG等人[32]和ZHU等人所提出的算法,主要在于扩大了特征图在网络中的感受野以及加入注意力机制使得通道和空间的权重对结果产生影响。图 11所示是本文中算法在视频流检测效果。图 11a表示在简单情况下检测效果,图 11b表示在复杂情况下的检测效果。综上所述,本文中模型在widerface数据集上表现出相对较高的准确率和相对较少的运算成本和时间成本。
基于改进S3FD网络的人脸检测算法
Face detection algorithm based on improved S3FD network
-
摘要: 为了解决人脸检测存在小目标人脸携带的特征信息少且相对较为模糊,导致检测难度较高的问题,采用将尺度不变人脸检测器(S3FD)网络与通道和空间注意力机制相结合的网络作为主干,在通道和空间上建立了特征之间的权重关系,强化特征提取能力,将原本S3FD所输出的特征图经扩大感受野后进行上采样,使得上一层特征图的输出包含了下一层特征图的特征。结果表明, widerface数据集的3个不同等级的验证集的平均精准率分别为95.0%,93.7%,86.4%,与原S3FD相比分别提高了1.3%,1.2%,0.5%。本文中提出的算法在人脸检测中具有较好的检测效果。Abstract: In face detection, the small target face carries less feature information and is relatively fuzzy, which leads to higher detection difficulty. In order to solve this problem, a novel algorithm was designed. The network that combines the single shot scale-invariant face detector (S3FD) network with the channel and the spatial attention mechanism was used as the backbone, and the channel and the spatial establish the weight relationship between the features, which strengthens the feature extraction ability. Then, the receptive field of the original S3FD output feature map was expanded and then up-sampled, so that the output of the feature map of the previous layer includes the features of the feature map of the next layer. Result: The average precision (AP) values of this algorithm on the three different levels of widerface verification datasets are 95.0%, 93.7%, and 86.4%, respectively, which are increased by 1.3%, 1.2%, and 0.5% compared with the original S3FD. The algorithm proposed in this paper has a better detection effect in face detection.
-
Key words:
- image processing /
- face detection /
- small target /
- attention mechanism /
- deep learning
-
Table 1. Results of three methods
methods AP/% easy medium hard S3FD 93.7 92.5 85.9 S3FD-CBAM 93.8 92.7 86.4 S3FD-double-stage 92.9 91.3 82.1 S3FD-double-stage-max 92.8 91.1 82.6 S3FD-CBAM-RFBNet 95.0 93.7 86.4 -
[1] ROWLEY H A, BALUJA S, KANADE T. Neural network-based face detection[J]. IEEE Transactions on Pattern Analysis & Machine Intelligence, 2002, 20(1): 23-38. [2] ROWLEY H A, BALUJA S, KANADE T. Rotation invariant neural network-based face detection[C]// Computer Vision and Pattern Recognition. New York, USA: IEEE, 1998: 38-44. [3] VIOLA P, JONES M J. Robust real-time face detection[J]. International Journal of Computer Vision, 2004, 57(2): 137-154. doi: 10.1023/B:VISI.0000013087.49260.fb [4] MATHIAS M, BENENSON R, PEDERSOLI M, et al. Face detection without bells and whistles[C]// European Conference on Computer Vision. Zurich, Switzerland: ECCV, 2014: 720- 735. [5] YAN J, LEI Z, WEN L, et al. The fastest deformable part model for object detection[C]//Computer Vision and Pattern Recognition. New York, USA: IEEE, 2014: 2497-2504. [6] ZHU X, RAMANAN D. Face detection, pose estimation, and landmark localization in the wild[C]//Computer Vision and Pattern Re-cognition. New York, USA: IEEE, 2012: 2879-2886. [7] KRIZHEVSKY A, SUTSKEVER I, HINTON G, et al. ImageNet classification with deep convolutional neural networks ImageNet classification with deep convolutional neural networks[J]. Communications of the ACM, 2017, 60(6): 84-90. doi: 10.1145/3065386 [8] LEI H L, ZHANG B H. Crowd count algorithm based on multi-model deep convolution network integration[J]. Laser Technology, 2019, 43(4): 476-481(in Chinese). [9] CHEN Q X, WU W Ch, ASKAR H. Detection algorithm based on multi-scale spotted target modeling[J]. Laser Technology, 2020, 44(4): 520-524(in Chinese). [10] LI H, LIN Z, SHEN X, et al. A convolutional neural network cascade for face detection[C]// Computer Vision and Pattern Recognition. New York, USA: IEEE, 2015: 5325-5334. [11] QIN H, YAN J, LI X, et al. Joint training of cascaded CNN for face detection[C]// Computer Vision and Pattern Recognition. New York, USA: IEEE, 2016: 3456-3465. [12] YANG S, LUO P, LOY C C, et al. From facial parts responses to face detection: A deep learning approach[C]//International Confe-rence on Computer Vision. New York, USA: IEEE, 2015: 3676-3684. [13] ZHANG K, ZHANG Z, LI Z, et al. Joint face detection and alignment using multitask cascaded convolutional networks[J]. IEEE Signal Processing Letters, 2016, 23(10): 1499-1503. doi: 10.1109/LSP.2016.2603342 [14] JIANG H, LEARNED-MILLER E. Face detection with the faster R-CNN[C]//Automatic Face and Gesture Recognition. New York, USA: IEEE, 2017: 650-657. [15] REN S, HE K, GIRSHICK R, et al. Faster R-CNN: Towards real-time object detection with region proposal networks[J]. IEEE Transactions on Pattern Analysis & Machine Intelligence, 2017, 39(6): 1137-1149. [16] ZHU C, ZHENG Y, LUU K, et al. CMS-RCNN: Contextual multi-scale region-based CNN for unconstrained face detection[EB/OL]. (2016-06-16)[2020-12-22]. https://arxiv.org/pdf/1606.05413.pdf. [17] WAN S, CHEN Z, ZHANG T, et al. Bootstrapping face detection with hard negative examples[EB/OL]. (2016-08-07)[2020-12-22]. https://arxiv.org/pdf/1608.02236.pdf. [18] ZHANG S, ZHU X, LEI Z, et al. S3fd: Single shot scale-invariant face detector[C]//International Conference on Computer Vision. New York, USA: IEEE, 2017: 192-201. [19] LIU W, ANGUELOV D, ERHAN D, et al. SSD: Single shot multibox detector[C]// European Conference on Computer Vision. Amsterdam, The Netherlands: Springer International Publishing, 2016: 21-37. [20] ZHU C, TAO R, LUU K, et al. Seeing small faces from robust anchor's perspective[C]// Computer Vision and Pattern Recognition. New York, USA: IEEE, 2018: 5127-5136. [21] LI J, WANG Y, WANG C, et al. DSFD: Dual shot face detector[C]// Computer Vision and Pattern Recognition. New York, USA: IEEE, 2019: 5055-5064. [22] GU Y, LU X Q, YANG L D, et al. Automatic lung nodule detection using a 3D deep convolutional neural network combined with a multi-scale prediction strategy in chest CTs[J]. Computers in Biology and Medicine, 2018, 103: 220-231. doi: 10.1016/j.compbiomed.2018.10.011 [23] LI Z, TANG X, HAN J, et al. PyramidBox+ +: High performance detector for finding tiny face[EB/OL]. (2019-08-07)[2020-12-22]. https://arxiv.org/pdf/1904.00386.pdf. [24] SIMONYAN K, ZISSERMAN A. Very deep convolutional networks for large-scale image recognition[EB/OL]. (2015-04-10)[2020-12-22]. https://arxiv.org/pdf/1409.1556.pdf. [25] WOO S, PARK J, LEE J Y, et al. CBAM: Convolutional block attention module[C]// European Conference on Computer Vision. Munich, Germany: ECCV, 2018: 3-19. [26] LIN T Y, DOLLAR P, GIRSHICK R, et al. Feature pyramid networks for object detection[C]//Computer Vision and Pattern Recognition. New York, USA: IEEE, 2017: 936-944. [27] LIU S, HUANG D, WANG Y. Receptive field block net for accurate and fast object detection[J]. Lecture Notes in Computer Science, 2018, 11215: 404-419. [28] SZEGEDY C, LIU W, JIA Y, et al. Going deeper with convolutions[C]//Computer Vision and Pattern Recognition. New York, USA: IEEE, 2014: 1-9. [29] BA J, MNIH V, KAVUKCUOGLU K. Multiple object recognition with visual attention[EB/OL]. (2015-04-23)[2020-12-22]. https://arxiv.org/pdf/1412.7755.pdf. [30] YANG S, LUO P, LOY C C, et al. Wider face: A face detection benchmark[C]// Computer Vision and Pattern Recognition. New York, USA: IEEE, 2016: 5525-5533. [31] ZHANG H Sh. Research on key algorithms of face detection and face recognition in video surveillance[D]. Chengdu: University of Electronic Science and Technology of China, 2019: 11-48(in Chinese). [32] WANG M, SU H S, LIU G H, et al. Classroom face detection algorithm based on convolutional neural network[J]. Laser & Optoelectronics Progress, 2019, 56(21): 211501(in Chinese).