轻量化网络

您所在的位置:网站首页 ghost念什么 轻量化网络

轻量化网络

2024-07-15 07:38| 来源: 网络整理| 查看: 265

Contents 1 Ghost2 Ghost module3 Ghost Bottlenecks:4 GhostNet5 ghostnet中用到的SEblock结构

论文链接:GhostNet: More Features from Cheap Operations 开源地址:https://github.com/huawei-noah/ghostnet

1 Ghost

     Ghost模块是一种实现轻量级神经网络的方法,使得深度神经网络可以在保证算法表现能力的基础上将网络移植到一些计算能力相对较弱的移动设备上(如智能手机等)。整体方向是减少网络模型参数数量及浮点数运算次数(FLOPs)。

     上图是普通的卷积层,将Input经过卷积运算得到Output。      下图是将一张小猫图片输入到ResNet50网络中经过第一个Resdual block后的特征图可视化结果。可以看出其中的有些特征图非常相似,如下图中的红、绿、蓝框,圈出来的这些框就是论文中提到的(the redundancy in feature maps,特征图冗余)。这些相似的特征图可以通过廉价的线性运算互相转换,故下图中的小扳手就是Ghost模块。

     Output的通道数是由参与卷积操作的filter的数量来决定的,这样一来,我们可以减少filter的数量,通过廉价的线性转换同样可以生成类似的结果,从而减少了网络模型参数以及FLOPs,以至于实现模型的轻量化。

2 Ghost module

     上图中intrinsic feature maps是通过普通卷积操作得到的,Ghost模块用于将 intrinsic feature maps 通过一系列廉价的线性转换生成更多的ghost feature maps,生成的这些ghost feature maps可以极大地展示 intrinsic feature maps 中潜在包含的特征信息。

     上图中的这些Φ表示之前所说的廉价的线性转换操作,那么它具体是什么呢? Φ其实是 3×3、5×5大小的内核卷积,因为普通的filter在进行卷积时,filter的通道数与输入的通道数必须保持一致,故相比于普通的filter进行卷积操作,仅仅在一个通道上进行卷积运算,其计算成本极大降低。      从 intrinsic feature maps 生成 ghost feature maps的公式如下:

     其中 yi’表示 intrinsic feature maps 中的第i个特征图,i 表示m个intrinsic feature maps中的序列号,j 表示对于每个intrinsic feature maps中的特征图进行的第 j次线性转换。从上图公式中可以看出,对于 intrinsic feature maps 中的每一个特征图,都可以进行 s-1 次的线性转换(还有一次是上图中的Identity操作),从而Ghost模块将生成(s-1)×m+m=s×m=n个ghost feature maps(假设普通卷积操作的结果是生成 n 个特征图)

class GhostModule(nn.Module): def __init__(self, inp, oup, kernel_size=1, ratio=2, dw_size=3, stride=1, relu=True): super(GhostModule, self).__init__() self.oup = oup init_channels = math.ceil(oup / ratio) # ratio = oup / intrinsic new_channels = init_channels*(ratio-1) self.primary_conv = nn.Sequential( nn.Conv2d(inp, init_channels, kernel_size, stride, kernel_size//2, bias=False), nn.BatchNorm2d(init_channels), nn.ReLU(inplace=True) if relu else nn.Sequential(), ) self.cheap_operation = nn.Sequential( nn.Conv2d(init_channels, new_channels, dw_size, 1, padding=dw_size//2, groups=init_channels, bias=False), # groups 分组卷积 nn.BatchNorm2d(new_channels), nn.ReLU(inplace=True) if relu else nn.Sequential(), ) def forward(self, x): x1 = self.primary_conv(x) x2 = self.cheap_operation(x1) out = torch.cat([x1,x2], dim=1) return out[:,:self.oup,:,:]

     量化衡量引入Ghost的加速比:

     其中d×d表示线性转换的内核卷积的平均大小,公式中d×d与k×k有相同的数量级,故可约去;s



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3