智慧农业农作物病虫害检测数据集
病虫害检测数据集,包含100余种病虫害类型,YOLO格式标注,支持YOLOv5-12等直接训练。
数据集已经划分处理:
train集: 15182个文件(占比: 80.0%)
val集: 1897个文件(占比: 10.0%)
test集: 1897个文件(占比: 10.0%)
共标注了 102 种农作物相关害虫,按作物类型与害虫特性可分为六大类,具体如下:水稻相关害虫(12 种),稻作及其他作物害虫(12 种),麦类作物害虫(11 种),甜菜及十字花科害虫(6 种),豆类及牧草害虫(13 种
智慧农业农作物病虫害检测数据集的详细分类统计表格,按作物类型与害虫特性划分为六大类,共102 种害虫,并附带各子类数量及占比:
🌾 智慧农业农作物病虫害数据集分类统计表
| 序号 | 害虫类别(按作物/生态类型) | 包含害虫种类数 | 占总类数比例 | 说明 |
|---|---|---|---|---|
| 1 | 水稻相关害虫 | 12 | 11.76% | 如稻飞虱、二化螟、稻纵卷叶螟等 |
| 2 | 稻作及其他作物害虫 | 12 | 11.76% | 跨水稻与其他作物的共生病虫害 |
| 3 | 麦类作物害虫 | 11 | 10.78% | 如麦蚜、吸浆虫、麦蜘蛛等 |
| 4 | 甜菜及十字花科害虫 | 6 | 5.88% | 如菜青虫、小菜蛾、甜菜夜蛾等 |
| 5 | 豆类及牧草害虫 | 13 | 12.75% | 如豆荚螟、大豆食心虫、苜蓿盲蝽等 |
| 6 | 其他主要农作物害虫(补充类) | 48 | 47.06% | 包括玉米、棉花、果树、蔬菜等常见害虫(如棉铃虫、玉米螟、蚜虫、红蜘蛛等) |
| 总计 | 102 | 100% | — |
✅数据集规模
- 训练集(train):15,182 张图像(80.0%)
- 验证集(val):1,897 张图像(10.0%)
- 测试集(test):1,897 张图像(10.0%)
- 标注格式:YOLO 格式(每张图对应
.txt文件,含class_id cx cy w h)- 兼容模型:YOLOv5 / YOLOv6 / YOLOv7 / YOLOv8 / YOLOv9 / YOLOv10 / YOLOv11(社区版)等
📁 数据集目录结构示例
agriculture_pest_dataset/ ├── images/ │ ├── train/# 15,182 images (.jpg)│ ├── val/# 1,897 images│ └── test/# 1,897 images├── labels/ │ ├── train/# 15,182 label files (.txt)│ ├── val/ │ └── test/ ├── classes.txt# 102 行,每行一个害虫类别名称(英文或中文拼音)└── dataset.yaml# YOLO 训练配置文件📄dataset.yaml示例
# agriculture_pest_dataset/dataset.yamltrain:./images/trainval:./images/valtest:./images/testnc:102names:['rice_planthopper','stem_borer','leaf_folder',...,'aphid','spider_mite'# 共102个类别名称,与 classes.txt 一致]该数据集适用于:
- 农业无人机巡检
- 手机端病虫害识别 App
- 智慧农场 AI 预警系统
- 科研与竞赛(如 AI+农业挑战赛)
1
基于 YOLOv8 的智慧农业农作物病虫害检测系统的完整实现,包含:
✅训练代码(含数据集配置)
✅推理与可视化系统代码
✅训练结果分析(结合你提供的损失曲线图)
✅模型部署与使用说明
📊 一、训练结果分析(基于损失图)
你提供的图表显示了YOLOv8 在 102 类病虫害数据集上的训练过程,关键指标如下:
| 指标 | 趋势 | 分析 |
|---|---|---|
train/box_loss | 快速下降 → 平稳 | 边界框回归收敛良好 |
train/cls_loss | 下降明显 | 分类任务学习稳定 |
train/dfl_loss | 下降趋势 | 分布焦点损失优化良好 |
val/mAP50(B) | 从 0.37 → 0.50 | 验证集 mAP 提升显著,模型泛化能力好 |
val/mAP50-95(B) | 从 0.25 → 0.36 | 小目标检测性能提升明显 |
precision&recall | 均稳步上升 | 检测准确率与召回率平衡 |
✅结论:模型在100 个 epoch 内收敛良好,mAP50 达到50%,适合用于实际农业场景。
🧩 二、训练代码(train.py)
# train.pyfromultralyticsimportYOLOif__name__=='__main__':# 加载预训练模型(推荐使用 yolov8s.pt)model=YOLO('yolov8s.pt')# 可选: yolov8n, yolov8m, yolov8x# 训练参数设置results=model.train(data='dataset.yaml',# 数据集配置文件epochs=100,# 训练轮数imgsz=640,# 输入图像大小batch=16,# 批次大小(根据 GPU 调整)name='agriculture_pest_v8s',# 实验名称workers=4,# 多进程数量optimizer='AdamW',# 优化器lr0=0.001,# 初始学习率weight_decay=0.0005,# 权重衰减mosaic=0.5,# Mosaic 数据增强比例mixup=0.2,# MixUp 比例save_period=10,# 每10轮保存一次模型device=0,# 使用 GPU 0val=True,# 每轮验证plot=True,# 绘制训练曲线augment=True# 启用数据增强)📁 三、数据集结构与dataset.yaml
# dataset.yamltrain:./images/trainval:./images/valtest:./images/testnc:102names:['rice_planthopper','stem_borer','leaf_folder','aphid','spider_mite','corn_borer','cotton_bollworm','beetle','weevil','cutworm','loopers','whitefly',...]✅ 确保目录结构:
agriculture_pest_dataset/ ├── images/ │ ├── train/ │ ├── val/ │ └── test/ ├── labels/ │ ├── train/ │ ├── val/ │ └── test/ └── dataset.yaml🔍 四、推理与可视化系统(detect.py)
# detect.pyfromultralyticsimportYOLOimportcv2importos model=YOLO('runs/detect/agriculture_pest_v8s/best.pt')defdetect_image(image_path):results=model(image_path)annotated=results[0].plot()# 自动绘制边界框和标签cv2.imwrite('output.jpg',annotated)print(f"检测完成,结果保存为 output.jpg")defdetect_video(video_path):cap=cv2.VideoCapture(video_path)whilecap.isOpened():ret,frame=cap.read()ifnotret:breakresults=model(frame)annotated=results[0].plot()cv2.imshow('Pest Detection',annotated)ifcv2.waitKey(1)&0xFF==ord('q'):breakcap.release()cv2.destroyAllWindows()# 示例调用detect_image('test.jpg')# 或 detect_video('field.mp4')🖥️ 五、PyQt5 图形界面(app.py)
# app.pyfromPyQt5.QtWidgetsimportQApplication,QMainWindow,QLabel,QPushButton,QVBoxLayout,QWidget,QFileDialogfromPyQt5.QtGuiimportQPixmapfromultralyticsimportYOLOimportsys,cv2classPestDetectionApp(QMainWindow):def__init__(self):super().__init__()self.setWindowTitle("智慧农业病虫害检测系统")self.model=YOLO('runs/detect/agriculture_pest_v8s/best.pt')self.init_ui()definit_ui(self):layout=QVBoxLayout()self.label=QLabel("请选择待检测图像")self.btn=QPushButton("选择图像")self.btn.clicked.connect(self.select_image)layout.addWidget(self.label)layout.addWidget(self.btn)self.setCentralWidget(QWidget())self.centralWidget().setLayout(layout)defselect_image(self):path,_=QFileDialog.getOpenFileName(self,"选择图像","","Images (*.jpg *.png)")ifpath:results=self.model(path)annotated=results[0].plot()cv2.imwrite("temp_result.jpg",annotated)self.label.setPixmap(QPixmap("temp_result.jpg").scaled(640,480))if__name__=='__main__':app=QApplication(sys.argv)window=PestDetectionApp()window.show()sys.exit(app.exec_())📈 六、训练后图片解释(以results.png为例)
你提供的训练曲线图(
results.png)可由 Ultralytics 自动生成,包含以下内容:
| 子图 | 含义 |
|---|---|
train/box_loss | 边界框回归损失,越低越好 |
train/cls_loss | 分类损失,反映类别预测准确性 |
train/dfl_loss | 分布焦点损失(Distribution Focal Loss),用于定位精度 |
metrics/precision(B) | 精确率(TP / (TP + FP)),越高越好 |
metrics/recall(B) | 召回率(TP / (TP + FN)),越高越好 |
val/box_loss,val/cls_loss,val/dfl_loss | 验证集损失,判断是否过拟合 |
metrics/mAP50(B) | IoU=0.5 时的平均精度,最终 mAP50 ≈ 50% |
metrics/mAP50-95(B) | IoU 从 0.5~0.95 的平均精度,≈ 36% |
✅结论:模型在100 轮内稳定收敛,无明显过拟合,适合部署。
💡 七、部署建议
1. 导出 ONNX 模型(用于边缘设备)
model.export(format='onnx',opset=12)2. 移动端部署(Android/iOS)
- 使用TFLite或Core ML
- 推荐工具:
torchscript+ONNX Runtime
3. 无人机集成
- 使用 NVIDIA Jetson Nano/Orin
- 部署 YOLOv8s + TensorRT 加速
📦 八、项目交付内容
| 内容 | 说明 |
|---|---|
| ✅ 完整训练代码 | train.py,detect.py |
| ✅ 数据集组织模板 | dataset.yaml, 目录结构 |
| ✅ 图形界面 | app.py(PyQt5) |
| ✅ 训练结果分析 | 损失曲线解读 |
| ✅ 模型文件 | best.pt(训练后生成) |
| ✅ 使用文档 | 如何运行、部署、调参 |