This project implements a real-time behavioral monitoring system designed to detect driver fatigue. By leveraging the YOLOv5n architecture and optimizing it for edge deployment, the system classifies driver states into three categories: Alert, Yawn, and MicroSleep, triggering visual and auditory alerts when danger is detected.
.
├── dataset/ # Structured YOLOv5 dataset
│ ├── data.yaml # Class names and path configurations
│ ├── train/ # Training images & labels
│ ├── test/ # Test images & labels
│ └── valid/ # Validation images & labels
├── docs/ # Project Documentation
│ ├── CS324_Project_Report.pdf
│ ├── CS324_Project_Run_Instructions.pdf
│ └── CS324_Project_Slides.pptx
├── icons/ # UI Assets for Alerts
│ ├── coffee.jpg # Yawn warning icon
│ └── warning.jpg # MicroSleep alert icon
├── models/ # Model definition logic
│ ├── yolov5n_drowsy.yaml # Custom architecture config
│ └── yolo.py # Core YOLOv5 model logic
├── runs/ # Training outputs
│ └── train/
│ └── drowsiness_yolov5/ # Artifacts: weights, curves, metrics
├── utils/ # Helper functions (augmentation, plots)
├── yolov5/ # YOLOv5 Submodule
├── detect.py # Inference script with Alert Logic
├── train.py # Training & ONNX Export script
├── requirements.txt # Python dependencies
└── README.md
We utilized YOLOv5n (Nano), the most lightweight variant of the YOLOv5 family. It features ~1.9 million parameters, making it ideal for the limited RAM and computational power of the NVIDIA Jetson Nano.
The model was fine-tuned from a checkpoint pre-trained on the COCO dataset. This allowed the system to inherit robust low-level feature extractors (edges, textures) and adapt upper layers specifically to facial features indicative of fatigue.
- Alert: Normal, attentive driving behavior.
- Yawn: Early sign of fatigue; triggers a "WARNING" (Yellow).
- MicroSleep: Dangerous momentary loss of consciousness; triggers a "DROWSY" Alert (Red + Audio).
The system was evaluated based on training convergence, classification accuracy, and real-time hardware performance. The model achieved production-grade results, demonstrating high reliability for critical safety applications.
After training for 50 epochs, the YOLOv5n model reached the following benchmarks on the validation set:
| Metric | Value |
|---|---|
| mAP@0.5 | 98.5% |
| mAP@0.5:0.95 | 75.8% |
| Precision | 96.3% |
| Recall | 97.6% |
The training process followed three distinct phases:
- Initial Phase (Epochs 0-10): Rapid convergence due to transfer learning. mAP@0.5 jumped from 16.1% to 94.2% as the model adapted its COCO-pretrained weights to facial features.
- Refinement Phase (Epochs 10-30): Significant improvement in localization. mAP@0.5:0.95 increased from 49.5% to 71.4%, narrowing the gap between predicted and ground-truth boxes.
- Steady State (Epochs 30-50): Fine-grained optimization. Loss values reached their floor (Box Loss: 0.020, Class Loss: 0.006).
While the model achieves high accuracy, its primary success is efficiency on the NVIDIA Jetson Nano:
- Inference Speed: Sustained 15-20 FPS using the optimized ONNX pipeline.
- Latency: Total end-to-end processing (capture to alert) stays within 50-70ms, well under the threshold required for immediate driver notification.
- Optimization: Achieved through the use of the
Nanovariant of YOLOv5 (1.9M parameters) and half-precision (FP16) inference where available.
Follow these steps to set up the environment, prepare the data, and run the detection.
Clone the repository and install dependencies. It is recommended to use a Jetson-optimized environment with PyTorch and Torchvision pre-installed via JetPack.
# Clone the repository
git clone <your-repo-link>
cd <repo-name>
# Install python dependencies
pip install -r requirements.txtWe use a specialized drowsiness dataset from Roboflow.
- Download the dataset in YOLOv5 PyTorch format from Roboflow Universe.
- Unzip the folder and rename it to
dataset. - Ensure
dataset/data.yamlpoints to the correct absolute paths.
Run the training script. This script is configured to:
- Disable WandB (offline mode).
- Train for 50 epochs.
- Automatically export the best weights to
.onnxfor optimized inference.
python3 train.pyThe trained model will be saved at: runs/train/drowsiness_yolov5/weights/best.pt.
Connect a USB Webcam or CSI Camera to your Jetson Nano and run:
python3 detect.py --weights runs/train/drowsiness_yolov5/weights/best.pt --source 0 --hide-confKey Flags:
--source 0: Uses the default webcam.--weights: Path to your trained.ptor.onnxfile.--hide-conf: Cleans up the UI by hiding confidence percentages.
During detection, the system provides real-time feedback:
- Normal (Blue Box): No alert.
- Yawn (Yellow Box + Coffee Icon): Displayed when a yawn is detected.
- Drowsy (Red Box + Warning Icon): Displayed during MicroSleep.
- Sound: The
playsoundlibrary is used to trigger an audible alarm during MicroSleep events.
- Southern University of Science and Technology (SUSTech)
- Team:
Developed as part of CS324's final project: Demo AI on Chips.


