This is a deep learning model for a self-driving car. Neural network has been used to create a self driving car AI . The project consists of three phases:
- Generating data
- Training model
- Self Driving
The data for the neural network is generated by playing the game (provided in the link) and running main.py in training mode, the data generated consist of game frames as 30x30x3 array with keys w,s,a,d, both are captured while the user plays the game.
Once the data is gathered this data is feeded to a neural network model model.py the model takes input frames as 1x2700 array and keys 1x4 array. Using the convolutional neural network, the model trains upon the data generated in previous phase.
Now run the main.py in driving mode. The trained model will predict and automate key-press on running the game in driving mode.
The python library used to capture frames is Win32api which is only available on windows. As an alteranative Pyscreenshot can be used in linux but it capture frames extremely slow (~ 10fps). Keras with tensorflow backend has been used to train the model. Others: Numpy, Pandas, OpenCV , Pyautogui and Keyboard has been used.
- Run game.exe in 512x384.
- Once the red screen with the note "Press Space" appears, run main.py. Let main.py locate the game window. So don't press space until it finds the game screen.
- main.py will capture the location of the game and will ask whether to train, test or quit.
- Choose an option:
- Training: use w, a, s, d to move the car on the road and press q to stop training. This will collect data and store it to
data/
folder. Once data has been collected, run model.py to create a trained model for the self-driving car in themodel/
folder. Now this model can be used for testing. - Testing: Testing here refers to driving. Once there is a trained model this option can be used. Just select the option and let the car drive itself. To stop testing, put the cursor on the opencv screen window and press esc.
- Training: use w, a, s, d to move the car on the road and press q to stop training. This will collect data and store it to
The link of the car game to be trained: https://www.dropbox.com/s/ji1ywiaj7s1kin7/Game-Updated.rar?dl=0
Video recorded after accuracy 72.8%. https://www.dropbox.com/s/3a5ygtqumct2huc/carai.mp4?dl=0