基于YOLOv8深度學習的學生課堂行為檢測識別系統,其能識別三種學生課堂行為:names: ['舉手', '讀書', '寫字']
具體圖片見如下:
第一步:YOLOv8介紹
YOLOv8?是 ultralytics 公司在 2023 年 1月 10 號開源的 YOLOv5 的下一個重大更新版本,目前支持圖像分類、物體檢測和實例分割任務,在還沒有開源時就收到了用戶的廣泛關注。
YOLOv8 算法的核心特性和改動可以歸結為如下:
提供了一個全新的 SOTA 模型,包括 P5 640 和 P6 1280 分辨率的目標檢測網絡和基于 YOLACT 的實例分割模型。和 YOLOv5 一樣,基于縮放系數也提供了 N/S/M/L/X 尺度的不同大小模型,用于滿足不同場景需求
Backbone:
骨干網絡和 Neck 部分可能參考了 YOLOv7 ELAN 設計思想,將 YOLOv5 的 C3 結構換成了梯度流更豐富的 C2f 結構,并對不同尺度模型調整了不同的通道數。
屬于對模型結構精心微調,不再是無腦一套參數應用所有模型,大幅提升了模型性能。不過這個 C2f 模塊中存在 Split 等操作對特定硬件部署沒有之前那么友好了
Head: Head部分較yolov5而言有兩大改進:1)換成了目前主流的解耦頭結構(Decoupled-Head),將分類和檢測頭分離 2)同時也從 Anchor-Based 換成了 Anchor-Free
Loss :1) YOLOv8拋棄了以往的IOU匹配或者單邊比例的分配方式,而是使用了Task-Aligned Assigner正負樣本匹配方式。2)并引入了 Distribution Focal Loss(DFL)
Train:訓練的數據增強部分引入了 YOLOX 中的最后 10 epoch 關閉 Mosiac 增強的操作,可以有效地提升精度
第二步:YOLOv8網絡結構
第三步:代碼展示
# 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框架——基于深度學習YOLOv8神經網絡學生課堂行為檢測識別系統_嗶哩嗶哩_bilibili
?