问小白 wenxiaobai
资讯
历史
科技
环境与自然
成长
游戏
财经
文学与艺术
美食
健康
家居
文化
情感
汽车
三农
军事
旅行
运动
教育
生活
星座命理

基于YOLOv5的驾驶员疲劳驾驶行为检测系统

创作时间:
作者:
@小白创作中心

基于YOLOv5的驾驶员疲劳驾驶行为检测系统

引用
CSDN
1.
https://blog.csdn.net/m0_63774211/article/details/136547398

疲劳驾驶是导致交通事故的重要原因之一,每年都会造成大量人员伤亡和财产损失。随着信息技术的发展,现在可以通过驾驶员的眼部和嘴部动作来实时监测其疲劳状态,从而及时提醒驾驶员避免疲劳驾驶。

数据集介绍

本文使用的数据集包含2914张图像,主要关注驾驶员的疲劳状态,具体分为四个类别:闭眼(closed_eye)、闭嘴(closed_mouth)、睁眼(open_eye)和张嘴(open_mouth)。

基于YOLOv5的疲劳驾驶行为检测

修改配置文件fatigue.yaml

为了使用YOLOv5进行疲劳驾驶行为检测,需要对配置文件进行相应的修改。以下是修改后的配置文件内容:

# PASCAL VOC dataset http://host.robots.ox.ac.uk/pascal/VOC/
# Download command: bash ./data/get_voc.sh
# Train command: python train.py --data voc.yaml
# Dataset should be placed next to yolov5 folder:
#   /parent_folder
#     /VOC
#     /yolov5
# train and val datasets (image directory or *.txt file with image paths)
train: ./data/fatigue/train.txt # 16551 images
val: ./data/fatigue/val.txt  # 4952 images
# number of classes
nc: 4
# class names
names: ['closed_eye','closed_mouth','open_eye','open_mouth']

修改训练脚本train.py

为了适应疲劳驾驶检测任务,还需要对训练脚本进行一些调整。以下是修改后的部分代码:

def parse_opt(known=False):
    """Parses command-line arguments for YOLOv5 training, validation, and testing."""
    parser = argparse.ArgumentParser()
    parser.add_argument("--weights", type=str, default=ROOT / "weights/yolov5s.pt", help="initial weights path")
    parser.add_argument("--cfg", type=str, default="models/yolov5s.yaml", help="model.yaml path")
    parser.add_argument("--data", type=str, default=ROOT / "data/fatigue.yaml", help="dataset.yaml path")
    parser.add_argument("--hyp", type=str, default=ROOT / "data/hyps/hyp.scratch-low.yaml", help="hyperparameters path")
    parser.add_argument("--epochs", type=int, default=50, help="total training epochs")
    parser.add_argument("--batch-size", type=int, default=16, help="total batch size for all GPUs, -1 for autobatch")
    parser.add_argument("--imgsz", "--img", "--img-size", type=int, default=640, help="train, val image size (pixels)")
    parser.add_argument("--rect", action="store_true", help="rectangular training")
    parser.add_argument("--resume", nargs="?", const=True, default=False, help="resume most recent training")
    parser.add_argument("--nosave", action="store_true", help="only save final checkpoint")
    parser.add_argument("--noval", action="store_true", help="only validate final epoch")
    parser.add_argument("--noautoanchor", action="store_true", help="disable AutoAnchor")
    parser.add_argument("--noplots", action="store_true", help="save no plot files")
    parser.add_argument("--evolve", type=int, nargs="?", const=300, help="evolve hyperparameters for x generations")
    parser.add_argument(
        "--evolve_population", type=str, default=ROOT / "data/hyps", help="location for loading population"
    )

结果可视化分析

经过训练和测试,模型在疲劳驾驶行为检测任务上取得了较好的效果。以下是模型的性能指标:

YOLOv5s summary: 157 layers, 7020913 parameters, 0 gradients, 15.8 GFLOPs
                 Class     Images  Instances          P          R      mAP50   mAP50-95: 100%|██████████| 25/25 [00:10<00:00,  2.38it/s]
                   all        787       2109       0.97      0.982       0.99      0.611
            closed_eye        787        566      0.953      0.979      0.988       0.54
          closed_mouth        787        701      0.986      0.997      0.989      0.622
              open_eye        787        774      0.955      0.967      0.988      0.545
            open_mouth        787         68      0.985      0.985      0.995      0.736

混淆矩阵

混淆矩阵是一个n×n的矩阵,其中n为分类数目,矩阵的每一行代表一个真实类别,每一列代表一个预测类别,矩阵中的每一个元素表示真实类别为行对应的类别,而预测类别为列对应的类别的样本数。

PR曲线

PR曲线中的P代表的是precision(精准率),R代表的是recall(召回率),其代表的是精准率与召回率的关系,一般情况下,将recall设置为横坐标,precision设置为纵坐标。PR曲线下围成的面积即AP,所有类别AP平均值即Map。

预测结果

© 2023 北京元石科技有限公司 ◎ 京公网安备 11010802042949号