当前位置: 首页 > news >正文

PyTorch框架——基于深度学习YOLOv5神经网络水果蔬菜检测识别系统

基于深度学习YOLOv5神经网络水果蔬菜检测识别系统,其能识别的水果蔬菜有15种,# 水果的种类 names: ['黑葡萄', '绿葡萄', '樱桃', '西瓜', '龙眼', '香蕉', '芒果', '菠萝', '柚子', '草莓', '苹果', '柑橘', '火龙果', '梨子', '花生', '黄瓜', '土豆', '大蒜', '茄子', '白萝卜', '辣椒', '胡萝卜', '花菜', '白菜', '番茄', '西蓝花', '橙子'],见如下

第一步:YOLOv5介绍

YOLOv5是一种目标检测算法,它是YOLO(You Only Look Once)系列的最新版本。YOLOv5在YOLOv4的基础上进行了改进和优化,以提高检测的准确性和速度。

YOLOv5采用了一些新的技术和方法来改进目标检测的性能。其中包括以下几个方面:

  1. 损失函数:YOLOv5使用了CIOU_Loss作为bounding box的损失函数。CIOU_Loss是一种改进的IOU_Loss,可以更好地衡量目标框的位置和大小。

  2. 非极大值抑制(NMS):YOLOv5使用NMS来抑制重叠的边界框,以减少重复检测的问题。

  3. 聚类anchors:YOLOv5使用k-means聚类算法来生成anchors,这些anchors用于检测不同尺度的目标。

总的来说,YOLOv5在YOLOv4的基础上进行了一些改进和优化,以提高目标检测的准确性和速度。

标注数据,YOLOv5的训练和测试步骤,可以参考我的这篇博客:手把手教你通过YOLOv5训练自己的目标检测模型_yolov5怎么测试自己训练的结果-CSDN博客

第二步:YOLOv5网络结构

第三步:代码展示

# Ultralytics YOLO 🚀, AGPL-3.0 licensefrom pathlib import Pathfrom ultralytics.engine.model import Model
from ultralytics.models import yolo
from ultralytics.nn.tasks import ClassificationModel, DetectionModel, OBBModel, PoseModel, SegmentationModel, WorldModel
from ultralytics.utils import ROOT, yaml_loadclass YOLO(Model):"""YOLO (You Only Look Once) object detection model."""def __init__(self, model="yolo11n.pt", task=None, verbose=False):"""Initialize YOLO model, switching to YOLOWorld if model filename contains '-world'."""path = Path(model)if "-world" in path.stem and path.suffix in {".pt", ".yaml", ".yml"}:  # if YOLOWorld PyTorch modelnew_instance = YOLOWorld(path, verbose=verbose)self.__class__ = type(new_instance)self.__dict__ = new_instance.__dict__else:# Continue with default YOLO initializationsuper().__init__(model=model, task=task, verbose=verbose)@propertydef task_map(self):"""Map head to model, trainer, validator, and predictor classes."""return {"classify": {"model": ClassificationModel,"trainer": yolo.classify.ClassificationTrainer,"validator": yolo.classify.ClassificationValidator,"predictor": yolo.classify.ClassificationPredictor,},"detect": {"model": DetectionModel,"trainer": yolo.detect.DetectionTrainer,"validator": yolo.detect.DetectionValidator,"predictor": yolo.detect.DetectionPredictor,},"segment": {"model": SegmentationModel,"trainer": yolo.segment.SegmentationTrainer,"validator": yolo.segment.SegmentationValidator,"predictor": yolo.segment.SegmentationPredictor,},"pose": {"model": PoseModel,"trainer": yolo.pose.PoseTrainer,"validator": yolo.pose.PoseValidator,"predictor": yolo.pose.PosePredictor,},"obb": {"model": OBBModel,"trainer": yolo.obb.OBBTrainer,"validator": yolo.obb.OBBValidator,"predictor": yolo.obb.OBBPredictor,},}class YOLOWorld(Model):"""YOLO-World object detection model."""def __init__(self, model="yolov8s-world.pt", verbose=False) -> None:"""Initialize YOLOv8-World model with a pre-trained model file.Loads a YOLOv8-World model for object detection. If no custom class names are provided, it assigns defaultCOCO class names.Args:model (str | Path): Path to the pre-trained model file. Supports *.pt and *.yaml formats.verbose (bool): If True, prints additional information during initialization."""super().__init__(model=model, task="detect", verbose=verbose)# Assign default COCO class names when there are no custom namesif not hasattr(self.model, "names"):self.model.names = yaml_load(ROOT / "cfg/datasets/coco8.yaml").get("names")@propertydef task_map(self):"""Map head to model, validator, and predictor classes."""return {"detect": {"model": WorldModel,"validator": yolo.detect.DetectionValidator,"predictor": yolo.detect.DetectionPredictor,"trainer": yolo.world.WorldTrainer,}}def set_classes(self, classes):"""Set classes.Args:classes (List(str)): A list of categories i.e. ["person"]."""self.model.set_classes(classes)# Remove background if it's givenbackground = " "if background in classes:classes.remove(background)self.model.names = classes# Reset method class names# self.predictor = None  # reset predictor otherwise old names remainif self.predictor:self.predictor.model.names = classes

第四步:统计训练过程的一些指标,相关指标都有

第五步:运行(支持图片、文件夹、摄像头和视频功能)

第六步:整个工程的内容

有训练代码和训练好的模型以及训练过程,提供数据,提供GUI界面代码

项目完整文件下载请见演示与介绍视频的简介处给出:➷➷➷

PyTorch框架——基于深度学习YOLOv5神经网络水果蔬菜检测识别系统_哔哩哔哩_bilibili

http://www.lryc.cn/news/521705.html

相关文章:

  • Redisson中红锁(RedLock)的实现
  • 小结:路由器和交换机的指令对比
  • 使用yarn命令创建Vue3项目
  • Three.js+Vue3+Vite应用lil-GUI调试开发3D效果(三)
  • K8S集群常用命令
  • 【优先算法】滑动窗口--(结合例题讲解解题思路)(C++)
  • mayavi -> python 3D可视化工具Mayavi的安装
  • 【C++】B2112 石头剪子布
  • 【Vue】vue3 video 保存视频进度,每次进入加载上次的视频进度
  • C# 25Dpoint
  • 如何制作一个高质量的 Dockerfile 镜像:从入门到实践
  • Linux 机器学习
  • 青少年编程与数学 02-006 前端开发框架VUE 25课题、UI数据
  • css实现响应式详解
  • python-应用自动化操作方法集合
  • mac地址是用来做什么的
  • 【Compose multiplatform教程】05 IOS环境编译
  • 3D滤波器处理遥感tif图像
  • fisco bcosV3 Table智能合约开发
  • leetcode刷题记录(四十八)——128. 最长连续序列
  • HTML中如何保留字符串的空白符和换行符号的效果
  • Linux入门——环境基础开发(上)
  • c++类和对象---下
  • 组件中的Props
  • 并行服务、远程SSH无法下载conda,报错404
  • 迅为RK3568开发板篇OpenHarmony配置HDF驱动控制LED-新增 topeet子系统-编写 bundle.json文件
  • 深度剖析RabbitMQ:从基础组件到管理页面详解
  • usb通过hdc连接鸿蒙next的常用指令
  • 【落羽的落羽 C语言篇】文件操作
  • RNN之:LSTM 长短期记忆模型-结构-理论详解-及实战(Matlab向)