Skip to content

Commit

Permalink
auto dataset download + misc fixups (commaai#21)
Browse files Browse the repository at this point in the history
* fixups

* auto download

* update ci

* show size
  • Loading branch information
adeebshihadeh authored Aug 3, 2024
1 parent ec9f86c commit d3b647b
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 34 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
jobs:
rollout:
runs-on: ubuntu-20.04

steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -25,14 +25,10 @@ jobs:
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Download dataset
run: |
bash ./download_dataset.sh
- name: Run Simple controller rollout
run: |
python tinyphysics.py --model_path ./models/tinyphysics.onnx --data_path ./data/00000.csv --controller pid
- name: Run batch rollouts
run: |
python tinyphysics.py --model_path ./models/tinyphysics.onnx --data_path ./data --num_segs 20 --controller pid
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
__pycache__/
data/
report.html
models/tinyphysics_*.onnx
models/tinyphysics_*.onnx
*.swp
11 changes: 4 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
# Comma Controls Challenge!
![Car](./imgs/car.jpg)
# comma Controls Challenge!

Machine learning models can drive cars, paint beautiful pictures and write passable rap. But they famously suck at doing low level controls. Your goal is to write a good controller. This repo contains a model that simulates the lateral movement of a car, given steering commands. The goal is to drive this "car" well for a given desired trajectory.


## Geting Started
We'll be using a synthetic dataset based on the [comma-steering-control](https://github.com/commaai/comma-steering-control) dataset for this challenge. These are actual routes with actual car and road states.
We'll be using a synthetic dataset based on the [comma-steering-control](https://github.com/commaai/comma-steering-control) dataset for this challenge. These are actual car and road states from [openpilot](https://github.com/commaai/openpilot) users.

```
# download necessary dataset (~0.6G)
bash ./download_dataset.sh
# install required packages
# recommended python==3.11
pip install -r requirements.txt
Expand Down Expand Up @@ -58,5 +54,6 @@ python eval.py --model_path ./models/tinyphysics.onnx --data_path ./data --num_s
- With [this commit](https://github.com/commaai/controls_challenge/commit/4282a06183c10d2f593fc891b6bc7a0859264e88) we fixed a bug that caused the simulator model to be initialized wrong.

## Work at comma

Like this sort of stuff? You might want to work at comma!
https://www.comma.ai/jobs
[comma.ai/jobs](https://comma.ai/jobs)
18 changes: 0 additions & 18 deletions download_dataset.sh

This file was deleted.

4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
numpy==1.25.2
numpy
onnxruntime
pandas==2.1.2
matplotlib==3.8.1
seaborn==0.13.2
tqdm
tqdm
20 changes: 20 additions & 0 deletions tinyphysics.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
import importlib
import numpy as np
import onnxruntime as ort
import os
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import signal
import urllib.request
import zipfile

from io import BytesIO
from collections import namedtuple
from functools import partial
from hashlib import md5
Expand Down Expand Up @@ -36,6 +40,8 @@
State = namedtuple('State', ['roll_lataccel', 'v_ego', 'a_ego'])
FuturePlan = namedtuple('FuturePlan', ['lataccel', 'roll_lataccel', 'v_ego', 'a_ego'])

DATASET_URL = "https://huggingface.co/datasets/commaai/commaSteeringControl/resolve/main/data/SYNTHETIC_V0.zip"
DATASET_PATH = Path(__file__).resolve().parent / "data"

class LataccelTokenizer:
def __init__(self):
Expand Down Expand Up @@ -215,6 +221,17 @@ def run_rollout(data_path, controller_type, model_path, debug=False):
return sim.rollout(), sim.target_lataccel_history, sim.current_lataccel_history


def download_dataset():
print("Downloading dataset (0.6G)...")
DATASET_PATH.mkdir(parents=True, exist_ok=True)
with urllib.request.urlopen(DATASET_URL) as resp:
with zipfile.ZipFile(BytesIO(resp.read())) as z:
for member in z.namelist():
if not member.endswith('/'):
with z.open(member) as src, open(DATASET_PATH / os.path.basename(member), 'wb') as dest:
dest.write(src.read())


if __name__ == "__main__":
available_controllers = get_available_controllers()
parser = argparse.ArgumentParser()
Expand All @@ -225,6 +242,9 @@ def run_rollout(data_path, controller_type, model_path, debug=False):
parser.add_argument("--controller", default='pid', choices=available_controllers)
args = parser.parse_args()

if not DATASET_PATH.exists():
download_dataset()

data_path = Path(args.data_path)
if data_path.is_file():
cost, _, _ = run_rollout(data_path, args.controller, args.model_path, debug=args.debug)
Expand Down

0 comments on commit d3b647b

Please sign in to comment.