发布时间:2023-02-23 17:00
分享一下自己写的一个模块,我在VOC数据集上测试没有涨点,但是好多人在自己的数据集上都涨点了,那我就简单说下原理
我起初想法很简单,就是觉得原本的 6 × 6 6×6 6×6卷积参数量太大了,然后就想使用一个 3 × 3 3×3 3×3和一个 5 × 5 5×5 5×5的卷积替代,主要目的是想节省一点参数量(虽然微不足道),后来有同学说可以试试空洞卷积,随后我就把 5 × 5 5×5 5×5的普通卷积替换成了 3 × 3 3×3 3×3的空洞卷积,这样可以保持感受野不变的同时进一步减少参数
原理图如下所示,(a)为原始的 6 × 6 6×6 6×6卷积(b)为我自己改进的卷积,我这里没有加BN和SiLU,我测试了一下,加了比不加点数还低,
class Inception_Conv(nn.Module):
# Standard convolution
def __init__(self, c1, c2, k=3, s=2, g=1, p=None): # ch_in, ch_out, kernel, stride, padding, groups
super().__init__()
self.conv1 = nn.Conv2d(c1, c2, k, s, autopad(k, p), groups=g, bias=False)
self.conv2 = nn.Conv2d(c1, c2, k , s, autopad(k+2 , p),dilation=2, groups=g, bias=False)
def forward(self, x):
x1 = self.conv1(x)
x2 = self.conv2(x)
x = torch.add(x1, x2)
return x
配置文件:
# YOLOv5 by Ultralytics, GPL-3.0 license
# Parameters
nc: 80 # number of classes
depth_multiple: 0.33 # model depth multiple
width_multiple: 0.50 # layer channel multiple
anchors:
- [10,13, 16,30, 33,23] # P3/8
- [30,61, 62,45, 59,119] # P4/16
- [116,90, 156,198, 373,326] # P5/32
# YOLOv5 v6.0 backbone
backbone:
# [from, number, module, args]
[[-1, 1, Inception_Conv, [64, 3]], # 0-P1/2
[-1, 1, Conv, [128, 3, 2]], # 1-P2/4
[-1, 3, C3, [128]],
[-1, 1, Conv, [256, 3, 2]], # 3-P3/8
[-1, 6, C3, [256]],
[-1, 1, Conv, [512, 3, 2]], # 5-P4/16
[-1, 9, C3, [512]],
[-1, 1, Conv, [1024, 3, 2]], # 7-P5/32
[-1, 3, C3, [1024]],
[-1, 1, SPPF, [1024, 5]], # 9
]
# YOLOv5 v6.0 head
head:
[[-1, 1, Conv, [512, 1, 1]],
[-1, 1, nn.Upsample, [None, 2, 'nearest']],
[[-1, 6], 1, Concat, [1]], # cat backbone P4
[-1, 3, C3, [512, False]], # 13
[-1, 1, Conv, [256, 1, 1]],
[-1, 1, nn.Upsample, [None, 2, 'nearest']],
[[-1, 4], 1, Concat, [1]], # cat backbone P3
[-1, 3, C3, [256, False]], # 17 (P3/8-small)
[-1, 1, Conv, [256, 3, 2]],
[[-1, 14], 1, Concat, [1]], # cat head P4
[-1, 3, C3, [512, False]], # 20 (P4/16-medium)
[-1, 1, Conv, [512, 3, 2]],
[[-1, 10], 1, Concat, [1]], # cat head P5
[-1, 3, C3, [1024, False]], # 23 (P5/32-large)
[[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
]