当前位置: 首页> 科技> 名企 > 东莞横沥三江工业区_网站推广的方法及特点_淘宝关键词top排行榜_现在最火的推广平台

东莞横沥三江工业区_网站推广的方法及特点_淘宝关键词top排行榜_现在最火的推广平台

时间:2025/7/11 20:25:01来源:https://blog.csdn.net/ALiLiLiYa/article/details/142688188 浏览次数:0次
东莞横沥三江工业区_网站推广的方法及特点_淘宝关键词top排行榜_现在最火的推广平台

 

大豆虫害检测数据集 1800张 大豆虫害 带标注 voc yolo

大豆虫害检测数据集

名称

大豆虫害检测数据集 (Soybean Pest Detection Dataset)

规模
  • 图像数量:共1825张图像。
  • 类别:包括12种不同的大豆害虫,涵盖了从幼虫到成虫的不同生长阶段。
数据划分
  • 训练集 (Train):通常占总数据的80%左右,约1460张图像。
  • 验证集 (Validation):通常占总数据的20%左右,约365张图像。
数据特点

  • 多样化的目标类型:数据集包含了多种常见和特定的大豆害虫,有助于全面了解不同类型的害虫。
  • 详细的标注信息:每张图片都带有精确的边界框标注,适用于VOC和YOLO格式。
  • 高分辨率图像:图像质量较高,有助于识别细小的害虫特征。
  • 实际应用场景:可用于农业领域的害虫监测、防治以及自动化管理系统的开发。
应用领域

  • 农业监测:帮助农民及时发现并处理大豆田中的害虫问题。
  • 智能农业:结合物联网技术,实现自动化的害虫监测和预警系统。
  • 科研应用:为昆虫学、生态学以及计算机视觉研究提供宝贵的数据资源。
  • 害虫管理:支持精准农业中的害虫管理和防控策略制定。
分类说明
  • Euschistus heros_ ninfa(绿蝽若虫):(606张, 858个标注)
  • Euschistus heros_ adulto(绿蝽成虫):(654张, 891个标注)
  • Nezara viridula_ adulto(绿盲蝽成虫):(132张, 137个标注)
  • Diabrotica speciosa(玉米象甲):(94张, 97个标注)
  • Spodoptera albula(斜纹夜蛾):(227张, 228个标注)
  • Gastropoda(蜗牛):(170张, 173个标注)
  • Anticarsia gemmatalis(大豆尺蠖):(123张, 123个标注)
  • Nezara viridula_ ninfa(绿盲蝽若虫):(22张, 24个标注)
  • Coccinellidae(瓢虫):(112张, 115个标注)
  • Edessa meditabunda(红腹缘蝽):(115张, 115个标注)
  • Lagria villosa(毛毛虫):(69张, 69个标注)
  • Rhammatocerus schistocercoides(蝗虫):(38张, 38个标注)
总数

  • 图片总数:1825张
  • 标注总数:2868个
  • 类别数 (nc):12类
1. 安装依赖库

首先,确保安装了必要的依赖库。可以在项目目录中的requirements.txt文件中列出这些依赖库,然后运行以下命令进行安装:

pip install -r requirements.txt

requirements.txt 文件内容示例:

torch==1.10.0
torchvision==0.11.1
pandas==1.3.4
cv2
albumentations==1.1.0
pycocotools
2. 创建数据集

定义一个自定义的数据集类,并创建数据加载器。

import os
import pandas as pd
import cv2
from torch.utils.data import Dataset, DataLoader
from torchvision.transforms import Compose, ToTensor, Normalize, Resize
from albumentations import HorizontalFlip, RandomBrightnessContrast, ShiftScaleRotate, BboxFromMasks, BBoxFormatPASCAL
from albumentations.pytorch import ToTensorV2# 自定义数据集类
class SoybeanPestDataset(Dataset):def __init__(self, data_root, annotations_file, transforms=None):self.data_root = data_rootself.annotations = pd.read_csv(annotations_file)self.transforms = transformsdef __len__(self):return len(self.annotations)def __getitem__(self, idx):img_path = os.path.join(self.data_root, self.annotations.iloc[idx, 0])image = cv2.imread(img_path)bboxes = self.annotations.iloc[idx, 1:].values.reshape(-1, 4)  # bounding box coordinateslabels = self.annotations.columns[1:]if self.transforms:augmented = self.transforms(image=image, bboxes=bboxes, class_labels=labels)image = augmented['image']bboxes = augmented['bboxes']return image, bboxes, labels# 图像预处理
def get_transforms():"""构建预处理函数"""_transform = [Resize(height=416, width=416, interpolation=cv2.INTER_LINEAR),HorizontalFlip(p=0.5),RandomBrightnessContrast(p=0.2),ShiftScaleRotate(p=0.5, shift_limit=0.0625, scale_limit=0.2, rotate_limit=15),Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),ToTensorV2(),BboxFromMasks(format=BBoxFormatPASCAL)]return Compose(_transform)# 创建数据加载器
train_dataset = SoybeanPestDataset(data_root='path_to_your_train_images',annotations_file='path_to_your_train_annotations.csv',transforms=get_transforms()
)
val_dataset = SoybeanPestDataset(data_root='path_to_your_val_images',annotations_file='path_to_your_val_annotations.csv',transforms=get_transforms()
)train_loader = DataLoader(train_dataset, batch_size=32, shuffle=True, num_workers=4)
val_loader = DataLoader(val_dataset, batch_size=32, shuffle=False, num_workers=4)
3. 训练模型

