Summary

<aside> 💡 What did I do? I built a racing game from scratch in Python and trained an RL agent (using Double Q-Learning) to grab coins while driving courses.

Why’d I do it? When I was starting my self-studying ML journey (retrospective detail here), I hadn’t developed a large project in around 2 years. So as a 2-for-1, I taught myself reinforcement learning and refamiliarized myself with larger coding projects.

</aside>

https://github.com/lucasdino/AI-Driving

S/o CodeBullet for giving me the idea for what to build in my first project. This was inspired by his video but improved upon by adding the ability to play multiple courses and have the AI generalize fairly well against courses it had not yet seen before. I think his memorized the map but not shaming…this stuff is FINICKY.


📺Couple GIFs

Track the car was trained on - performs fairly well on this one!

Track the car was trained on - performs fairly well on this one!

Let’s make this a bit harder…

Found this racetrack on Google Maps. A lot more windy than the others…this AI is lacking on the ‘I’.

Found this racetrack on Google Maps. A lot more windy than the others…this AI is lacking on the ‘I’.

Unseen track - slightly more difficult. It’s not bad but a bit of a downgrade.

Unseen track - slightly more difficult. It’s not bad but a bit of a downgrade.

Took a ton of different prompts to get a closed circuit top-down course from DALL-E 3 but it’s pretty groovy! At least I think it is. The AI doesn’t 🫠

Took a ton of different prompts to get a closed circuit top-down course from DALL-E 3 but it’s pretty groovy! At least I think it is. The AI doesn’t 🫠


Major Takeaways

  1. Coding: Relearned how to code larger projects after my 2-year banking hiatus. I’m happy with how the code turned out though there are obvious improvements I could make.
  2. Reinforcement Learning: If I had a dollar for the number of times I wanted to throw my laptop out the window I wouldn’t hesitate to put guac on my burrito bowl at Chipotle. Learned a lot by having to build the physics and data pipeline from the ground up. More on that below.

Coding

Only thing worthy of sharing here - initially I was getting around 40 FPS on training runs.

Note — all these measurements refer to when training my Neural Net (i.e., backprop is running and the model is updating). When my game starts and it hasn’t accumulated enough training data yet, I was clocking in over 200 FPS after all of these 🤠

That’s kind of slow. Like I needed this program to be Level 100 Pacer Test and it was just getting a passing grade.

So I stepped in an made a couple of improvements…

  1. Smart Collision / Vision Line Detection: (~40 FPS to ~80FPS)
  2. Concept of a Session: (~80 FPS to ~100FPS)
  3. NumPy / I actually now know linear algebra: (~100 FPS to ~120FPS)
  4. Render Toggle: (~120 FPS to ~140FPS)

All of this was huge. Faster iteration meant I could take the dog for a walk and cook dinner and have the equivalent of a full overnight training run previously.