yolov5中的6.0和5.0版本对比

paper:NO PAPER HERE!!!

github:github.com/ultralytics/

brief summary:github.com/ultralytics/

YOLO v5至今未发表正式的论文,但这丝毫不影响其强大的影响力. 依靠其强大的性能表现,不论是在学术界还是工业界,都是目标检测的香饽饽. 由于YOLO v5有众多版本,且每个版本间有细微差异,本文主要讨论6.0版本和5.0版本.

highlight

  • 自适应Anchor. 将聚类获得Anchor尺寸的方法嵌入到了训练代码中,每次训练前都会寻找最优的Anchors.
  • 自适应图片缩放. 和mmdetection的缩放图片方式相同.
  • 遗传算法获得最优超参数.
  • 6.0使用6x6卷积替代5.0的Focus. 二者效果一致,但卷积有更好的硬件支持.
  • 6.0提出SPPF替换SPP,二者效果一致,但前者较后者的执行时间减少至1/2.
  • 改用SiLU激活函数.

Improvement

YOLO v5整体结构和v4还是非常相似的,相较YOLO v4,其改进点也主要是上述highlight所提到的几个点.

YOLO v5网络结构

YOLO v5-6.0的网络结构如下图所示. 概括地说,结构主要分成三部分:CSPDarkNet-53 (Backbone) => SSPF + CSP-PAN (Neck)=> YOLOv3 (head).

 

Stem

在5.0的时候,输入图片(640,640,3)将会经过Focus,变成(320,320,12),再经一层Conv1x1变成(320,320,64). 而6.0收到热心网友的建议,将这个过程替换成了一层Conv6x6(stride=2,padding=2),直接将输入图片(640,640,3)变成(320,320,64).

Focus就是PyTorch里的nn.PixelUnshuffle. 用卷积替换Focus:github.com/ultralytics/
class Focus(nn.Module):
    # Focus wh information into c-space
    def __init__(self, c1, c2, k=1, s=1, p=None, g=1, act=True):  # ch_in, ch_out, kernel, stride, padding, groups
        super(Focus, self).__init__()
        self.conv = Conv(c1 * 4, c2, k, s, p, g, act)

    def forward(self, x):  # x(b,c,w,h) -> y(b,4c,w/2,h/2)
        return self.conv(torch.cat([x[..., ::2, ::2], x[..., 1::2, ::2], x[..., ::2, 1::2], x[..., 1::2, 1::2]], 1))

SPPF

下图是SPP和SPPF的对比图. 相较SPP的并行结构,SPPF使用了串行的方式,达到了同等效果,并且大幅减少了重复计算,提速200%.

 

class SPP(nn.Module):
    # Spatial Pyramid Pooling (SPP) layer https://arxiv.org/abs/1406.4729
    def __init__(self, c1, c2, k=(5, 9, 13)):
        super().__init__()
        c_ = c1 // 2  # hidden channels
        self.cv1 = Conv(c1, c_, 1, 1)
        self.cv2 = Conv(c_ * (len(k) + 1), c2, 1, 1)
        self.m = nn.ModuleList([nn.MaxPool2d(kernel_size=x, stride=1, padding=x // 2) for x in k])

    def forward(self, x):
        x = self.cv1(x)
        with warnings.catch_warnings():
            warnings.simplefilter('ignore')  # suppress torch 1.9.0 max_pool2d() warning
            return self.cv2(torch.cat([x] + [m(x) for m in self.m], 1))


class SPPF(nn.Module):
    # Spatial Pyramid Pooling - Fast (SPPF) layer for YOLOv5 by Glenn Jocher
    def __init__(self, c1, c2, k=5):  # equivalent to SPP(k=(5, 9, 13))
        super().__init__()
        c_ = c1 // 2  # hidden channels
        self.cv1 = Conv(c1, c_, 1, 1)
        self.cv2 = Conv(c_ * 4, c2, 1, 1)
        self.m = nn.MaxPool2d(kernel_size=k, stride=1, padding=k // 2)

    def forward(self, x):
        x = self.cv1(x)
        with warnings.catch_warnings():
            warnings.simplefilter('ignore')  # suppress torch 1.9.0 max_pool2d() warning
            y1 = self.m(x)
            y2 = self.m(y1)
            return self.cv2(torch.cat([x, y1, y2, self.m(y2)], 1))

CSP-PAN

CSP-PAN就是在YOLO v4所用的PAN结构中加入了CSP,也就是卷积部分进行了替换.

from:https://zhuanlan.zhihu.com/p/546395563

posted @ 2022-10-13 15:35  海_纳百川  阅读(4552)  评论(0编辑  收藏  举报
本站总访问量