可以使用YOLOv5或Mask R-CNN等模型进行训练。

对于YOLOv5:

!git clone https://github.com/ultralytics/yolov5  # 下载YOLOv5代码仓库
cd yolov5# 使用YOLOv5训练模型
python train.py --weights yolov5s.pt --data path_to_your_data.yaml --name soybean_pest_detection --img 416 --batch 16 --epochs 100 --device 0
  • 数据配置文件:创建一个名为data.yaml的数据配置文件,其中包含训练和验证数据集的信息。
train: path_to_your_train_images
val: path_to_your_val_images
nc: 12
names: ['Euschistus heros_ ninfa', 'Euschistus_ heros_ adulto', 'Nezara_ viridula_ adulto', 'Diabrotica_ speciosa', 'Spodoptera albula', 'Gastropoda', 'Anticarsia gemmatalis', 'Nezara_ viridula_ ninfa', 'Coccinellidae', 'Edessa_ meditabunda', 'Lagria_ villosa', 'Rhammatocerus_ schistocercoides']

对于Mask R-CNN:

# 使用Detectron2训练Mask R-CNN
!git clone https://github.com/facebookresearch/detectron2
cd detectron2
python setup.py build develop# 设置训练配置
from detectron2.config import get_cfg
from detectron2.engine import DefaultTrainer
from detectron2 import model_zoocfg = get_cfg()
cfg.merge_from_file(model_zoo.get_config_file("COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml"))
cfg.DATASETS.TRAIN = ("train",)
cfg.DATASETS.TEST = ()
cfg.DATALOADER.NUM_WORKERS = 2
cfg.MODEL.WEIGHTS = model_zoo.get_checkpoint_url("COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml")  # Let training initialize from model zoo
cfg.SOLVER.IMS_PER_BATCH = 2
cfg.SOLVER.BASE_LR = 0.00025  # pick a good LR
cfg.SOLVER.MAX_ITER = 30000    # 300 iterations seems good enough for this toy dataset; you may need to train longer for a practical dataset
cfg.MODEL.ROI_HEADS.BATCH_SIZE_PER_IMAGE = 128   # faster, and good enough for this toy dataset (default: 512)
cfg.MODEL.ROI_HEADS.NUM_CLASSES = 12  # 12 classes (soybean pests)os.makedirs(cfg.OUTPUT_DIR, exist_ok=True)
trainer = DefaultTrainer(cfg)
trainer.resume_or_load(resume=False)
trainer.train()
4. 调整模型
  • 超参数调整:根据实际情况调整学习率、批大小等超参数。
  • 数据增强:增加旋转、缩放、翻转等数据增强策略以提高模型鲁棒性。
5. 预测与评估

完成训练后,可以使用训练好的模型对新的图片进行预测和评估。

# YOLOv5 模型预测
from models.experimental import attempt_load
from utils.datasets import ImageList
from utils.torch_utils import select_device, time_synchronized
from utils.plots import plot_results# 加载模型
device = select_device('0')
model = attempt_load('runs/train/exp/weights/best.pt', map_location=device)  # 加载最佳权重# 新建数据集
test_dataset = ImageList('path_to_test_images', transform=get_transforms())
test_loader = DataLoader(test_dataset, batch_size=1, shuffle=False, num_workers=4)# 进行预测
results = []
with torch.no_grad():t0 = time_synchronized()for i, (x, path) in enumerate(test_loader):x = x.to(device)  # 将输入图像转换到设备上pred = model(x)[0]  # 获取预测结果results += plot_results(pred, path, save=True, show=False)  # 绘制预测结果图print(f'Time {time_synchronized("start") - t0:.3f} s')# Mask R-CNN 模型预测
from detectron2.utils.visualizer import Visualizer
from detectron2.data import MetadataCatalogfor d in random.sample(dataset_dicts, 3):im = cv2.imread(d["file_name"])outputs = predictor(im)v = Visualizer(im[:, :, ::-1], MetadataCatalog.get(cfg.DATASETS.TRAIN[0]), scale=1.2)out = v.draw_instance_predictions(outputs["instances"].to("cpu"))cv2.imshow(out.get_image()[:, :, ::-1])

注意:以上代码仅供参考,请根据实际情况修改路径和参数。

关键字:东莞横沥三江工业区_网站推广的方法及特点_淘宝关键词top排行榜_现在最火的推广平台

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: