一、项目介绍
摘要
本项目基于前沿的YOLOv10目标检测算法,开发了一套高精度的猫狗品种识别检测系统,能够区分37种不同的猫犬品种(包括12种猫品种和25种犬品种)。系统采用包含13,983张图像的专业数据集进行训练和验证,其中训练集12,879张,验证集736张,测试集368张。该识别系统能够在复杂场景下准确识别并分类不同品种的猫狗,可广泛应用于宠物医院智能诊断、宠物商店管理、动物收容所自动化登记、宠物社交平台内容分类以及智能家居宠物识别等多个领域,为宠物相关行业提供智能化解决方案。
项目意义
宠物行业智能化转型:推动传统宠物相关行业向自动化、智能化方向发展,提升服务效率和准确性。
精准宠物管理:帮助宠物医院、美容院等机构快速识别宠物品种,提供更有针对性的服务。
动物收容所效率提升:自动识别流浪动物品种,简化登记流程,提高领养匹配效率。
宠物社交平台增强:为宠物社交平台提供自动内容分类和标签生成功能,改善用户体验。
智能家居集成:可与智能家居系统结合,实现基于宠物品种的个性化设置(如自动喂食器调整)。
学术研究价值:为细粒度图像识别领域提供新的应用案例和技术参考。
动物保护应用:辅助识别特定受保护品种,支持野生动物保护和非法贸易监管工作。
技术验证意义:验证YOLOv10在多类别细粒度物体检测中的性能表现,为后续研究提供基准。
目录
一、项目介绍
摘要
项目意义
二、项目功能展示
系统功能
图片检测
视频检测
摄像头实时检测
三、数据集介绍
数据集概述
数据集特点
数据集配置文件
数据集制作流程
四、项目环境配置
创建虚拟环境
pycharm中配置anaconda
安装所需要库
五、模型训练
训练代码
训练结果
六、核心代码
七、项目源码(视频下方简介内)
基于深度学习YOLOv10的猫狗品种识别检测系统(YOLOv10+YOLO数据集+UI界面+Python项目源码+模型)_哔哩哔哩_bilibili
基于深度学习YOLOv10的猫狗品种识别检测系统(YOLOv10+YOLO数据集+UI界面+Python项目源码+模型)
二、项目功能展示
系统功能
✅图片检测:可对图片进行检测,返回检测框及类别信息。
✅视频检测:支持视频文件输入,检测视频中每一帧的情况。
✅摄像头实时检测:连接USB 摄像头,实现实时监测。
✅参数实时调节(置信度和IoU阈值)
图片检测
该功能允许用户通过单张图片进行目标检测。输入一张图片后,YOLO模型会实时分析图像,识别出其中的目标,并在图像中框出检测到的目标,输出带有目标框的图像。
视频检测
视频检测功能允许用户将视频文件作为输入。YOLO模型将逐帧分析视频,并在每一帧中标记出检测到的目标。最终结果可以是带有目标框的视频文件或实时展示,适用于视频监控和分析等场景。
摄像头实时检测
该功能支持通过连接摄像头进行实时目标检测。YOLO模型能够在摄像头拍摄的实时视频流中进行目标检测,实时识别并显示检测结果。此功能非常适用于安防监控、无人驾驶、智能交通等应用,提供即时反馈。
核心特点:
- 高精度:基于YOLO模型,提供精确的目标检测能力,适用于不同类型的图像和视频。
- 实时性:特别优化的算法使得实时目标检测成为可能,无论是在视频还是摄像头实时检测中,响应速度都非常快。
- 批量处理:支持高效的批量图像和视频处理,适合大规模数据分析。
三、数据集介绍
数据集概述
本项目构建了一个大规模的猫狗品种识别专用数据集,共包含37个品种(12猫+25狗),总样本量达13,983张高质量图像。数据集按照8:1:1的比例划分为训练集(12,879张)、验证集(736张)和测试集(368张),确保模型开发和评估的科学性。数据集覆盖了各种姿态、年龄、毛色和场景下的猫狗图像,每张图像都经过专业标注和严格质检。
数据集特点
品种覆盖全面:
包含12个热门猫品种:从阿比西尼亚猫到斯芬克斯猫
涵盖25个常见犬种:从哈巴狗到约克夏梗
每个品种包含300-500张样本图像,确保数据平衡
图像多样性丰富:
多种姿态:站立、坐卧、奔跑、睡觉等
不同年龄段:幼崽、成年、老年
各种光照条件:自然光、室内光、逆光等
复杂背景:家庭环境、户外场景、专业摄影棚
多角度拍摄:正面、侧面、俯视、特写
标注精细专业:
每个目标都使用矩形框精确标注
品种标签由动物学专家验证确认
对相似品种(如英国短毛猫vs俄罗斯蓝猫)进行特别标注
包含部分遮挡、截断等困难样本的标注
数据质量保障:
所有图像分辨率高
经过三阶段质量筛选流程
由专业兽医团队参与数据校验
定期更新和维护数据集
评估维度全面:
独立的测试集用于最终模型评估
包含跨品种难例分析子集
提供不同场景下的性能评估指标
数据集配置文件
数据集采用标准YOLO格式组织:
train: F:\猫狗品种识别检测数据集\train\images val: F:\猫狗品种识别检测数据集\valid\images test: F:\猫狗品种识别检测数据集\test\images nc: 37 names: ['cat-Abyssinian', 'cat-Bengal', 'cat-Birman', 'cat-Bombay', 'cat-British_Shorthair', 'cat-Egyptian_Mau', 'cat-Maine_Coon', 'cat-Persian', 'cat-Ragdoll', 'cat-Russian_Blue', 'cat-Siamese', 'cat-Sphynx', 'dog-american_bulldog', 'dog-american_pit_bull_terrier', 'dog-basset_hound', 'dog-beagle', 'dog-boxer', 'dog-chihuahua', 'dog-english_cocker_spaniel', 'dog-english_setter', 'dog-german_shorthaired', 'dog-great_pyrenees', 'dog-havanese', 'dog-japanese_chin', 'dog-keeshond', 'dog-leonberger', 'dog-miniature_pinscher', 'dog-newfoundland', 'dog-pomeranian', 'dog-pug', 'dog-saint_bernard', 'dog-samoyed', 'dog-scottish_terrier', 'dog-shiba_inu', 'dog-staffordshire_bull_terrier', 'dog-wheaten_terrier', 'dog-yorkshire_terrier']数据集制作流程
需求分析与规划阶段:
调研宠物市场需求,确定核心品种清单
与兽医专家合作制定品种分类标准
设计数据采集方案,确定样本量和分布
数据采集阶段:
专业摄影师团队实地拍摄(宠物展、医院、家庭)
从授权图库获取高质量样本
与宠物育种机构合作获取稀有品种图像
网络爬虫获取补充样本(严格版权审查)
设计多场景拍摄脚本确保多样性
数据清洗与预处理:
去除低质量、重复或无关图像
统一调整图像尺寸和格式(保留高分辨率)
对敏感信息进行模糊处理
建立图像质量评分体系进行分级筛选
专业标注流程:
第一阶段:由普通标注员进行初步边界框标注
第二阶段:专业宠物美容师验证品种标签
第三阶段:兽医专家团队复核争议样本
使用CVAT标注工具进行高效协作标注
数据集划分与增强:
按品种分层抽样确保分布均衡
采用8:1:1比例划分训练/验证/测试集
应用智能数据增强策略:
几何变换(旋转、缩放、翻转)
色彩空间调整(亮度、对比度、饱和度)
随机遮挡模拟(增强鲁棒性)
背景替换与合成
质量控制体系:
建立三级质量检查流程(标注员自查、组长复查、专家抽查)
开发自动化校验工具检测标注一致性
定期组织标注标准培训与考核
建立错误样本追溯与修正机制
持续维护与扩展:
定期收集用户反馈识别缺失样本
每季度新增品种和样本
建立数据版本控制体系
开发自动化数据清洗管道
四、项目环境配置
创建虚拟环境
首先新建一个Anaconda环境,每个项目用不同的环境,这样项目中所用的依赖包互不干扰。
终端输入
conda create -n yolov10 python==3.9
激活虚拟环境
conda activate yolov10
安装cpu版本pytorch
pip install torch torchvision torchaudio
pycharm中配置anaconda
安装所需要库
pip install -r requirements.txt
五、模型训练
训练代码
from ultralytics import YOLOv10 model_path = 'yolov10s.pt' data_path = 'datasets/data.yaml' if __name__ == '__main__': model = YOLOv10(model_path) results = model.train(data=data_path, epochs=500, batch=64, device='0', workers=0, project='runs/detect', name='exp', )根据实际情况更换模型 yolov10n.yaml (nano):轻量化模型,适合嵌入式设备,速度快但精度略低。 yolov10s.yaml (small):小模型,适合实时任务。 yolov10m.yaml (medium):中等大小模型,兼顾速度和精度。 yolov10b.yaml (base):基本版模型,适合大部分应用场景。 yolov10l.yaml (large):大型模型,适合对精度要求高的任务。
--batch 64:每批次64张图像。--epochs 500:训练500轮。--datasets/data.yaml:数据集配置文件。--weights yolov10s.pt:初始化模型权重,yolov10s.pt是预训练的轻量级YOLO模型。
训练结果
六、核心代码
import sys import cv2 import numpy as np from PyQt5.QtWidgets import QApplication, QMessageBox, QFileDialog from PyQt5.QtCore import QThread, pyqtSignal from ultralytics import YOLOv10 from UiMain import UiMainWindow import time import os class DetectionThread(QThread): frame_received = pyqtSignal(np.ndarray, np.ndarray, list) # 原始帧, 检测帧, 检测结果 finished_signal = pyqtSignal() # 线程完成信号 def __init__(self, model, source, conf, iou, parent=None): super().__init__(parent) self.model = model self.source = source self.conf = conf self.iou = iou self.running = True def run(self): try: if isinstance(self.source, int) or self.source.endswith(('.mp4', '.avi', '.mov')): # 视频或摄像头 cap = cv2.VideoCapture(self.source) while self.running and cap.isOpened(): ret, frame = cap.read() if not ret: break # 保存原始帧 original_frame = frame.copy() # 检测 results = self.model(frame, conf=self.conf, iou=self.iou) annotated_frame = results[0].plot() # 提取检测结果 detections = [] for result in results: for box in result.boxes: class_id = int(box.cls) class_name = self.model.names[class_id] confidence = float(box.conf) x, y, w, h = box.xywh[0].tolist() detections.append((class_name, confidence, x, y)) # 发送信号 self.frame_received.emit( cv2.cvtColor(original_frame, cv2.COLOR_BGR2RGB), cv2.cvtColor(annotated_frame, cv2.COLOR_BGR2RGB), detections ) # 控制帧率 time.sleep(0.03) # 约30fps cap.release() else: # 图片 frame = cv2.imread(self.source) if frame is not None: original_frame = frame.copy() results = self.model(frame, conf=self.conf, iou=self.iou) annotated_frame = results[0].plot() # 提取检测结果 detections = [] for result in results: for box in result.boxes: class_id = int(box.cls) class_name = self.model.names[class_id] confidence = float(box.conf) x, y, w, h = box.xywh[0].tolist() detections.append((class_name, confidence, x, y)) self.frame_received.emit( cv2.cvtColor(original_frame, cv2.COLOR_BGR2RGB), cv2.cvtColor(annotated_frame, cv2.COLOR_BGR2RGB), detections ) except Exception as e: print(f"Detection error: {e}") finally: self.finished_signal.emit() def stop(self): self.running = False class MainWindow(UiMainWindow): def __init__(self): super().__init__() # 初始化模型 self.model = None self.detection_thread = None self.current_image = None self.current_result = None self.video_writer = None self.is_camera_running = False self.is_video_running = False self.last_detection_result = None # 新增:保存最后一次检测结果 # 连接按钮信号 self.image_btn.clicked.connect(self.detect_image) self.video_btn.clicked.connect(self.detect_video) self.camera_btn.clicked.connect(self.detect_camera) self.stop_btn.clicked.connect(self.stop_detection) self.save_btn.clicked.connect(self.save_result) # 初始化模型 self.load_model() def load_model(self): try: model_name = self.model_combo.currentText() self.model = YOLOv10(f"{model_name}.pt") # 自动下载或加载本地模型 self.update_status(f"模型 {model_name} 加载成功") except Exception as e: QMessageBox.critical(self, "错误", f"模型加载失败: {str(e)}") self.update_status("模型加载失败") def detect_image(self): if self.detection_thread and self.detection_thread.isRunning(): QMessageBox.warning(self, "警告", "请先停止当前检测任务") return file_path, _ = QFileDialog.getOpenFileName( self, "选择图片", "", "图片文件 (*.jpg *.jpeg *.png *.bmp)") if file_path: self.clear_results() self.current_image = cv2.imread(file_path) self.current_image = cv2.cvtColor(self.current_image, cv2.COLOR_BGR2RGB) self.display_image(self.original_image_label, self.current_image) # 创建检测线程 conf = self.confidence_spinbox.value() iou = self.iou_spinbox.value() self.detection_thread = DetectionThread(self.model, file_path, conf, iou) self.detection_thread.frame_received.connect(self.on_frame_received) self.detection_thread.finished_signal.connect(self.on_detection_finished) self.detection_thread.start() self.update_status(f"正在检测图片: {os.path.basename(file_path)}") def detect_video(self): if self.detection_thread and self.detection_thread.isRunning(): QMessageBox.warning(self, "警告", "请先停止当前检测任务") return file_path, _ = QFileDialog.getOpenFileName( self, "选择视频", "", "视频文件 (*.mp4 *.avi *.mov)") if file_path: self.clear_results() self.is_video_running = True # 初始化视频写入器 cap = cv2.VideoCapture(file_path) frame_width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) frame_height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) fps = cap.get(cv2.CAP_PROP_FPS) cap.release() # 创建保存路径 save_dir = "results" os.makedirs(save_dir, exist_ok=True) timestamp = time.strftime("%Y%m%d_%H%M%S") save_path = os.path.join(save_dir, f"result_{timestamp}.mp4") fourcc = cv2.VideoWriter_fourcc(*'mp4v') self.video_writer = cv2.VideoWriter(save_path, fourcc, fps, (frame_width, frame_height)) # 创建检测线程 conf = self.confidence_spinbox.value() iou = self.iou_spinbox.value() self.detection_thread = DetectionThread(self.model, file_path, conf, iou) self.detection_thread.frame_received.connect(self.on_frame_received) self.detection_thread.finished_signal.connect(self.on_detection_finished) self.detection_thread.start() self.update_status(f"正在检测视频: {os.path.basename(file_path)}") def detect_camera(self): if self.detection_thread and self.detection_thread.isRunning(): QMessageBox.warning(self, "警告", "请先停止当前检测任务") return self.clear_results() self.is_camera_running = True # 创建检测线程 (默认使用摄像头0) conf = self.confidence_spinbox.value() iou = self.iou_spinbox.value() self.detection_thread = DetectionThread(self.model, 0, conf, iou) self.detection_thread.frame_received.connect(self.on_frame_received) self.detection_thread.finished_signal.connect(self.on_detection_finished) self.detection_thread.start() self.update_status("正在从摄像头检测...") def stop_detection(self): if self.detection_thread and self.detection_thread.isRunning(): self.detection_thread.stop() self.detection_thread.quit() self.detection_thread.wait() if self.video_writer: self.video_writer.release() self.video_writer = None self.is_camera_running = False self.is_video_running = False self.update_status("检测已停止") def on_frame_received(self, original_frame, result_frame, detections): # 更新原始图像和结果图像 self.display_image(self.original_image_label, original_frame) self.display_image(self.result_image_label, result_frame) # 保存当前结果帧用于后续保存 self.last_detection_result = result_frame # 新增:保存检测结果 # 更新表格 self.clear_results() for class_name, confidence, x, y in detections: self.add_detection_result(class_name, confidence, x, y) # 保存视频帧 if self.video_writer: self.video_writer.write(cv2.cvtColor(result_frame, cv2.COLOR_RGB2BGR)) def on_detection_finished(self): if self.video_writer: self.video_writer.release() self.video_writer = None self.update_status("视频检测完成,结果已保存") elif self.is_camera_running: self.update_status("摄像头检测已停止") else: self.update_status("图片检测完成") def save_result(self): if not hasattr(self, 'last_detection_result') or self.last_detection_result is None: QMessageBox.warning(self, "警告", "没有可保存的检测结果") return save_dir = "results" os.makedirs(save_dir, exist_ok=True) timestamp = time.strftime("%Y%m%d_%H%M%S") if self.is_camera_running or self.is_video_running: # 保存当前帧为图片 save_path = os.path.join(save_dir, f"snapshot_{timestamp}.jpg") cv2.imwrite(save_path, cv2.cvtColor(self.last_detection_result, cv2.COLOR_RGB2BGR)) self.update_status(f"截图已保存: {save_path}") else: # 保存图片检测结果 save_path = os.path.join(save_dir, f"result_{timestamp}.jpg") cv2.imwrite(save_path, cv2.cvtColor(self.last_detection_result, cv2.COLOR_RGB2BGR)) self.update_status(f"检测结果已保存: {save_path}") def closeEvent(self, event): self.stop_detection() event.accept() if __name__ == "__main__": app = QApplication(sys.argv) # 设置应用程序样式 app.setStyle("Fusion") # 创建并显示主窗口 window = MainWindow() window.show() sys.exit(app.exec_())七、项目源码(视频下方简介内)
完整全部资源文件(包括测试图片、视频,py文件,训练数据集、训练代码、界面代码等),这里已打包上传至博主的面包多平台,见可参考博客与视频,已将所有涉及的文件同时打包到里面,点击即可运行,完整文件截图如下:
基于深度学习YOLOv10的猫狗品种识别检测系统(YOLOv10+YOLO数据集+UI界面+Python项目源码+模型)_哔哩哔哩_bilibili
基于深度学习YOLOv10的猫狗品种识别检测系统(YOLOv10+YOLO数据集+UI界面+Python项目源码+模型)