CNN-Based Drowsiness Detection - Model
An ONNX-exported CNN that predicts driver drowsiness from a preprocessed face crop. Trained with Sony Neural Network Console on notgoodkeeper/cnn-based-drowsiness-detection-data.
Code: https://github.com/not-good-keeper/cnn-based-drowsiness-detection
Usage
import cv2
import numpy as np
import onnxruntime as ort
session = ort.InferenceSession("model.onnx")
# face: a 412x412 preprocessed face crop (see src/preprocessing.py in the code repo
# for face detection, background removal, and CLAHE + grayscale steps)
rgb = cv2.cvtColor(face, cv2.COLOR_GRAY2RGB) if face.ndim == 2 else face
input_tensor = (rgb.astype(np.float32) / 255.0).transpose(2, 0, 1)[None, ...]
predicted_class, confidence, regressions = session.run(
None, {session.get_inputs()[0].name: input_tensor}
)
regressions is a 6-element vector [drowsiness_score, ear, mar, head_roll, head_pitch, head_combined], each normalized to [0, 1]. See src/realtime_inference.py in the
code repo for the denormalization ranges and a full real-time inference loop.
Architecture
A deep CNN (multiple Conv2D + BatchNorm + ReLU blocks feeding into dense layers), multi-headed to jointly predict a drowsiness class, a confidence score, and the six regression targets above.
Training
- Input: 412x412x3 RGB (grayscale-preprocessed face crop, replicated to 3 channels)
- ~2,376 labeled samples (1,661 train / 356 val / 359 test)
- Best validation loss: 0.925 (from Sony NNC's training log), converged within 18 epochs
- Labels are weak/heuristic (see the dataset card), not hand-annotated - this is a research/portfolio project, not a validated safety system.
Files
model.onnx- the exported modelnet.nntxt- Sony NNC network definition (for reference / re-training)result.ini- training run summary (epochs, cost, validation error)
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support