Distracted-Driver: The Open-Source Safety System That Turns a Webcam Into an Alarm Stack

A ResNet50 classifier is only the beginning. This repo shows the messy, revealing last mile of driver monitoring: live video, label smoothing, audio warnings, email alerts, and location lookup.

8 min read • View on GitHub • More from Nayeem-Akhta

A driver cockpit seen from a slightly elevated wide angle. One hand holds a phone, the other rests on the wheel, while a webcam-like camera frame, an audio speaker, an email envelope, and a location pin radiate from the windshield as linked response nodes. The scene explains that this repository is not just classifying distraction. It is turning one prediction into a chain of safety actions.
The interesting part is not the classifier. It is the response stack that hangs off it.
Key Takeaways

Why this repo matters

Most distracted-driving repos stop when the model predicts a class. This one keeps going. It takes a distracted frame, stabilizes the label, and turns that signal into sound, text, email, and location reporting.

That changes the story. The repository is not really about computer vision accuracy. It is about what happens after the prediction, when a model has to become useful in a real-time safety loop.

From one prediction to five responses

The pipeline is simple to describe and surprisingly revealing in practice. A camera feed becomes frames, frames go through ResNet50 inference, the predicted label gets mapped to a human-readable state, and a small gate checks whether the label is repeating before the alert stack fires.

This diagram shows the whole trick: the repo does not stop at prediction. It uses prediction as a trigger for action.

That last hop matters. Once the label crosses the debounce gate, the system can speak to the driver, play an alarm, show the warning on screen, send an email, and attach a rough location. The model is the front door. The product logic is the house.

The model is conventional. The product logic is not

The training side is familiar transfer learning. `resnet_train.py` builds on ResNet50 with a small classification head, while `driver_prediction.py` wraps inference by loading the saved model and mapping class codes to readable labels.

model = ResNet50(weights='imagenet', include_top=False, input_shape=(224, 224, 3))
# ...
model.add(Flatten())
model.add(Dense(256, activation='relu'))
model.add(Dense(8, activation='softmax'))

The interesting part is the mismatch. The research notes show a training setup that expects 8 classes, while the broader project framing points to 10 distracted-driving categories. Inference also resizes to 128 by 128 in one place and 224 by 224 in another. Those are the kinds of seams you only see in a prototype that has moved faster than its own paperwork.

LayerWhat it doesWhat stands out
Training scriptFine-tunes ResNet50 for driver-state classificationConventional transfer learning with a small dense head
Inference wrapperLoads the model and maps outputs to labelsBridges code and product, but shows size and class drift
Application loopTurns predictions into alertsThis is where the repo becomes a safety system, not a demo
A close-up mechanical relay where one label signal passes through a small gate marked by a spring-loaded arm, then splits into a speaker, a video overlay, and an email envelope with a location pin. One branch is blocked from repeating, showing how the system avoids alarm thrashing. The image explains the repo’s debounce logic and why repeated predictions do not need to trigger repeated alerts.
A tiny control check makes the loop usable. Without it, the system would scream on every frame.

How the real-time loop keeps alarms from thrashing

`predict_distracted.py` is the file that makes the project feel alive. It reads frames from a live camera feed, predicts the current label, compares it with `prevlabel`, and only escalates when the system sees a meaningful change.

if current_label != prevlabel:
    prevlabel = current_label
    if distracted:
        play_alarm()
        speak_warning()
        send_email()
        show_overlay()

That `prevlabel` check is small, but it is the difference between a prototype and a nuisance. It acts like a primitive debounce layer, keeping the alert stack from firing continuously when the frame-level model wobbles.

Why IP geolocation is the tell

`gpsloc.py` is one of the clearest signs that this project is trying to be useful without specialized hardware. Instead of a dedicated GPS module, it uses public IP lookup to estimate location. That makes the system easier to demo, but it also reveals the prototype’s boundaries.

OptionProsCons
IP geolocationNo extra hardware, easy to wire into a demoCoarse and sometimes wrong
Dedicated GPSPrecise enough for incident reportingRequires hardware and integration
No locationSimplest systemLess actionable when something goes wrong

This is closer to a capstone than a product

The repository has the smell of an educational build that got pushed until it worked. Backup files are left in place, hardcoded alert credentials are visible in the code, and the dimension and class-count inconsistencies suggest the implementation evolved faster than the cleanup pass.

That is not a reason to dismiss it. It is the reason to read it closely. The repo shows what a real safety prototype looks like before polish, when the hard part is not model selection but making a prediction usable, tolerable, and operational.

Where it sits in the wider landscape

Compared with Kaggle-style distracted-driver notebooks, this project goes beyond accuracy and into action. Compared with commercial driver-monitoring systems, it is far less robust, but also far more legible. It sits in the gap between a tutorial and a deployable product.

Project typeStrengthLimit
Kaggle classifierStrong benchmarking cultureUsually ends at prediction
Commercial DMSHardware-backed reliabilityOpaque and expensive
Distracted-DriverClear last-mile alert logicPrototype-level rough edges

What this project teaches

The lesson is bigger than distracted driving. AI projects become interesting when they have to do something after they know something. This repo is a compact example of that shift, from classification to intervention.

That is the real last mile of AI safety. Not a model in isolation. A system that notices, decides, and then acts.