news 2026/4/17 22:29:03

苹果缺陷检测和识别2:基于深度学习YOLO26神经网络实现苹果缺陷检测和识别(含训练代码和数据集)

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
苹果缺陷检测和识别2:基于深度学习YOLO26神经网络实现苹果缺陷检测和识别(含训练代码和数据集)

基于深度学习YOLO26神经网络实现苹果缺陷检测和识别,其能识别检测出2种苹果缺陷检测:names: ['good_apple','bad_apple']

具体图片见如下:

第一步:YOLO26介绍

YOLO26采用了端到端无NMS推理,直接生成预测结果,无需非极大值抑制(NMS)后处理。这种设计减少了延迟,简化了集成,并提高了部署效率。此外,YOLO26移除了分布焦点损失(DFL),从而增强了硬件兼容性,特别是在边缘设备上的表现。

模型还引入了ProgLoss小目标感知标签分配(STAL),显著提升了小目标检测的精度。这对于物联网、机器人技术和航空影像等应用至关重要。同时,YOLO26采用了全新的MuSGD优化器,结合了SGD和Muon优化技术,提供更稳定的训练和更快的收敛速度。

第二步:YOLO26网络结构

第三步:代码展示

# Ultralytics YOLO 🚀, AGPL-3.0 license from pathlib import Path from 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_load class 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 model new_instance = YOLOWorld(path, verbose=verbose) self.__class__ = type(new_instance) self.__dict__ = new_instance.__dict__ else: # Continue with default YOLO initialization super().__init__(model=model, task=task, verbose=verbose) @property def 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 default COCO 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 names if not hasattr(self.model, "names"): self.model.names = yaml_load(ROOT / "cfg/datasets/coco8.yaml").get("names") @property def 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 given background = " " if background in classes: classes.remove(background) self.model.names = classes # Reset method class names # self.predictor = None # reset predictor otherwise old names remain if self.predictor: self.predictor.model.names = classes

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

第五步:运行预测代码

#coding:utf-8 from ultralytics import YOLO import cv2 # 所需加载的模型目录 path = 'models/best.pt' # 需要检测的图片地址 img_path = "TestFiles/000353.jpg" # 加载预训练模型 # conf 0.25 object confidence threshold for detection # iou 0.7 intersection over union (IoU) threshold for NMS model = YOLO(path, task='detect') results = model.predict(img_path, iou=0.5) # 检测图片 res = results[0].plot() cv2.imshow("YOLO26 Detection", res) cv2.waitKey(0)

第六步:整个工程的内容

包含苹果缺陷数据集、训练代码和预测代码

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

https://www.bilibili.com/video/BV1e9zeBQEy8/

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/4/16 11:17:44

告别肝帝模式?这款AI助手让你躺着变强

告别肝帝模式?这款AI助手让你躺着变强 【免费下载链接】yysScript 阴阳师脚本 支持御魂副本 双开 项目地址: https://gitcode.com/gh_mirrors/yy/yysScript 在阴阳师的世界里,每一位玩家都渴望拥有强大的式神和顶级的御魂,但传统的手动…

作者头像 李华
网站建设 2026/4/15 16:44:21

阿里Z-Image开源镜像下载慢?国内加速部署教程推荐

阿里Z-Image开源镜像下载慢?国内加速部署教程推荐 你是不是也遇到过这样的情况:看到阿里新发布的Z-Image模型,兴奋地点开下载链接,结果进度条卡在15%一动不动,刷新三次后终于断连——不是网络问题,是官方源…

作者头像 李华
网站建设 2026/4/14 21:31:11

探索赛马娘汉化插件的隐藏玩法:从入门到精通的实用秘诀

探索赛马娘汉化插件的隐藏玩法:从入门到精通的实用秘诀 【免费下载链接】Trainers-Legend-G 赛马娘本地化插件「Trainers Legend G」 项目地址: https://gitcode.com/gh_mirrors/tr/Trainers-Legend-G 当你在赛马娘的世界中因语言障碍而错失精彩剧情&#xf…

作者头像 李华
网站建设 2026/4/15 9:18:01

阿里通义Z-Image-Turbo部署疑问:如何确认服务是否正常运行?

阿里通义Z-Image-Turbo部署疑问:如何确认服务是否正常运行? 你刚跑完 bash scripts/start_app.sh,终端刷出一串日志,浏览器打开 http://localhost:7860 却显示“无法连接”,或者页面加载后一片空白——这时候别急着重…

作者头像 李华
网站建设 2026/4/16 12:59:46

Python金融数据接口与量化分析实战指南:从入门到精通

Python金融数据接口与量化分析实战指南:从入门到精通 【免费下载链接】akshare 项目地址: https://gitcode.com/gh_mirrors/aks/akshare 在金融科技快速发展的今天,高效获取和分析金融数据成为量化投资和市场研究的关键环节。本文将系统介绍如何…

作者头像 李华
网站建设 2026/4/11 20:05:42

用ms-swift做个性化AI?这篇就够了!

用ms-swift做个性化AI?这篇就够了! 你是不是也遇到过这些问题:想给大模型加点“个性”,让它更懂你的业务场景,但微调门槛太高?试过LoRA却卡在环境配置上,连第一步都走不通?看中了Qw…

作者头像 李华