无人机枸杞树病害目标检测数据集
数据集概览
| 项目 | 内容 |
|---|---|
| 总图像数 | 1,539 张(航拍 RGB 图像) |
| 类别数量 | 2 类 |
| 类别标签 | 0: healthy(健康作物)1: stressed(病害作物) |
| 病害类型 | 点片状发病区、连片扩散区、叶片卷曲、病斑面积占比高、初期病斑、局部黄化、大面积枯萎、组织坏死等 |
| 数据划分 | - 训练集(train):1,083 张 - 验证集(val):304 张 - 测试集(test):152 张 |
| 标注格式 | YOLO 格式(.txt 文件,归一化坐标) |
| 兼容模型 | YOLOv5 / YOLOv6 / YOLOv8 / YOLOv11 等 |

类别信息
| 类别索引 | 类别名称 | 描述 |
|---|---|---|
| 0 | healthy(健康作物) | 表示没有受到病害影响的枸杞树区域。 |
| 1 | stressed(病害作物) | 包括点片状发病区、连片扩散区、叶片卷曲程度、病斑面积占比、初期病斑、局部黄化、大面积枯萎、组织坏死等多种病害情况。 |



目录结构(标准 YOLO 格式)
确保你的数据组织如下:
goji_blight_dataset/
├── images/
│ ├── train/ # 1083 张
│ ├── val/ # 304 张
│ └── test/ # 152 张
├── labels/
│ ├── train/ # 对应 .txt 标签
│ ├── val/
│ └── test/
└── data.yaml # 配置文件(必须)
data.yaml 配置文件
创建 goji_blight_dataset/data.yaml:
# goji_blight_dataset/data.yaml
train: ./images/train
val: ./images/val
test: ./images/test
nc: 2
names: ['healthy', 'stressed']
⚠️ 路径为相对路径,与训练脚本同级。
YOLOv8 完整训练代码(Python)
保存为 train_goji_blight.py:
# -*- coding: utf-8 -*-
""" 无人机枸杞树病害检测 - YOLOv8 训练脚本
支持:2 类目标检测(healthy / stressed)
"""
import os
from ultralytics import YOLO
import torch
# -----------------------------
# 1. 检查数据集路径是否存在
# -----------------------------
dataset_path = "goji_blight_dataset"
if not os.path.exists(dataset_path):
raise FileNotFoundError(f"❌ 数据集路径 '{dataset_path}' 不存在!请检查目录结构。")
# -----------------------------
# 2. 自动选择设备(GPU/CPU)
# -----------------------------
device = 'cuda' if torch.cuda.is_available() else 'cpu'
print(f"🚀 使用设备:{device}")
# -----------------------------
# 3. 加载预训练 YOLOv8 模型
# -----------------------------
# 推荐使用 yolov8s(平衡速度与精度),若部署到边缘设备可用 yolov8n
model = YOLO('yolov8s.pt') # 首次运行会自动下载权重
# -----------------------------
# 4. 开始训练(关键参数已优化)
# -----------------------------
results = model.train(
# 数据配置
data=os.path.join(dataset_path, 'data.yaml'), # 指向 data.yaml
# 训练参数
epochs=100, # 训练轮数(100 足够收敛)
imgsz=1280, # 输入图像尺寸(提升小病斑检出率)
batch=16, # 批大小(RTX 3060 可设 16~32)
name='goji_yolov8s_1280',
device=device,
hsv_h=,
hsv_s=,
hsv_v=,
degrees=,
translate=,
scale=,
mosaic=,
mixup=,
flipud=,
fliplr=,
patience=,
save_period=,
workers=,
cache=
)
()
()
命令行快速训练(可选)
yolo detect train \
data=goji_blight_dataset/data.yaml \
model=yolov8s.pt \
epochs=100 \
imgsz=1280 \
batch=16 \
name=goji_yolov8s_1280 \
device=0
模型评估(测试集性能)
# evaluate_model.py
from ultralytics import YOLO
# 加载最佳模型
model = YOLO('runs/detect/goji_yolov8s_1280/weights/best.pt')
# 在测试集上评估
metrics = model.val(
data='goji_blight_dataset/data.yaml',
split='test' # 指定使用 test 集
)
# 打印关键指标
print("📊 测试集评估结果:")
print(f" [email protected] : {metrics.box.map50:.4f}")
print(f" [email protected]:0.95: {metrics.box.map:.4f}")
print(f" Precision : {metrics.box.mp:.4f}")
print(f" Recall : {metrics.box.mr:.4f}")
💡 预期性能:[email protected] > 0.85(高质量航拍数据集)Recall > 0.80(避免漏检病害区域)
推理脚本(单图 + 批量)
1. 单图推理并保存结果
# infer_single.py
from ultralytics import YOLO
model = YOLO('best.pt') # 替换为你的 best.pt 路径
# 推理单张图像
results = model.predict(
source='goji_field.jpg', # 输入图像路径
conf=0.3, # 置信度阈值(病害检测可设低些)
iou=0.45, # NMS IoU 阈值
save=True, # 保存带框图像到 runs/detect/...
show=False # 不显示窗口
)
print("✅ 检测结果已保存!")
2. 批量处理并生成病害报告
# infer_batch_report.py
from ultralytics import YOLO
import os
import pandas as pd
model = YOLO('best.pt')
input_dir = 'field_images/' # 待检测图像目录
output_dir = 'detected_results/'
os.makedirs(output_dir, exist_ok=True)
report = []
for img_name in os.listdir(input_dir):
if img_name.lower().endswith(('.jpg', '.png', '.jpeg')):
img_path = os.path.join(input_dir, img_name)
results = model.predict(img_path, conf=0.3, save=True)
for r in results:
# 统计每张图的病害区域数量
stressed_count = sum(1 for cls in r.boxes.cls if int(cls) == 1)
healthy_count = len(r.boxes) - stressed_count
report.append({
'image': img_name,
'healthy_regions': healthy_count,
'stressed_regions': stressed_count,
'total_detections': len(r.boxes)
})
# 保存 CSV 报告
df = pd.DataFrame(report)
df.to_csv(os.path.join(output_dir, 'goji_health_report.csv'), index=False)
print(f"✅ 病害统计报告已生成:{output_dir}/goji_health_report.csv")


