Spot a road accident
in 30 milliseconds
Rakshak is an open-source computer-vision model that tells an accident scene apart from ordinary traffic. Train it on your own footage in minutes on a laptop CPU, then ship it to Python, the edge, or straight into a web page.
Try it on a real photo
The model is downloaded once and runs inside this tab with onnxruntime-web. Your image is never sent anywhere.
Or try a sample
Small, honest, and actually runnable
Most accident-detection repos are a notebook that no longer runs. This one is a package, a test suite, and a model you can execute right now.
Trains in minutes on CPU
Two-phase transfer learning on a frozen ImageNet backbone. No GPU required, and the whole run finishes while you make coffee.
One command each way
rakshak train, evaluate, predict and
export. Or import AccidentDetector and call
.predict().
Runs anywhere ONNX runs
Export folds normalisation and softmax into the graph, so browsers, mobile and edge runtimes all get identical numbers to Python.
Metrics that matter
Precision, recall, F1 and ROC-AUC on the accident class — not just accuracy, which hides exactly the errors you care about.
Tested, not hoped
66 tests cover the data split, the freezing logic, checkpoint round-trips, ONNX export and the CLI. CI runs them on every push.
Bring your own data
Point it at any two-folder dataset. Folder names are matched loosely, and class weights adjust automatically if your split is skewed.
How it works
Five steps from a folder of photos to a model running in a web page.
Collect
rakshak scrape pulls openly licensed images and records the licence
for each one.
Split
Validation is carved out of Train with a fixed seed, so
Test stays genuinely held out.
Train head
The backbone is frozen and only the classifier learns — the key trick for a few-hundred-image dataset.
Fine-tune
Everything unfreezes at a 10× lower learning rate to adapt the features without destroying them.
Export
The best checkpoint becomes ONNX, verified against PyTorch to 1e-4 before it ships.
Results on the held-out test set
Measured on 100 images the model never saw during training or validation. Reproduce
with rakshak evaluate --split Test.
| Metric | Score | What it means |
|---|---|---|
| Accuracy | — | Share of all test images classified correctly |
| Recall (accident) | — | Share of real accidents the model catches |
| Precision (accident) | — | Share of accident alerts that are correct |
| F1 (accident) | — | Balance of precision and recall |
| ROC AUC | — | Ranking quality across every threshold |
Running in under a minute
# Install git clone https://github.com/4ryanwalia/Rakshak---Car.git cd Rakshak---Car pip install -e ".[onnx]" # Train on the bundled dataset (CPU is fine) rakshak train --epochs 12 --finetune-epochs 8 # Score it on the held-out test set rakshak evaluate --split Test # Classify anything rakshak predict my_dashcam_frame.jpg
from rakshak import AccidentDetector detector = AccidentDetector.from_checkpoint("models/rakshak.pt") result = detector.predict("scene.jpg") print(result.label) # 'accident' print(result.accident_probability) # 0.94 # Whole folder in batches for r in detector.predict_dir("frames/"): if r.is_accident: alert(r.path, r.confidence)
Help Rakshak grow up
The roadmap is video and dashcam streams, severity grading, and a dataset with properly licensed images at scale. Stars help people find it; sponsorship pays for the compute and the data work.