美文网首页程序员深度学习
人脸检测—Retinanetface

人脸检测—Retinanetface

作者: zidea | 来源:发表于2020-10-13 08:17 被阅读0次
    截屏2020-10-13上午5.24.57.png

    retinaface 人脸检测算法

    甜点

    最近一直了解人脸检测的算法,所以也尝试学多人脸检测框架。所以这里将拿出来和大家分享一下

    Retinaface 与普通的目标检测算法类似,在图片上预先设定好一些先验框,这些先验框会分布在整个图片上,网络内部结构会对这些先验框进行判断看是否包含人脸,同时也会调整位置进行调整并且给每一个先验框的一个置信度。

    在 Retinaface 的先验框不但要获得人脸位置,还需要获得每一个人脸的五个关键点位置

    接下来我们对 Retinaface 执行过程其实就是在图片上预先设定好先验框,网络的预测结果会判断先验框内部是否包含人脸并且对先验框进行调整获得预测框和五个人脸关键点。

    主干特征提取网络

    • mobileNet 和 Resnet
    • 在主干网络(例如 mobileNetv1) 不断进行特征提取,在特征提取过程就是压缩长宽到深度(通道扩张)上过程(下采样)

    mobileNet

    MobileNet 网络是由 google 团队在 2017 年提出的,专注移动端和嵌入式设备中轻量级 CNN 网络,在大大减少模型参数与运算量下,对于精度只是小幅度下降而已。

    加强特征提取网络 FPN 和 SHH

    • FPN 构建就是生成特征图进行融合,通过上采样然后和上一层的有效特征层进行
      retinanet_001.png
    • SSH 的思想非常简单,使用了 3 个并行结构,利用 3 x 3 卷积的堆叠代替 5 x 5 与 7 x 7 卷积的效果,
    retinanet_002.png

    retina head

    在主干网络输出的相当输出了不同大小网格,用于检测不同大小目标,先验框默认数量为 2,这些先验框用于检测目标,然后通过调整得到目标边界框。

    • face classification 用于检测先验框中是否存在人脸。也就是判断先验框内部是否包含目标,利用一个 1 x 1 的卷积,将 SSH 的通道数调整成 num_anchors x 2 ,用于代表每个先验框内部包含人脸的概率, 这里觉得有必要解释一下 2,通常不就是用一个概率来表示先验框存在人脸的概率,而在这里用了两个值来表示人脸是否存在先验框内的概率。其实在两个值中,如果第一个值比较大,就表示有人脸,那么如果第二值比较大,表示没有人脸存在
    • face box regression 用于调整先验框的中心和宽高,用四个参数对先验框进行调整。此时可以利用 1 x 1 的卷积,将 SSH 的通道数调整成 num_anchors x 4 用于表示每个先验框的调整参数
    • facial landmark regression 对先验框进行调整获得人脸关键点,每一个人脸关键点需要两个调整参数,一共有五个人脸关键点。此时利用 1 x 1 的卷积,将 SSH 通道调整成为 num_anchor(num_anchors x 5 x 2) 表示每个先验框的每一个人脸关键点的调整,5 就是人脸上 5 个关键点,这里 2 表示对人脸中心点进行调整的参数。

    FPN

    class FPN(nn.Module):
        def __init__(self,in_channels_list,out_channels):
            super(FPN,self).__init__()
            leaky = 0
            if (out_channels <= 64):
                leaky = 0.1
            
            # 利用 1x1 卷积对获得的3有效特征层进行通道数的调整,输出通道数都为 64
            self.output1 = conv_bn1X1(in_channels_list[0], out_channels, stride = 1, leaky = leaky)
            self.output2 = conv_bn1X1(in_channels_list[1], out_channels, stride = 1, leaky = leaky)
            self.output3 = conv_bn1X1(in_channels_list[2], out_channels, stride = 1, leaky = leaky)
    
            self.merge1 = conv_bn(out_channels, out_channels, leaky = leaky)
            self.merge2 = conv_bn(out_channels, out_channels, leaky = leaky)
    
        def forward(self, input):
            # names = list(input.keys())
            input = list(input.values())
    
            # 
            output1 = self.output1(input[0])
            output2 = self.output2(input[1])
            output3 = self.output3(input[2])
    
            # 对于最小特征层进行上采样来获得 up3
            up3 = F.interpolate(output3, size=[output2.size(2), output2.size(3)], mode="nearest")
            # 然后将最小特征层经过上采用获得结果和中间有效特征层进行相加
            output2 = output2 + up3
            # 进行 64 通道卷积进行特征整合
            output2 = self.merge2(output2)
    
            # 这个步骤和上面类似
            up2 = F.interpolate(output2, size=[output1.size(2), output1.size(3)], mode="nearest")
            output1 = output1 + up2
            output1 = self.merge1(output1)
    
            out = [output1, output2, output3]
            return out
    

    SSH

    class SSH(nn.Module):
        def __init__(self, in_channel, out_channel):
            super(SSH, self).__init__()
            assert out_channel % 4 == 0
            leaky = 0
            if (out_channel <= 64):
                leaky = 0.1
            self.conv3X3 = conv_bn_no_relu(in_channel, out_channel//2, stride=1)
    
            # 用 2 个 3 x 3 的卷积来代替 5 x 5 的卷积
            self.conv5X5_1 = conv_bn(in_channel, out_channel//4, stride=1, leaky = leaky)
            self.conv5X5_2 = conv_bn_no_relu(out_channel//4, out_channel//4, stride=1)
            # 使用 3 个 3 x 3 的卷积来代替 7 x 7 的卷积
            self.conv7X7_2 = conv_bn(out_channel//4, out_channel//4, stride=1, leaky = leaky)
            self.conv7x7_3 = conv_bn_no_relu(out_channel//4, out_channel//4, stride=1)
    
        def forward(self, input):
            conv3X3 = self.conv3X3(input)
    
            conv5X5_1 = self.conv5X5_1(input)
            conv5X5 = self.conv5X5_2(conv5X5_1)
    
            conv7X7_2 = self.conv7X7_2(conv5X5_1)
            conv7X7 = self.conv7x7_3(conv7X7_2)
    
            # 堆叠
            out = torch.cat([conv3X3, conv5X5, conv7X7], dim=1)
            out = F.relu(out)
            return out
    

    先验框调整

    深度可分离卷积(Depthwise separable convolution)

    深度可分离卷积好处就是可以减少参数数量,从而降低运算的成本。经常出现在一些轻量级的网络结构(这些网络结构适合于移动设备或者嵌入式设备),深度可分离卷积是由DW(depthwise)和PW(pointwise)组成

    convolutional_filter.jpg

    这里我们通过对比普通卷积神经网络来解释,深度可分离卷积是如何减少参数

    • 卷积核通道数与输入通道数保持一致
    • 输出通道与卷积核个数保持一致
    DW_PW.jpeg
    DW(Depthwise Conv)

    我们先看图中 DW 部分,在这一个部分每一个卷积核通道数 1 ,每一个卷积核对应一个输入通道进行计算,那么可想而知输出通道数就与卷积核个数以及输入通道数量保持一致。
    简单总结一下有以下两点

    • 卷积核通道数为 1
    • 输入通道数等于卷积核个数等于输出通道数
    PW(Pointwise Conv)

    PW 卷积核核之前普通卷积核类似,只不过 PW 卷积核大小为 1 ,卷积核深度与输入通道数相同,而卷积核个数核输出通道数相同

    常规卷积
    输入 5 \times 5 \times 3
    卷积核 3 \times 3 \times 3 \times 4
    输出 5 \times 5 \times 4
    参数量 108

    普通卷积
    D_k \times D_k \times M \times N \times D_F \times D_F
    深度可分离卷积
    D_k \times D_k \times M \times D_F \times D_F + D_k \times D_k \times N \times D_F \times D_F

    • D_F 表示输入矩阵大小
    • D_K 表示卷积核大小
    • M 表示输入通道数
    • N 表示输出通道数

    \frac{1}{N} + \frac{1}{D_K^2}= \frac{1}{N} + \frac{1}{9}

    kernel_{width} \times kernel_{height} \times kernel_{channel} \times count

    卷积核W \times 卷积核H \times (输入W - 卷积核W + 1) \times (输入H - 卷积核H + 1) \times 输入通道数 \times 输出通道数

    增加两个超参数\alpha\beta

    相关文章

      网友评论

        本文标题:人脸检测—Retinanetface

        本文链接:https://www.haomeiwen.com/subject/yrbmpktx.html