【魔改YOLOv5-6.x(上)】:结合轻量化网络Shufflenetv2、Mobilenetv3和Ghostnet
【魔改YOLOv5-6.x(中)】:加入ACON激活函数、CBAM和CA注意力机制、加权双向特征金字塔BiFPN
本文使用的YOLOv5版本为v6.1,对YOLOv5-6.x网络结构还不熟悉的同学,可以移步至:【YOLOv5-6.x】网络模型&源码解析
$ python -m torch.distributed.launch --nproc_per_node 2 train.py --weights --cfg yolov5s.yaml --data data/VOC2007.yaml -- hyp data/hyps/hyp.scratch-high.yaml --epochs 300 --device 0,1
$ python val.py --weights yolov5s.pt --data VOC2007.yaml --img 832 --augment --half --iou 0.6
$ python val.py --weights yolov5s.pt --data VOC2007.yaml --img 640 --task speed --batch 1
根据实验效果,最终作出如下选择:
yolov5s-Ghostconv-BiFPN-CA.yaml
# Parameters
nc: 20 # 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, Conv, [64, 6, 2, 2]], # 0-P1/2
[-1, 1, GhostConv, [128, 3, 2]], # 1-P2/4
[-1, 3, C3, [128]],
[-1, 1, GhostConv, [256, 3, 2]], # 3-P3/8
[-1, 6, C3, [256]],
[-1, 1, GhostConv, [512, 3, 2]], # 5-P4/16
[-1, 9, C3, [512]],
[-1, 1, GhostConv, [1024, 3, 2]], # 7-P5/32
[-1, 3, C3, [1024]],
[-1, 1, CABlock, [1024, 32]], # 9 CA <-- Coordinate Attention [out_channel, reduction]
[-1, 1, SPPF, [1024, 5]], # 10
]
# YOLOv5 v6.0 head
head:
[[-1, 1, GhostConv, [512, 1, 1]],
[-1, 1, nn.Upsample, [None, 2, 'nearest']],
[[-1, 6], 1, Concat, [1]], # cat backbone P4
[-1, 3, C3, [512, False]], # 14
[-1, 1, GhostConv, [256, 1, 1]],
[-1, 1, nn.Upsample, [None, 2, 'nearest']],
[[-1, 4], 1, Concat, [1]], # cat backbone P3
[-1, 3, C3, [256, False]], # 18 (P3/8-small)
[-1, 1, GhostConv, [256, 3, 2]],
[[-1, 15, 6], 1, Concat, [1]], # cat head P4 <--- BiFPN change
[-1, 3, C3, [512, False]], # 21 (P4/16-medium)
[-1, 1, GhostConv, [512, 3, 2]],
[[-1, 11], 1, Concat, [1]], # cat head P5
[-1, 3, C3, [1024, False]], # 24 (P5/32-large)
[[18, 21, 24], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
]
这里分享一下部分较为完整的实验记录,其他实验记录因为只测试了map,看到效果并不是很好,就没有继续测试其他的指标,因此也就没有放上来。
序号 | Model | mAP_50 | mAP_0.5:0.95 | Speed b1 (ms) | params(M) | FLOPs(G) |
---|---|---|---|---|---|---|
0 | yolov5s-baseline | 72.6 | 45.9 | 5.8 | 7.07 | 16.0 |
1 | yolov5s-BiFPN | 72.6(+0.0) | 45.8(-0.1) | 5.9 | 7.14 | 16.2 |
2 | yolov5s-CA | 73.2(+0.6) | 46.3(+0.4) | 6.3 | 7.10 | 16.0 |
3 | yolov5s-BiFPN-CA | 72.4(-0.2) | 45.3(-0.6) | 6.4 | 7.17 | 16.2 |
4 | yolov5s-Ghostconv-CA | 73.7(+1.1) | 47.9(+2.0) | 7.8 | 5.88 | 13.7 |
5 | yolov5s-Ghostconv-BiFPN-CA | 74.1(+1.5) | 48.7(+2.8) | 7.8 | 5.95 | 13.9 |
目前还没有尝试更多的改进方法,欢迎大家前来交流,分享改进YOLOv5的方法~