目标检测算法——YOLOv5/YOLOv7改进之GSConv+Slim Neck(优化成本)

目标检测算法——YOLOv5/YOLOv7改进之GSConv+Slim Neck(优化成本)_第1张图片

>>>深度学习Tricks,第一时间送达<<<

目录

(一)前言

1.GSConv模块

2.Slim Neck(GSBottleneck+VoVGSCSP)

(二)YOLOv5改进之GSConv+Slim Neck

1.配置common.py文件

2.配置yolo.py文件

3.配置YOLOv5/YOLOv7_GSConv.yaml文件


论文题目:Slim-neck by GSConv: A better design paradigm of detector architectures for autonomous vehicles

论文地址:https://arxiv.org/abs/2206.02424

代码地址:https://github.com/AlanLi1997/Slim-neck-by-GSConv


(一)前言

目标检测算法——YOLOv5/YOLOv7改进之GSConv+Slim Neck(优化成本)_第2张图片

作者提出了一种新方法 GSConv 来减轻模型的复杂度并保持准确性。GSConv可以更好地平衡模型的准确性和速度。并且,提供了一种设计范式Slim Neck,以实现检测器更高的计算成本效益。实验过程中,与原始网络相比,改进方法获得了最优秀的检测结果。

如上图所示,作者在 SODA10M 的无人驾驶数据集上比较了最先进的Slim Neck 检测器和原始检测器的速度和准确度,并证实了该方法的有效性。

1.GSConv模块

目标检测算法——YOLOv5/YOLOv7改进之GSConv+Slim Neck(优化成本)_第3张图片

2.Slim Neck(GSBottleneck+VoVGSCSP)

目标检测算法——YOLOv5/YOLOv7改进之GSConv+Slim Neck(优化成本)_第4张图片

(二)YOLOv5改进之GSConv+Slim Neck

1.配置common.py文件

复制粘贴以下代码:

#GSConv_______________________________________________________

class GSConv(nn.Module):
    def __init__(self, c1, c2, k=1, s=1, g=1, act=True):
        super().__init__()
        c_ = c2 // 2
        self.cv1 = Conv(c1, c_, k, s, None, g, act)
        self.cv2 = Conv(c_, c_, 5, 1, None, c_, act)

    def forward(self, x):
        x1 = self.cv1(x)
        x2 = torch.cat((x1, self.cv2(x1)), 1)
        # shuffle
        b, n, h, w = x2.data.size()
        b_n = b * n // 2
        y = x2.reshape(b_n, 2, h * w)
        y = y.permute(1, 0, 2)
        y = y.reshape(2, -1, n // 2, h, w)
        return torch.cat((y[0], y[1]), 1)

2.配置yolo.py文件

找到相应位置,加入GSConv。

 if m in [Conv, GhostConv, Bottleneck, GhostBottleneck, SPP, 
DWConv, MixConv2d, Focus, CrossConv, BottleneckCSP, C3, C3TR, GSConv]:      

3.配置YOLOv5/YOLOv7_GSConv.yaml文件

下面以YOLOv5为例。

# anchors
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 backbone
backbone:
  # [from, number, module, args]
  [[-1, 1, Focus, [64, 3]],  # 0-P1/2
   [-1, 1, GSConv, [128, 3, 2]],  # 1-P2/4
   [-1, 3, C3, [128]],
   [-1, 1, GSConv, [256, 3, 2]],  # 3-P3/8
   [-1, 9, C3, [256]],
   [-1, 1, GSConv, [512, 3, 2]],  # 5-P4/16
   [-1, 9, C3, [512]],
   [-1, 1, GSConv, [1024, 3, 2]],  # 7-P5/32
   [-1, 1, SPP, [1024, [5, 9, 13]]],
   [-1, 3, C3, [1024, False]],  # 9
  ]

# YOLOv5 head
head:
  [[-1, 1, GSConv, [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, GSConv, [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, GSConv, [256, 3, 2]],
   [[-1, 14], 1, Concat, [1]],  # cat head P4
   [-1, 3, C3, [512, False]],  # 20 (P4/16-medium)

   [-1, 1, GSConv, [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)
  ]

小伙伴们改进过程有问题或需要Slim Neck的可直接私信博主~

关于算法改进及论文投稿可关注并留言博主的CSDN/QQ

>>>一起交流!互相学习!共同进步!<<<

你可能感兴趣的:(YOLOv5算法改进,YOLOv7算法改进,目标检测,人工智能,深度学习,python)