AI Learns To Drive

Опубликовано: 11 Июль 2026
на канале: Dubious Insights
156
4

This AI learned to drive in 9 generation using the NEAT framework to evolve its neural nets.

I had some trouble getting this to work, so I simplified my code from having a whole bunch of radar lines + speed + angle as the input to merely have 3 inputs to the AI's neural net. The inputs are the length of the line directly in front of the car, as well as the different in length of lines between the ones pointed off to the left and the ones pointed off to the right.

I also simplified the output to be only two things, either turn left or turn right. Initially I had 5 potential actions, turn left or right, accelerate or decelerate, or reverse. In theory I figured the car could learn that it was stuck and back up and try again. That didn't really ever pan out. When I had ~11 inputs and ~5 outputs, I let this go for several hundred generations without great results.

With this more simplified neural net architecture, it gives halfway decent results in fewer than 10 generations. In a few of my runs that I didn't screen capture, I saw cars doing well by generation 5.

The fitness function of this AI is simply the distance it traveled. Since these cars are all traveling at 3 meters per second (~7 mph), this fitness function basically amounts to length of time before they hit a wall...... Honestly distance traveled made more sense when the AI could choose to accelerate, or go backwards. Initially, many of them just sat still at that time.

This is done with
Python
Pygame - basically all the images
Neat - all the AI

car image from here
https://pixabay.com/vectors/car-vehic...

Unfortunately I'm not currently able to share the code for this. This is due to the fact that I work at Google as a software engineer, and thus need to get permission before releasing projects. (Note, this is a personal youtube channel though, and unaffiliated with my employer) If I end up going through the permission process in the future, I'll update this and share the code.