仅调整5%的骨干网络参数,就能超越全参数微调效果?!
还是在实例分割、目标检测、旋转目标检测这样的经典视觉任务场景。
这是来自清华、国科大、上海交大、阿里巴巴的一项研究,相关论文已被CVPR2025接受。
他们提出了Mona(Multi-cognitive Visual Adapter)这种新型视觉适配器微调方法,目标是打破传统全参数微调(full fine-tuning)在视觉识别任务中的性能瓶颈。
Mona方法通过引入多认知视觉滤波器和优化输入分布,仅调整5%的骨干网络参数,就能在实例分割、目标检测、旋转目标检测等多个经典视觉任务中超越全参数微调的效果。
这一方法显著降低了适配和存储成本,为视觉模型的高效微调提供了新的思路。
Mona首次突破了全量微调性能枷锁
随着现代深度学习的发展,训练数据和模型规模的增加成为模型性能的重要增长点,但随之而来的是模型的垂直应用和微调成本和难度的提升。
传统全量微调需要更新模型所有参数(如GPT-3的1750亿参数 ),计算成本极高。即使以早期的BERT为例,单卡训练100万数据也需5-7小时,对硬件资源和时间的要求限制了研究复现和实际应用。
同时,随着模型参数从亿级迈向万亿级,直接微调不仅成本高昂,还可能因过拟合导致性能下降。此外,多任务场景下需为每个任务保存完整模型副本,存储成本剧增加。
参数高效微调(Parameter Efficient Fine-Tuning,PEFT)通过保持预训练模型参数冻结,仅调整少量参数就可实现大模型在垂直应用领域的高效适配。
但目前大多数PEFT方法,尤其是视觉领域的PEFT方法的性能相较于全量微调而言还存在劣势。
Mona通过更适合视觉信号处理的设计以及对预训练特征分布的动态优化,在小于5%的参数成本下首次突破了全量微调的性能枷锁,为视觉微调提供了新的解决方案。
团队核心想通过研究强调:
(1)PEFT对于视觉模型性能上限的提升(尤其是参数量较大的模型);(2)视觉模型在全微调(尤其是少样本情况)会存在严重的过拟合问题;(3)1LVM+nAdapter模式在实际业务中潜在的性能和效率优势。
对于具体业务来说,有些用到LVM或者多模态大模型(如OCR等任务)的任务会对视觉编码器部分进行固定或仅微调linear层来适应下游数据。
Mona的存在理论上可以进一步提升LVM、多模态大模型对视觉特征的理解和重构,尤其是对于一些少样本post-training问题。
核心引入多认知视觉滤波器
Mona包含降维、多认知视觉滤波器、激活函数和升维等模块,并在适配器内部加入了跳跃连接(Skip-Connections),以增强模型的适应能力。
这种结构设计使得Mona能够在保持高效的同时,显著提升视觉任务的性能。
Mona方法的核心在于引入了多认知视觉滤波器,这些滤波器通过深度可分离卷积(Depth-Wise Convolution)和多尺度卷积核(3×3、5×5、7×7)来增强适配器对视觉信号的处理能力。
与传统的线性适配器不同,Mona专门针对视觉任务设计,能够更好地处理二维视觉特征,通过多尺度特征融合提升模型对视觉信息的理解能力。
另外,Mona在适配器的前端加入了分布适配层(Scaled LayerNorm),用于调整输入特征的分布。
这种设计能够优化从固定层传递过来的特征分布,使其更适合适配器的处理,从而提高微调效率。
实验结果
先来看实验设置。
论文在多个代表性视觉任务上进行了实验,包括:
- 实例分割(COCO)
- 语义分割(ADE20K)
- 目标检测(Pascal VOC)
- 旋转目标检测(DOTA/STAR)
- 图像分类(Flowers102、Oxford-IIIT Pet、VOC2007)
实验使用了SwinTransformer系列作为骨干网络,并基于ImageNet-22k数据集进行预训练。
实验结果显示,在COCO数据集上,Mona方法相比全参数微调提升了1%的mAP,仅调整了不到5%的参数。
在ADE20K数据集上,Mona提升了0.18%的mIoU,表现出色。
同时,在Pascal VOC数据集上,Mona提升了3.6%的APbox,显示出显著的性能提升。
在旋转目标检测任务(DOTA/STAR)中,Mona在多个框架下均优于其他方法。
在图像分类任务上,Mona也有不俗的性能。
在所有方法中, Mona收敛速度更快,并且明显超过了全微调。
以下为Mona即插即用模块:
复制import torch.nn asnn importtorch.nn.functionalasF # ------------------------------Mona模块------------------------------ INNER_DIM = 64 class MonaOp(nn.Module): def __init__(self, in_features): super().__init__() self.conv1 = nn.Conv2d(in_features, in_features, kernel_size=3, padding=3 // 2, groups=in_features) self.conv2 = nn.Conv2d(in_features, in_features, kernel_size=5, padding=5 // 2, groups=in_features) self.conv3 = nn.Conv2d(in_features, in_features, kernel_size=7, padding=7 // 2, groups=in_features) self.projector = nn.Conv2d(in_features, in_features, kernel_size=1, ) def forward(self, x): identity = x conv1_x = self.conv1(x) conv2_x = self.conv2(x) conv3_x = self.conv3(x) x = (conv1_x + conv2_x + conv3_x) / 3.0 + identity identity = x x = self.projector(x) return identity + x class Mona(BaseModule): def __init__(self, in_dim, factor=4): super().__init__() self.project1 = nn.Linear(in_dim, INNER_DIM) self.nonlinear = F.gelu self.project2 = nn.Linear(INNER_DIM, in_dim) self.dropout = nn.Dropout(p=0.1) self.adapter_conv = MonaOp(INNER_DIM) self.norm = nn.LayerNorm(in_dim) self.gamma = nn.Parameter(torch.ones(in_dim) * 1e-6) self.gammax = nn.Parameter(torch.ones(in_dim)) def forward(self, x, hw_shapes=None): identity = x x = self.norm(x) * self.gamma + x * self.gammax project1 = self.project1(x) b, n, c = project1.shape h, w = hw_shapes project1 = project1.reshape(b, h, w, c).permute(0, 3, 1, 2) project1 = self.adapter_conv(project1) project1 = project1.permute(0, 2, 3, 1).reshape(b, n, c) nonlinear = self.nonlinear(project1) nonlinear = self.dropout(nonlinear) project2 = self.project2(nonlinear) return identity + project2 #------------------------------插入模式------------------------------ #此处省略部分 Swin组件实现,仅提供 Mona插入模式。 class SwinBlock(BaseModule): """" Args: embed_dims (int): The feature dimension. num_heads (int): Parallel attention heads. feedforward_channels (int): The hidden dimension for FFNs. window_size (int, optional): The local window scale. Default: 7. shift (bool, optional): whether to shift window or not. Default False. qkv_bias (bool, optional): enable bias for qkv if True. Default: True. qk_scale (float | None, optional): Override default qk scale of head_dim ** -0.5 if set. Default: None. drop_rate (float, optional): Dropout rate. Default: 0. attn_drop_rate (float, optional): Attention dropout rate. Default: 0. drop_path_rate (float, optional): Stochastic depth rate. Default: 0. act_cfg (dict, optional): The config dict of activation function. Default: dict(type='GELU'). norm_cfg (dict, optional): The config dict of normalization. Default: dict(type='LN'). with_cp (bool, optional): Use checkpoint or not. Using checkpoint will save some memory while slowing down the training speed. Default: False. init_cfg (dict | list | None, optional): The init config. Default: None. """ def __init__(self, embed_dims, num_heads, feedforward_channels, window_size=7, shift=False, qkv_bias=True, qk_scale=None, drop_rate=0., attn_drop_rate=0., drop_path_rate=0., act_cfg=dict(type='GELU'), norm_cfg=dict(type='LN'), with_cp=False, init_cfg=None): super(SwinBlock, self).__init__() self.init_cfg = init_cfg self.with_cp = with_cp self.norm1 = build_norm_layer(norm_cfg, embed_dims)[1] self.attn = ShiftWindowMSA( embed_dims=embed_dims, num_heads=num_heads, window_size=window_size, shift_size=window_size // 2 if shift else 0, qkv_bias=qkv_bias, qk_scale=qk_scale, attn_drop_rate=attn_drop_rate, proj_drop_rate=drop_rate, dropout_layer=dict(type='DropPath', drop_prob=drop_path_rate), init_cfg=None) self.norm2 = build_norm_layer(norm_cfg, embed_dims)[1] self.ffn = FFN( embed_dims=embed_dims, feedforward_channels=feedforward_channels, num_fcs=2, ffn_drop=drop_rate, dropout_layer=dict(type='DropPath', drop_prob=drop_path_rate), act_cfg=act_cfg, add_identity=True, init_cfg=None) self.mona1 = Mona(embed_dims, 8) self.mona2 = Mona(embed_dims, 8) def forward(self, x, hw_shape): def _inner_forward(x): identity = x x = self.norm1(x) x = self.attn(x, hw_shape) x = x + identity x = self.mona1(x, hw_shape) identity = x x = self.norm2(x) x = self.ffn(x, identity=identity) x = self.mona2(x, hw_shape) return x if self.with_cp and x.requires_grad: x = cp.checkpoint(_inner_forward, x) else: x = _inner_forward(x) return x
最后小结一下,Mona方法通过多认知视觉滤波器和输入优化,显著提升了视觉任务的微调性能,同时大幅减少了参数调整量。
这一方法不仅在多个视觉任务中超越了传统全参数微调,还为未来视觉模型的高效微调提供了新的方向。
预印版期间,Mona已被复旦、中科大、南大、武大等多家单位的工作视为SOTA方法运用在医学、遥感等领域。
Mona的开源代码将进一步推动这一领域的研究和应用。
附论文引用格式:
复制@misc{yin20245100breakingperformanceshackles, title={5%>100%: Breaking Performance Shackles of Full Fine-Tuning on Visual Recognition Tasks}, author={Dongshuo Yin and Leiyi Hu and Bin Li and Youqun Zhang and Xue Yang}, year={2024}, eprint={2408.08345}, archivePrefix={arXiv}, primaryClass={cs.CV}, url={https://arxiv.org/abs/2408.08345}, }
论文地址:https://arxiv.org/pdf/2408.08345代码:https://github.com/Leiyi-Hu/mona