#6006·yolov5

Attention imporved yolov5 performance

Author: 315386775Created Dec 16, 2021Updated Oct 20, 2024
LabelsenhancementTODO

Search before asking

  • I have searched the YOLOv5 issues and found no similar feature requests.

Description

Hi, I really appreciate this great work for the cv community. Attention mechanism module can improve the performance of the model. Similar to the C3Ghost and C3SPP module. I have tested the C3-attention module with GCNet, named C3_GC module. With C3_GC module achieves 36.12% map (ori map 35.35) with yolov5s. GFLOPs from 17,1 to 17.3. and Parameter from 7.3M to 7.6M Paper : <GCNet: Non-local Networks Meet Squeeze-Excitation Networks and Beyond>

`class C3_GC(nn.Module): # C3 module with ContextBlock2d() def init(self, c1, c2, n=1, shortcut=True, g=1, e=0.5): # ch_in, ch_out, number, shortcut, groups, expansion super(C3_GC, self).init() c_ = int(c2 * e) # hidden channels self.gc = ContextBlock2d(c1) self.cv1 = Conv(c1, c_, 1, 1) self.cv2 = Conv(c1, c_, 1, 1) self.cv3 = Conv(2 * c_, c2, 1) # act=FReLU(c2) self.m = nn.Sequential(*[Bottleneck(c_, c_, shortcut, g, e=1.0) for _ in range(n)])

def forward(self, x):
    out = torch.cat((self.m(self.cv1(x)), self.cv2(self.gc(x))), dim=1)
    out = self.cv3(out)
    return out`

Use case

You need modify the yolov5s.yaml

`backbone:

[from, number, module, args]

[[-1, 1, Focus, [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, 9, C3_GC, [256, True]], [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 [-1, 9, C3_GC, [512, True]], [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 [-1, 1, SPP, [1024, [5, 9, 13]]], [-1, 3, C3_GC, [1024, False]], # 9 ]`

Additional

No response

Are you willing to submit a PR?

  • Yes I'd like to help by submitting a PR!