自建数据集,基于YOLOv7开发构建农田场景下杂草检测识别系统

在我们前面的一些文章中也做过不少跟农业相关的检测项目,感兴趣的话可以自行移步阅读即可,这里仅给出来最近的两个:

《激光除草距离我们实际的农业生活还有多远,结合近期所见所感基于yolov8开发构建田间作物杂草检测识别系统》

《助力农作物病虫害检测识别,基于yolov3—yolov8开发构建马铃薯作物甲虫检测识别系统》

本文的主要目的就是想要基于yolov7这一款模型来开发构建基于自己构建的杂草数据的检测模型,首先看下整体效果:

接下来简单看下数据详情:

自建数据集,基于YOLOv7开发构建农田场景下杂草检测识别系统_第1张图片

自建数据集,基于YOLOv7开发构建农田场景下杂草检测识别系统_第2张图片

实例标注数据内容如下所示:

16 0.401333 0.409 0.12 0.218
16 0.632667 0.441 0.113333 0.222
16 0.169333 0.646 0.157333 0.184

xml标注内容实例如下所示:


	data
	0391.jpg
	0391.jpg
	
		Unknown
	
	
		750
		500
		3
	
	0
	
		gouweibacao
		Unspecified
		0
		0
		
			181
			95
			287
			154
		
	
	
		gouweibacao
		Unspecified
		0
		0
		
			219
			163
			264
			239
		
	
	
		gouweibacao
		Unspecified
		0
		0
		
			310
			225
			370
			285
		
	
	
		gouweibacao
		Unspecified
		0
		0
		
			289
			160
			448
			236
		
	
	
		gouweibacao
		Unspecified
		0
		0
		
			458
			192
			570
			235
		
	
	
		gouweibacao
		Unspecified
		0
		0
		
			485
			217
			535
			302
		
	
	
		gouweibacao
		Unspecified
		0
		0
		
			624
			232
			675
			316
		
	

本文中选择的是参数量相对适中的yolov7模型,模型文件如下所示:

# parameters
nc: 20  # number of classes
depth_multiple: 1.0  # model depth multiple
width_multiple: 1.0  # layer channel multiple

# anchors
anchors:
  - [12,16, 19,36, 40,28]  # P3/8
  - [36,75, 76,55, 72,146]  # P4/16
  - [142,110, 192,243, 459,401]  # P5/32

# yolov7 backbone
backbone:
  # [from, number, module, args]
  [[-1, 1, Conv, [32, 3, 1]],  # 0
  
   [-1, 1, Conv, [64, 3, 2]],  # 1-P1/2      
   [-1, 1, Conv, [64, 3, 1]],
   
   [-1, 1, Conv, [128, 3, 2]],  # 3-P2/4  
   [-1, 1, Conv, [64, 1, 1]],
   [-2, 1, Conv, [64, 1, 1]],
   [-1, 1, Conv, [64, 3, 1]],
   [-1, 1, Conv, [64, 3, 1]],
   [-1, 1, Conv, [64, 3, 1]],
   [-1, 1, Conv, [64, 3, 1]],
   [[-1, -3, -5, -6], 1, Concat, [1]],
   [-1, 1, Conv, [256, 1, 1]],  # 11
         
   [-1, 1, MP, []],
   [-1, 1, Conv, [128, 1, 1]],
   [-3, 1, Conv, [128, 1, 1]],
   [-1, 1, Conv, [128, 3, 2]],
   [[-1, -3], 1, Concat, [1]],  # 16-P3/8  
   [-1, 1, Conv, [128, 1, 1]],
   [-2, 1, Conv, [128, 1, 1]],
   [-1, 1, Conv, [128, 3, 1]],
   [-1, 1, Conv, [128, 3, 1]],
   [-1, 1, Conv, [128, 3, 1]],
   [-1, 1, Conv, [128, 3, 1]],
   [[-1, -3, -5, -6], 1, Concat, [1]],
   [-1, 1, Conv, [512, 1, 1]],  # 24
         
   [-1, 1, MP, []],
   [-1, 1, Conv, [256, 1, 1]],
   [-3, 1, Conv, [256, 1, 1]],
   [-1, 1, Conv, [256, 3, 2]],
   [[-1, -3], 1, Concat, [1]],  # 29-P4/16  
   [-1, 1, Conv, [256, 1, 1]],
   [-2, 1, Conv, [256, 1, 1]],
   [-1, 1, Conv, [256, 3, 1]],
   [-1, 1, Conv, [256, 3, 1]],
   [-1, 1, Conv, [256, 3, 1]],
   [-1, 1, Conv, [256, 3, 1]],
   [[-1, -3, -5, -6], 1, Concat, [1]],
   [-1, 1, Conv, [1024, 1, 1]],  # 37
         
   [-1, 1, MP, []],
   [-1, 1, Conv, [512, 1, 1]],
   [-3, 1, Conv, [512, 1, 1]],
   [-1, 1, Conv, [512, 3, 2]],
   [[-1, -3], 1, Concat, [1]],  # 42-P5/32  
   [-1, 1, Conv, [256, 1, 1]],
   [-2, 1, Conv, [256, 1, 1]],
   [-1, 1, Conv, [256, 3, 1]],
   [-1, 1, Conv, [256, 3, 1]],
   [-1, 1, Conv, [256, 3, 1]],
   [-1, 1, Conv, [256, 3, 1]],
   [[-1, -3, -5, -6], 1, Concat, [1]],
   [-1, 1, Conv, [1024, 1, 1]],  # 50
  ]

