Spaces:
Running
Running
File size: 4,350 Bytes
81762c0 85d6e75 81762c0 85d6e75 81762c0 85d6e75 81762c0 85d6e75 81762c0 85d6e75 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | ---
title: Next Drive
emoji: 🚦
colorFrom: green
colorTo: gray
sdk: static
app_file: index.html
pinned: false
license: apache-2.0
short_description: Autonomous driving in simulated intersections
---
# Next Drive
Next Drive is a small learned driver for a **simulated** city intersection. Every 0.1 s it chooses one of six
longitudinal actions (brake hard, brake, ease off, hold speed, speed up, accelerate) while following a straight, left or right route through a traffic
light, a crosswalk, a lead car that brakes suddenly, oncoming and cross traffic, and parked cars that hide a pedestrian.
**Simulation and education only. It is not connected to, and has never been tested on, a real vehicle, and nothing here
supports a claim about real-road safety.**
**Model:** https://huggingface.co/thelamapi/Next-Drive — pick a scene, density and driver; the drive is generated in your browser and can be replayed with its critical events.
## Results on unseen test scenes (450 per driver; seeds ≥ 10000; density 3 never seen in training)
| Driver | Collisions | Red-light violations | Goal reached | Hard brakes / drive | Time to goal (s) | Decision ms (mean / p95) |
|---|---:|---:|---:|---:|---:|---:|
| Learned + safety check | 4.4% | 0.4% | 89.1% | 1.67 | 21.0 | 0.34 / 0.47 |
| Learned | 4.4% | 10.0% | 89.8% | 0.95 | 19.3 | 0.28 / 0.40 |
| Rule-based | 27.1% | 0.0% | 71.1% | 0.95 | 23.3 | 0.02 / 0.07 |
| Expert (teacher) | 2.7% | 1.3% | 93.6% | 1.01 | 19.2 | 1.61 / 2.38 |
Collision / goal-reached rate by scene type:
| Scene | Learned + safety | Learned | Rule-based | Expert |
|---|---:|---:|---:|---:|
| light | 4% / 96% | 2% / 98% | 1% / 99% | 1% / 99% |
| crosswalk | 7% / 93% | 1% / 99% | 9% / 86% | 0% / 100% |
| lead_brake | 8% / 92% | 1% / 99% | 3% / 97% | 2% / 98% |
| occlusion | 2% / 79% | 10% / 73% | 68% / 32% | 7% / 82% |
| mixed | 1% / 86% | 8% / 80% | 54% / 42% | 3% / 89% |
Collision rate by traffic density:
| Density | Learned + safety | Learned | Rule-based | Expert |
|---|---:|---:|---:|---:|
| 1 | 1% | 2% | 23% | 0% |
| 2 | 5% | 3% | 23% | 3% |
| 3 (unseen) | 7% | 8% | 35% | 5% |
Rates count drives with at least one event. Decision latency was measured in Python on NVIDIA L4, single process; the
Space reports its own browser timing. All 138 failures of the learned drivers are listed in `evaluation.json`
and can be replayed in the Space.

[Replay video](replay.mp4): one unselected test scene, then failure replays.
## How it works
* **Simulator:** 1-lane roads, NS/EW signals with yellow and all-red, IDM-like traffic, pedestrians, and line-of-sight occlusion by parked cars. The ego car perceives cars always and pedestrians only when visible within 60 m.
* **Expert:** evaluates 6×6 two-phase action sequences (1 s + 2 s) at 0.25 s resolution with constant-velocity predictions, the known light schedule, a 2 m + 1.2 s following gap, and a speed cap that allows stopping before occluded gaps.
* **Learned driver:** MLP 21→64→64→6 on hand-made features (speed, light state, stop-line distance, lead gap, time-to-collision under three accelerations, visible-pedestrian and occlusion distances, route). Behaviour cloning on 300 expert drives (59750 states), then 3 DAgger round(s); iteration 2 was selected on validation seeds.
* **Safety check:** keeps an action only if braking at −6 m/s² after 0.5 s still avoids every predicted collision and red-light entry; otherwise picks the strongest safe deceleration.
* **Rule-based baseline:** IDM car following plus stop-line, visible-pedestrian and left-turn-yield rules.
* The browser runs a line-by-line JavaScript port; Node parity: 8 full drives, 0 mismatches.
## Usage
```bash
python inference.py --seed 10007 --kind mixed --density 2 --driver shield
python inference.py --selftest
```
`policy.safetensors` holds the PyTorch weights; `model.json` the same weights for NumPy and the browser.
## Limitations
* Speed-only control on fixed routes; no lane changes, no steering errors, no sensor noise beyond occlusion.
* Other road users follow simple scripted behaviour and never react to the ego car.
* The expert is imperfect too (see the table); the learned driver copies its habits, including frequent hard braking at yellow lights.
* All numbers come from this simulator and say nothing about real driving.
|