💡💡💡本文主要内容:详细介绍了水下生物检测整个过程,从数据集到训练模型到结果可视化分析,以及如何优化提升检测性能。
💡💡💡加入超轻量高效动态上采样DySample mAP@0.5由原始的0.522提升至0.565
1.水下生物检测数据集介绍
水下生物检测类别:
0: echinus1: holothurian2: scallop3: starfish4: waterweeds
数据集大小:1000张
细节图:
2.基于YOLOv8的水下生物检测
2.1 修改fish.yaml
path: ./data/fish # dataset root dir
train: train.txt # train images (relative to 'path') 118287 images
val: val.txt # val images (relative to 'path') 5000 images# number of classes
nc: 5# class names
names:0: echinus1: holothurian2: scallop3: starfish4: waterweeds
2.2 开启训练
import warnings
warnings.filterwarnings('ignore')
from ultralytics import YOLOif __name__ == '__main__':model = YOLO('ultralytics/cfg/models/v8/lyolo/yolov8n-lyolo.yaml')#model.load('yolov8n.pt') # loading pretrain weightsmodel.train(data='data/fish/fish.yaml',cache=False,imgsz=640,epochs=200,batch=16,close_mosaic=10,workers=0,device='0',optimizer='SGD', # using SGDproject='runs/train',name='exp',)
3.结果可视化分析
F1_curve.png:F1分数与置信度(x轴)之间的关系。F1分数是分类的一个衡量标准,是精确率和召回率的调和平均函数,介于0,1之间。越大越好。
TP:真实为真,预测为真;
FN:真实为真,预测为假;
FP:真实为假,预测为真;
TN:真实为假,预测为假;
精确率(precision)=TP/(TP+FP)
召回率(Recall)=TP/(TP+FN)
F1=2*(精确率*召回率)/(精确率+召回率)
PR_curve.png :PR曲线中的P代表的是precision(精准率),R代表的是recall(召回率),其代表的是精准率与召回率的关系。
R_curve.png :召回率与置信度之间关系
results.png
mAP_0.5:0.95表示从0.5到0.95以0.05的步长上的平均mAP.
预测结果:
4.如何优化模型
4.1 DySample介绍
YOLOv8独家改进:上采样算子 | 超轻量高效动态上采样DySample,效果秒杀CAFFE,助力小目标检测-CSDN博客
论文:https://arxiv.org/pdf/2308.15085.pdf
摘要:我们介绍DySample,一个超轻量和有效的动态上采样器。虽然最近基于内核的动态上采样器(如CARAFE、FADE和SAPA)的性能提升令人印象深刻,但它们带来了大量的工作负载,主要是由于耗时的动态卷积和用于生成动态内核的额外子网络。此外,对高特征指导的需求在某种程度上限制了它们的应用场景。为了解决这些问题,我们绕过动态卷积并从点采样的角度制定上采样,这更节省资源,并且可以很容易地使用PyTorch中的标准内置函数实现。我们首先展示了一个朴素的设计,然后演示了如何逐步加强其上采样行为,以实现我们的新上采样器DySample。与以前基于内核的动态上采样器相比,DySample不需要定制CUDA包,并且具有更少的参数、FLOPs、GPU内存和延迟。除了轻量级的特点,DySample在五个密集预测任务上优于其他上采样器,包括语义分割、目标检测、实例分割、全视分割和单目深度估计。
图1所示。不同上采样器的性能、推理速度和GFLOPs的比较。圆圈的大小表示GFLOPs的开销。通过×2上采样大小为256 × 120 × 120的特征图来测试推理时间。在ADE20K数据集[42]上使用SegFormer-B1[40]测试了mIoU性能和额外的gflop。
4.2 对应yaml
# Ultralytics YOLO 🚀, AGPL-3.0 license
# YOLOv8 object detection model with P3-P5 outputs. For Usage examples see https://docs.ultralytics.com/tasks/detect# Parameters
nc: 80 # number of classes
scales: # model compound scaling constants, i.e. 'model=yolov8n.yaml' will call yolov8.yaml with scale 'n'# [depth, width, max_channels]n: [0.33, 0.25, 1024] # YOLOv8n summary: 225 layers, 3157200 parameters, 3157184 gradients, 8.9 GFLOPss: [0.33, 0.50, 1024] # YOLOv8s summary: 225 layers, 11166560 parameters, 11166544 gradients, 28.8 GFLOPsm: [0.67, 0.75, 768] # YOLOv8m summary: 295 layers, 25902640 parameters, 25902624 gradients, 79.3 GFLOPsl: [1.00, 1.00, 512] # YOLOv8l summary: 365 layers, 43691520 parameters, 43691504 gradients, 165.7 GFLOPsx: [1.00, 1.25, 512] # YOLOv8x summary: 365 layers, 68229648 parameters, 68229632 gradients, 258.5 GFLOPs# YOLOv8.0n backbone
backbone:# [from, repeats, module, args]- [-1, 1, Conv, [64, 3, 2]] # 0-P1/2- [-1, 1, Conv, [128, 3, 2]] # 1-P2/4- [-1, 3, C2f, [128, True]]- [-1, 1, Conv, [256, 3, 2]] # 3-P3/8- [-1, 6, C2f, [256, True]]- [-1, 1, Conv, [512, 3, 2]] # 5-P4/16- [-1, 6, C2f, [512, True]]- [-1, 1, Conv, [1024, 3, 2]] # 7-P5/32- [-1, 3, C2f, [1024, True]]- [-1, 1, SPPF, [1024, 5]] # 9# YOLOv8.0n head
head:- [-1, 1, DySample, [2, 'lp']]- [[-1, 6], 1, Concat, [1]] # cat backbone P4- [-1, 3, C2f, [512]] # 12- [-1, 1, DySample, [2, 'lp']]- [[-1, 4], 1, Concat, [1]] # cat backbone P3- [-1, 3, C2f, [256]] # 15 (P3/8-small)- [-1, 1, Conv, [256, 3, 2]]- [[-1, 12], 1, Concat, [1]] # cat head P4- [-1, 3, C2f, [512]] # 18 (P4/16-medium)- [-1, 1, Conv, [512, 3, 2]]- [[-1, 9], 1, Concat, [1]] # cat head P5- [-1, 3, C2f, [1024]] # 21 (P5/32-large)- [[15, 18, 21], 1, Detect, [nc]] # Detect(P3, P4, P5)
4.3 实验结果分析
mAP@0.5由原始的0.522提升至0.565
YOLOv8-dysample summary (fused): 170 layers, 3018975 parameters, 0 gradients, 8.1 GFLOPsClass Images Instances Box(P R mAP50 mAP50-95): 100%|██████████| 9/9 [00:22<00:00, 2.55s/it]all 270 1602 0.72 0.512 0.565 0.274echinus 270 976 0.833 0.716 0.779 0.375holothurian 270 265 0.619 0.263 0.307 0.137scallop 270 92 0.691 0.412 0.47 0.236starfish 270 269 0.737 0.658 0.703 0.347
5.系列篇
系列篇1:自研注意力BSAM
系列篇2:MSAM(CBAM升级版)
系列篇3:创新自研CPMS注意力(CBAM升级版)
系列篇4:DCNv4结合SPPF,效果秒杀DCNv3
系列篇5:超轻量高效动态上采样DySample涨点四个点