Skip to content

Commit

Permalink
auto download
Browse files Browse the repository at this point in the history
  • Loading branch information
adeebshihadeh committed Aug 3, 2024
1 parent 922ac9e commit 471ee7b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 23 deletions.
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
# Comma Controls Challenge!
# 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 from [openpilot](https://github.com/commaai/openpilot) users.
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
18 changes: 0 additions & 18 deletions download_dataset.sh

This file was deleted.

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...")
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 471ee7b

Please sign in to comment.