【魔改YOLOv5-6.x(下)】YOLOv5s+Ghostconv+BiFPN+CA
文章目录
前言
【魔改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)
]
训练仍在进行中,之后会更新相应的测试结果,目前还没有尝试更多的改进方法,欢迎大家前来交流,分享改进YOLOv5的方法~
来源:嗜睡的篠龙