Giter Club home page Giter Club logo

controls_challenge's Introduction

comma Controls Challenge v2

Prize money: best score between August 5th and September 1st 2024 wins $500!

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 dataset for this challenge. These are actual car and road states from openpilot users.

# install required packages
# recommended python==3.11
pip install -r requirements.txt

# test this works
python tinyphysics.py --model_path ./models/tinyphysics.onnx --data_path ./data/00000.csv --debug --controller pid 

There are some other scripts to help you get aggregate metrics:

# batch Metrics of a controller on lots of routes
python tinyphysics.py --model_path ./models/tinyphysics.onnx --data_path ./data --num_segs 100 --controller pid

# generate a report comparing two controllers
python eval.py --model_path ./models/tinyphysics.onnx --data_path ./data --num_segs 100 --test_controller pid --baseline_controller zero

You can also use the notebook at experiment.ipynb for exploration.

TinyPhysics

This is a "simulated car" that has been trained to mimic a very simple physics model (bicycle model) based simulator, given realistic driving noise. It is an autoregressive model similar to ML Controls Sim in architecture. Its inputs are the car velocity (v_ego), forward acceleration (a_ego), lateral acceleration due to road roll (road_lataccel), current car lateral acceleration (current_lataccel), and a steer input (steer_action), then it predicts the resultant lateral acceleration of the car.

Controllers

Your controller should implement a new controller. This controller can be passed as an arg to run in-loop in the simulator to autoregressively predict the car's response.

Evaluation

Each rollout will result in 2 costs:

  • lataccel_cost: $\dfrac{\Sigma(actual\_lat\_accel - target\_lat\_accel)^2}{steps} * 100$

  • jerk_cost: $\dfrac{\Sigma((actual\_lat\_accel_t - actual\_lat\_accel_{t-1}) / \Delta t)^2}{steps - 1} * 100$

It is important to minimize both costs. total_cost: $(lataccel\_cost * 50) + jerk\_cost$

Submission

Run the following command, then submit report.html and your code to this form.

python eval.py --model_path ./models/tinyphysics.onnx --data_path ./data --num_segs 5000 --test_controller <insert your controller name> --baseline_controller pid

Changelog

  • With this commit we made the simulator more robust to outlier actions and changed the cost landscape to incentivize more aggressive and interesting solutions.
  • With this commit 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! comma.ai/jobs

controls_challenge's People

Contributors

adeebshihadeh avatar grekiki2 avatar haraschax avatar nuwandavek avatar nworb-cire avatar quantizr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

controls_challenge's Issues

Onnx inference is slow

Running the rollouts on a bunch of segments is really slow. There are a couple of options to speed things up.

  1. GPU: The model currently lives inside the sim. But if it outside, inputs can be batched.
  2. CPU: multiprocessing will make it much faster with the onnxruntime as CPU.

CONTROL_START_IDX

Shouldn't CONTEXT_LENGTH in the reset and rollout functions be replaced with CONTROL_START_IDX

Screenshot 2024-05-22 at 9 23 07 AM

Jerky Motion

I am getting weird behaviors out of the car model when steering the wheel to values close to 0

[tinyphysics] Model is not robust to out of distribution data

The current model has a couple of issues:

  1. The model is not robust to out of distribution steer values (like all 0, or all a constant value). This makes it behave unnaturally to those inputs. Augmenting training data should fix this.
  2. The road roll is very highly correlated to the lateral accel. The above steer augmentation should fix this as well.

Controllers not given history

When implementing a controller it's a bit annoying that I don't see any history at control_start time. I guess I can do file fingerprinting to get the data but it doesn't seem very "fair".

Any chance to give controllers data even before control_start?

The column "targetLateralAcceleration" missing from HYUNDAI_SONATA_2020 & HONDA_CIVIC_2022

Hi guys,

I downloaded HONDA_CIVIC_2022 from huggingface and when I was checking the experiment.ipynb I got this error:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
File ~/sof/dev/comma_ai/challenges/controls_challenge/controls/lib/python3.12/site-packages/pandas/core/indexes/base.py:3805, in Index.get_loc(self, key)
   3804 try:
-> 3805     return self._engine.get_loc(casted_key)
   3806 except KeyError as err:

File index.pyx:167, in pandas._libs.index.IndexEngine.get_loc()