# yolov7 head
head:
  [[-1, 1, SPPCSPC, [512]], # 51
  
   [-1, 1, Conv, [256, 1, 1]],
   [-1, 1, nn.Upsample, [None, 2, 'nearest']],
   [37, 1, Conv, [256, 1, 1]], # route backbone P4
   [[-1, -2], 1, Concat, [1]],
   
   [-1, 1, Conv, [256, 1, 1]],
   [-2, 1, Conv, [256, 1, 1]],
   [-1, 1, Conv, [128, 3, 1]],
   [-1, 1, Conv, [128, 3, 1]],
   [-1, 1, Conv, [128, 3, 1]],
   [-1, 1, Conv, [128, 3, 1]],
   [[-1, -2, -3, -4, -5, -6], 1, Concat, [1]],
   [-1, 1, Conv, [256, 1, 1]], # 63
   
   [-1, 1, Conv, [128, 1, 1]],
   [-1, 1, nn.Upsample, [None, 2, 'nearest']],
   [24, 1, Conv, [128, 1, 1]], # route backbone P3
   [[-1, -2], 1, Concat, [1]],
   
   [-1, 1, Conv, [128, 1, 1]],
   [-2, 1, Conv, [128, 1, 1]],
   [-1, 1, Conv, [64, 3, 1]],
   [-1, 1, Conv, [64, 3, 1]],
   [-1, 1, Conv, [64, 3, 1]],
   [-1, 1, Conv, [64, 3, 1]],
   [[-1, -2, -3, -4, -5, -6], 1, Concat, [1]],
   [-1, 1, Conv, [128, 1, 1]], # 75
      
   [-1, 1, MP, []],
   [-1, 1, Conv, [128, 1, 1]],
   [-3, 1, Conv, [128, 1, 1]],
   [-1, 1, Conv, [128, 3, 2]],
   [[-1, -3, 63], 1, Concat, [1]],
   
   [-1, 1, Conv, [256, 1, 1]],
   [-2, 1, Conv, [256, 1, 1]],
   [-1, 1, Conv, [128, 3, 1]],
   [-1, 1, Conv, [128, 3, 1]],
   [-1, 1, Conv, [128, 3, 1]],
   [-1, 1, Conv, [128, 3, 1]],
   [[-1, -2, -3, -4, -5, -6], 1, Concat, [1]],
   [-1, 1, Conv, [256, 1, 1]], # 88
      
   [-1, 1, MP, []],
   [-1, 1, Conv, [256, 1, 1]],
   [-3, 1, Conv, [256, 1, 1]],
   [-1, 1, Conv, [256, 3, 2]],
   [[-1, -3, 51], 1, Concat, [1]],
   
   [-1, 1, Conv, [512, 1, 1]],
   [-2, 1, Conv, [512, 1, 1]],
   [-1, 1, Conv, [256, 3, 1]],
   [-1, 1, Conv, [256, 3, 1]],
   [-1, 1, Conv, [256, 3, 1]],
   [-1, 1, Conv, [256, 3, 1]],
   [[-1, -2, -3, -4, -5, -6], 1, Concat, [1]],
   [-1, 1, Conv, [512, 1, 1]], # 101
   
   [75, 1, RepConv, [256, 3, 1]],
   [88, 1, RepConv, [512, 3, 1]],
   [101, 1, RepConv, [1024, 3, 1]],

   [[102,103,104], 1, IDetect, [nc, anchors]],   # Detect(P3, P4, P5)
  ]

默认100次epoch的迭代计算,结果详情如下所示:

【混淆矩阵】

自建数据集,基于YOLOv7开发构建农田场景下杂草检测识别系统_第3张图片

【F1值曲线】

自建数据集,基于YOLOv7开发构建农田场景下杂草检测识别系统_第4张图片

【精确率曲线】

自建数据集,基于YOLOv7开发构建农田场景下杂草检测识别系统_第5张图片

【召回率曲线】

自建数据集,基于YOLOv7开发构建农田场景下杂草检测识别系统_第6张图片

【PR】曲线

自建数据集,基于YOLOv7开发构建农田场景下杂草检测识别系统_第7张图片

【训练可视化】

自建数据集,基于YOLOv7开发构建农田场景下杂草检测识别系统_第8张图片

【计算实例】

为方便部署使用这里开发了专用的可视化系统界面,能够支持图像和视频两种数据的推理计算,简单的实例效果图如下所示:

【图像推理】

自建数据集,基于YOLOv7开发构建农田场景下杂草检测识别系统_第9张图片

自建数据集,基于YOLOv7开发构建农田场景下杂草检测识别系统_第10张图片

【视频推理】

自建数据集,基于YOLOv7开发构建农田场景下杂草检测识别系统_第11张图片

自建数据集,基于YOLOv7开发构建农田场景下杂草检测识别系统_第12张图片

感兴趣的话可以自行开发实践一下!

 

你可能感兴趣的:(YOLO)