Real-time F1 telemetry analysis with a TCN model, WebSocket streaming backend, and a React dashboard. Trained on Hamilton and Verstappen qualifying data via FastF1.
F1 AI Driver Coach ingests telemetry channels β speed, throttle, brake, gear, lateral G, steering, distance delta β and runs them through a Temporal Convolutional Network (TCN) trained on real F1 qualifying telemetry. It compares inputs against a reference lap (Verstappen's 2023 Silverstone pole) and surfaces coaching cues in near real-time over WebSocket.
The core technical insight: use track distance as the comparison axis, not timestamps. Two drivers completing the same corner at different speeds will have different temporal profiles but identical distance profiles. This makes cross-driver comparison principled.
| Design Decision | Why It Matters |
|---|---|
| Auto-labelled training data | No human annotation. Late brakes, oversteer, understeer, and missed apices are derived algorithmically from telemetry delta |
| Distance-axis DTW alignment | Dynamic Time Warping on the distance axis gives robust cross-lap comparison without timestamp jitter artefacts |
| TCN over Transformer | 8ms vs 47ms CPU inference. For a real-time coaching loop, latency is a hard constraint |
| Real champion data | Trained on Hamilton and Verstappen lap telemetry β not synthetic or simulation data |
| ONNX export | Model is exported to ONNX Runtime for portable, dependency-light inference |
| Multi-label mistake classifier | Late brake, oversteer, understeer, and missed apex detected simultaneously per timestep |
| LLM post-lap debrief | Optional Ollama (Gemma) integration generates a 3-sentence technical coaching summary per lap |
FastF1 API (real F1 telemetry)
β
βΌ
telemetry.py β Distance-axis resampling, channel extraction
β
βΌ
labels.py β Algorithmic mistake labelling (no annotation)
β
βΌ
alignment.py β DTW-based cross-lap alignment
β
βΌ
train.py + tcn.py β TelemetryTCN training (PyTorch, MPS/CUDA/CPU)
β
βΌ
export.py β ONNX export (~8ms CPU inference)
β
βΌ
replay.py βββββββββββββββΊ main.py (FastAPI WebSocket)
β
βΌ
React Dashboard
LiveChart Β· TrackMap Β· CoachPanel
LapSelector Β· CompareLaps Β· CornerTable
The demo replays Verstappen's 2023 Silverstone qualifying lap at real-time speed. The AI coach streams frame-by-frame telemetry, mistake probabilities, and a running time delta against the sector-optimal reference. No simulator required.
git clone https://github.com/FK-75/f1-ai-driver-coach
cd f1-ai-driver-coach
pip install -r requirements.txt
python scripts/download_data.py # ~10β20 min first run (FastF1 caches locally)
python scripts/train.py # ~5 min on CPU, faster on MPS/CUDA
python backend/api/main.py # WebSocket server on :8000
# In a second terminal:
cd frontend && npm install && npm run dev # React dev server on :5173Open http://localhost:5173 and press Start Demo.
The backend auto-detects device: CUDA β MPS (Apple Silicon) β CPU.
Ifdata/models/tcn.onnxexists, the backend loads it; otherwise it falls back to heuristic mode.
Architecture: 1D Temporal Convolutional Network with causal dilated convolutions
Input: (B, 7, T) β 7 normalised telemetry channels over T timesteps
Outputs:
delta_timeregression head(B, T)β predicted time delta vs reference in secondsmistakesmulti-label head(B, 4, T)β per-timestep mistake probabilities
Input (7ch) β Input Projection
β TCNBlock(dilation=1)
β TCNBlock(dilation=2)
β TCNBlock(dilation=4)
β TCNBlock(dilation=8)
β delta_head β Ξt (regression)
β mistake_head β [late_brake, oversteer, understeer, missed_apex]
Receptive field: 61 samples = 305m of track context per prediction (at 5m resolution)
Training data: 2021β2024 qualifying sessions across Silverstone, Monza, Monaco, Spa, Suzuka, Barcelona, Abu Dhabi, Bahrain, Singapore, Zandvoort
Loss: Huber loss (delta time) + weighted BCE (mistakes, 3Γ positive class weight)
Inference: ONNX Runtime, ~8ms on CPU per 512-sample window
| Endpoint | Method | Description |
|---|---|---|
/health |
GET | Model load status, inference mode |
/laps |
GET | All available training laps, grouped by circuit |
/fixture |
GET | Demo fixture metadata |
/reference |
GET | Reference lap track coordinates for map rendering |
/compare/{a}/{b} |
GET | Full telemetry overlay for two laps, resampled to shared distance axis |
/corner-report |
GET | Per-corner apex speed, time delta, dominant mistake |
/sector-report |
GET | Sector-level time delta and primary issue |
/llm-summary |
POST | LLM post-lap coaching debrief (requires local Ollama) |
ws://β¦/ws/replay |
WebSocket | Replay stream β send {"action":"start"} to begin |
ws://β¦/ws/live |
WebSocket | Live sim placeholder (F1 24 / Assetto Corsa UDP) |
WebSocket frame schema:
{
"type": "frame",
"data": {
"distance_m": 1240.5,
"speed_kmh": 287.3,
"throttle": 98.0,
"brake": 0.0,
"gear": 7,
"lateral_g": 2.1,
"delta_time_s": -0.043,
"mistake_probs": {
"late_brake": 0.08,
"oversteer": 0.12,
"understeer": 0.03,
"missed_apex": 0.07
},
"ref_speed_kmh": 291.0,
"x": 142.3,
"y": -88.1
}
}| Layer | Technology | Rationale |
|---|---|---|
| Data | FastF1 | Real F1 telemetry, free, multi-season |
| ML | PyTorch TCN + ONNX Runtime | Sub-10ms CPU inference, portable export |
| Signal processing | SciPy | DTW alignment, braking zone detection |
| Backend | FastAPI + uvicorn WebSockets | Async, low-latency frame streaming |
| Frontend | React 18 + Recharts | Live charts, WebSocket hooks |
| LLM (optional) | Ollama / Gemma | Post-lap natural language debrief |
f1-ai-driver-coach/
βββ backend/
β βββ api/
β β βββ main.py # FastAPI app β HTTP + WebSocket endpoints
β βββ models/
β β βββ tcn.py # TelemetryTCN architecture + TelemetryLoss
β β βββ train.py # Training loop, dataset, sliding windows
β β βββ export.py # ONNX export + inference engine loader
β βββ pipeline/
β βββ telemetry.py # FastF1 fetching, distance-axis resampling
β βββ labels.py # Algorithmic mistake labelling
β βββ alignment.py # DTW cross-lap alignment, rolling delta
β βββ replay.py # Demo replay engine, fixture builder
βββ frontend/
β βββ src/
β βββ components/
β β βββ LiveChart.jsx # Real-time telemetry traces (Recharts)
β β βββ TrackMap.jsx # Track position overlay with mistake highlights
β β βββ CoachPanel.jsx # Coaching cues, mistake probabilities
β β βββ LapSelector.jsx # Browse and select training laps by circuit
β β βββ CompareLaps.jsx # Overlay two laps on shared distance axis
β β βββ CornerTable.jsx # Per-corner breakdown table
β βββ hooks/
β β βββ useWebSocket.js # WebSocket connection + frame state management
β βββ App.jsx # Main dashboard layout
β βββ main.jsx
βββ scripts/
β βββ download_data.py # Fetch FastF1 data and build demo fixture
β βββ train.py # Training entrypoint (wraps backend/models/train.py)
β βββ calibrate_thresholds.py # Tune mistake detection thresholds on real data
βββ data/
β βββ .gitkeep # Data directory (populated by download_data.py)
βββ requirements.txt
βββ README.md
"Online imitation learning from expert demonstrations for motor skill coaching β comparing driver control inputs against expert reference traces to produce actionable corrective feedback via a real-time TCN inference pipeline."
FastF1 provides a legitimate public dataset of expert motor skill demonstrations from professional F1 drivers. The auto-labelling approach (deriving mistakes from telemetry delta) is directly analogous to inverse reinforcement learning: we infer what constitutes a mistake by observing where a driver deviates from an expert.
- Live simulator UDP ingestion (F1 24 / Assetto Corsa / iRacing β port 20777)
- Sector-split model with per-sector reference selection
- Steering angle reconstruction from X/Y curvature (currently a proxy)
- Demo GIF / screen recording in README
MIT β see LICENSE.
Built as a portfolio project combining ML, real-time systems engineering, and motorsport telemetry.