1/3/5/7 四种卷积并行提取特征;分支求和后全局平均生成通道描述,再为每条分支预测通道权重,沿分支维 Softmax 后加权求和。
[2×32×16×16]2×32×16×16SKAttention(channel=32, kernels=[1,3,5,7], reduction=16, L=16);CPU / evalforward() 数据流顺序拆解 · 点击任意子模块方块可同步查看对应源码切片1/3/5/7 四种卷积并行提取特征;分支求和后全局平均生成通道描述,再为每条分支预测通道权重,沿分支维 Softmax 后加权求和。 本页使用 SKAttention(channel=32, kernels=[1,3,5,7], reduction=16, L=16);CPU / float32 / eval,forward_hook 记录子层输入输出,函数式运算的形状由同次前向局部张量读取。
47 weights=[]48 for fc in self.fcs:49 weight=fc(Z)50 weights.append(weight.view(bs,c,1,1)) #bs,channel 51 attention_weughts=torch.stack(weights,0)#k,bs,channel,1,152 attention_weughts=self.softmax(attention_weughts)#k,bs,channel,1,153 54 ### fuse 55 V=(attention_weughts*feats).sum(0)56 return V
本例输入 (2,32,16,16),内部描述宽度 d=max(L,C//reduction)=16。四条卷积分支均为普通卷积。
from SKAttention import SKAttention model = SKAttention(channel=32, kernels=[1,3,5,7], reduction=16, L=16).eval() y = model(x)
Method 动机参考:根据输入内容在不同感受野之间选择,而非对所有尺度固定求和。
| 消融变体 | 结构配置 | 验证目的 |
|---|---|---|
| 固定求和 | 四分支直接平均 | 建立多尺度静态融合基准 |
| 共享通道权重 | 只预测每分支单个标量 | 检验逐通道尺度选择 |
| 完整 SKAttention | 逐通道分支 Softmax | 同时报告多核卷积开销 |
SKAttention(channel=32, kernels=[1,3,5,7], reduction=16, L=16),输入为 torch.randn(2,32,16,16)。使用 PyTorch 2.6.0+cu124,CPU / float32 / eval;参数量为 89104,通过 sum(p.numel() for p in model.parameters()) 计算。测试使用随机输入,消融表是待开展的实验设计。