DynamicConv(动态卷积)

DynamicConv(动态卷积)
第一个总结:
动态卷积的目标在于:在网络性能与计算负载中寻求均衡。常规提升网络性能的方法(更宽、更深)往往会导致更高的计算消耗,因此对于高效网络并不友好。
在这里插入图片描述

因而,相比静态卷积,动态卷积具有更强的特征表达能力。
相比静态感知器,动态感知器具有更大的模型。它包含两个额外的计算:(a)注意力权值计算;(2)动态权值融合。尽管如此,这两点额外计算相比感知器的计算量可以忽略:
在这里插入图片描述

Dynamic Convolution
类似于动态感知器,动态卷积同样具有K个核。按照CNN中的经典设计,作者在动态卷积后接BatchNorm与ReLU。
在这里插入图片描述在这里插入图片描述

SENet的不同之处在于:SENet为通道赋予注意力机制,而动态卷积为卷积核赋予注意力机制。
核集成:由于核比较小,故而核集成过程是计算高效的。下表给出了动态卷积与静态卷积的计算量对比。从中可以看到:计算量提升非常有限。
在这里插入图片描述

动态CNN:动态卷积可以轻易的嵌入替换现有网络架构的卷积,比如1x1卷积, 3x3卷积,组卷积以及深度卷积。与此同时,它与其他技术(如SE、ReLU6、Mish等)存在互补关系。
为注意力的稀疏使得仅有部分核得到训练,这使得训练低效。这种低效会随着网络的加深而变得更为严重。为验证该问题,作者在DY-MobileNetV2变种模型(它仅在每个模块的最后1x1卷积替换为动态卷积)上进行了验证。
作者提出采用平滑注意力方式促使更多卷积核同时优化。该平滑过程描述如下:改进的训练机制可以收敛更快,精度更高。
在这里插入图片描述

结论
作者在ImageNet数据集上对所提方法的有效性进行了验证。对标模型包含MobileNetV2/V3,ResNet等。动态卷积中的核数目K设置为4,注意力权值归一化因子。整体实验对比结果如下所示,可以看到:动态卷积可以一致性得到性能提升,而计算量增加仅为4%。DY-ResNet可以得到2.3%的性能提升,DY-MobileNetV2可以得到2.4%的性能提升,DY-MobileNetV3-small可以得到2.3%的性能提升。
在这里插入图片描述

作者对动态卷积的期望属性为:(1)每层的动态卷积具有灵活性;(2)注意力机制与输入有关。对于第一个属性(如果不具有灵活性,那么不同的注意力会导致相似的性能,而实际上差异非常大),作者采用了不同的注意力进行验证,性能对比见下表。
在这里插入图片描述

Conclusion
作者引入一种动态卷积,它可以自适应根据输入融合多个卷积核。相比于静态卷积,动态卷积可以明显的提升模型表达能力与性能,这有助于高效CNN架构设计。该动态卷积具有“即插即用”特性,可以轻易嵌入到现有网络架构中。
第二个总结:
动态卷积中的 Attention 模块来源于 SENet[13] 网络, 它可以自动学习到不同通道特征的重要程度, 生成对应的权重, 这相当于一种注意力机制.
与 SENet 不同的是, 动态卷积处理的对象是卷积核, 按权重相加, 而后者是处理特征图, 对每个特征图乘上一个权重。
方法
在这里插入图片描述在这里插入图片描述
聚合的意思是将 K个卷积核根据权重πk(x)按元素求和,得到处理后的卷积核 W˜,b 由于πk(x)的生成是非线性的,所以动态卷积具有更强的表达能力。
在这里插入图片描述
第三个总结:
轻量级卷积神经网络(CNNs)由于其较低的计算预算限制了CNNs的深度(卷积层的数量)和宽度(通道的数量),导致其性能下降,从而限制了其表示能力。为了解决这个问题,我们提出了动态卷积,一种新的设计,在不增加网络深度或宽度的情况下增加模型的复杂性。动态卷积不是每层使用一个卷积核,而是根据多个并行卷积核的注意力动态地聚集在一起,这些卷积核是依赖于输入的。多核的装配不仅由于核的尺寸小而具有较高的计算效率,而且由于这些核是通过注意力以非线性的方式进行聚合而具有更强的表示能力。通过简单地使用动态卷积的最新架构MobilenetV3-Small,在ImageNet分类中排名前1的精度提高了2.3%,仅增加了4%的错误,而在COCO keypoint检测中实现了2.9 AP增益。

参考链接:https://blog.csdn.net/weixin_42096202/article/details/103494599

### DynamicConv in Neural Networks Architecture and Implementation DynamicConv, also known as dynamic convolution or deformable convolutions, represents an advanced technique designed to enhance the flexibility of convolutional layers within neural networks. Traditional convolution operations apply fixed kernels over input features, whereas DynamicConv allows these kernels' positions to adapt dynamically based on learned offsets. In terms of architecture design, DynamicConv introduces additional parameters that control how each kernel moves across spatial dimensions during feature extraction[^2]. This approach enables models to better capture geometric transformations present in data without requiring explicit augmentation techniques. For instance, when applied to image processing tasks such as object detection or segmentation, this mechanism can improve performance by accommodating variations like scale changes, rotations, and translations more effectively than standard methods do. For implementation purposes, integrating DynamicConv into existing frameworks typically involves modifying conventional convolution implementations so they support offset predictions alongside regular weight updates. A common practice includes adding extra branches responsible for generating per-pixel displacement vectors which guide where filters should focus their attention next while maintaining computational efficiency through efficient algorithms and hardware acceleration options provided by modern libraries. An example code snippet demonstrating part of a PyTorch-based DynamicConv layer could look something like: ```python import torch.nn.functional as F from torch import nn class DynamicConv(nn.Module): def __init__(self, in_channels, out_channels, kernel_size=3, stride=1, padding=1): super(DynamicConv, self).__init__() self.offset_conv = nn.Conv2d(in_channels=in_channels, out_channels=kernel_size * kernel_size * 2, # 2 coordinates per point kernel_size=kernel_size, stride=stride, padding=padding) self.regular_conv = nn.Conv2d(in_channels=in_channels, out_channels=out_channels, kernel_size=kernel_size, stride=stride, padding=padding) def forward(self, x): offset = self.offset_conv(x) output = F.grid_sample(input=x, grid=self._generate_grid(offset), align_corners=True) return self.regular_conv(output) @staticmethod def _generate_grid(offsets): batch_size, _, height, width = offsets.size() y_range = torch.linspace(-1, 1, steps=height).view(1, -1, 1, 1).expand(batch_size, -1, width, 1) x_range = torch.linspace(-1, 1, steps=width).view(1, 1, -1, 1).expand(batch_size, height, -1, 1) base_grid = torch.cat([x_range, y_range], dim=-1).to(offsets.device) return (base_grid + offsets.permute(0, 2, 3, 1)).contiguous() ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值