File index.pyx:196, in pandas._libs.index.IndexEngine.get_loc()

File pandas/_libs/hashtable_class_helper.pxi:7081, in pandas._libs.hashtable.PyObjectHashTable.get_item()

File pandas/_libs/hashtable_class_helper.pxi:7089, in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: 'targetLateralAcceleration'

The above exception was the direct cause of the following exception:

KeyError                                  Traceback (most recent call last)
Cell In[10], line 1
----> 1 sim = TinyPhysicsSimulator(model, "./data/00000.csv", controller=controller, debug=False)
      2 sim.rollout()

File ~/sof/dev/comma_ai/challenges/controls_challenge/controls_challenge/tinyphysics.py:102, in TinyPhysicsSimulator.__init__(self, model, data_path, controller, debug)
    100 self.data_path = data_path
    101 self.sim_model = model
--> 102 self.data = self.get_data(data_path)
    103 self.controller = controller
    104 self.debug = debug

File ~/sof/dev/comma_ai/challenges/controls_challenge/controls_challenge/tinyphysics.py:125, in TinyPhysicsSimulator.get_data(self, data_path)
    119 def get_data(self, data_path: str) -> pd.DataFrame:
    120   df = pd.read_csv(data_path)
    121   processed_df = pd.DataFrame({
    122     'roll_lataccel': np.sin(df['roll'].values) * ACC_G,
    123     'v_ego': df['vEgo'].values,
    124     'a_ego': df['aEgo'].values,
--> 125     'target_lataccel': df['targetLateralAcceleration'].values,
    126     'steer_command': -df['steerCommand'].values  # steer commands are logged with left-positive convention but this simulator uses right-positive
    127   })
    128   return processed_df

File ~/sof/dev/comma_ai/challenges/controls_challenge/controls/lib/python3.12/site-packages/pandas/core/frame.py:4102, in DataFrame.__getitem__(self, key)
   4100 if self.columns.nlevels > 1:
   4101     return self._getitem_multilevel(key)
-> 4102 indexer = self.columns.get_loc(key)
   4103 if is_integer(indexer):
   4104     indexer = [indexer]

File ~/sof/dev/comma_ai/challenges/controls_challenge/controls/lib/python3.12/site-packages/pandas/core/indexes/base.py:3812, in Index.get_loc(self, key)
   3807     if isinstance(casted_key, slice) or (
   3808         isinstance(casted_key, abc.Iterable)
   3809         and any(isinstance(x, slice) for x in casted_key)
   3810     ):
   3811         raise InvalidIndexError(key)
-> 3812     raise KeyError(key) from err
   3813 except TypeError:
   3814     # If we have a listlike key, _check_indexing_error will raise
   3815     #  InvalidIndexError. Otherwise we fall through and re-raise
   3816     #  the TypeError.
   3817     self._check_indexing_error(key)

KeyError: 'targetLateralAcceleration'

It seems like that column is called different. Perhaps one of this three columns is the match:

lateral_acc

I got the same error with the dataset called HYUNDAI_SONATA_2020 that you used here:

https://github.com/commaai/comma-steering-control/blob/master/visualize.ipynb

What column is the equivalent of targetLateralAcceleration used in your model tinyphysics.onnx?

Thank you so much for your time!

Off-by-one error in sim_step

It looks like the context for the sim model doesn't include the data for the current step, unclear if this is intentional or not. If I add print(len(self.state_history), max(0, step_idx - CONTEXT_LENGTH), step_idx) at the top of sim_step, I get an output that looks like this:

21 0 20
22 1 21
23 2 22
24 3 23
25 4 24
...

action_history before CONTROL_START_IDX is opposite sign

I was rerunning my PID controller last night on the revised challenge and was encountering some odd unexpected behavior in the results. Turns out that the action_history in the first 100 segments (before CONTROL_START_IDX), which is passed into tinyphysics.onnx has inverted sign. This causes the first few segments after CONTROL_START_IDX to be uncontrollable, especially for large lat_accels as the model sees a extremely large change in action_history and takes multiple segments to correct itself.

This was a problem in the first version of the challenge too (and explains why my old LSTM solution trained on the first 100 segments had to invert the output to function)

Problematic graph (the action_history (green line) is inverted for the first CONTROL_START_IDX segments):
image

Fixed graph by reinverting the first 100 segments of action_history passed into pred (no change in controller):
image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.