• Stars
    star
    1,568
  • Rank 29,186 (Top 0.6 %)
  • Language
    Python
  • License
    MIT License
  • Created over 7 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

self-driving MarioKart with TensorFlow

TensorKart

self-driving MarioKart with TensorFlow

Driving a new (untrained) section of the Royal Raceway:

RoyalRaceway.gif

Driving Luigi Raceway:

LuigiRacewayVideo

The model was trained with:

  • 4 races on Luigi Raceway
  • 2 races on Kalimari Desert
  • 2 races on Mario Raceway

With even a small training set the model is sometimes able to generalize to a new track (Royal Raceway seen above).

Dependencies

  • python and pip then run pip install -r requirements.txt
  • mupen64plus (install via apt-get)

Recording Samples

  1. Start your emulator program (mupen64plus) and run Mario Kart 64
  2. Make sure you have a joystick connected and that mupen64plus is using the sdl input plugin
  3. Run record.py
  4. Make sure the graph responds to joystick input.
  5. Position the emulator window so that the image is captured by the program (top left corner)
  6. Press record and play through a level. You can trim some images off the front and back of the data you collect afterwards (by removing lines in data.csv).

record

Notes

  • the GUI will stop updating while recording to avoid any slow downs.
  • double check the samples, sometimes the screenshot is the desktop instead. Remove the appropriate lines from the data.csv file

Viewing Samples

Run python utils.py viewer samples/luigi_raceway to view the samples

Preparing Training Data

Run python utils.py prepare samples/* with an array of sample directories to build an X and y matrix for training. (zsh will expand samples/* to all the directories. Passing a glob directly also works)

X is a 3-Dimensional array of images

y is the expected joystick ouput as an array:

  [0] joystick x axis
  [1] joystick y axis
  [2] button a
  [3] button b
  [4] button rb

Training

The train.py program will train a model using Google's TensorFlow framework and cuDNN for GPU acceleration. Training can take a while (~1 hour) depending on how much data you are training with and your system specs. The program will save the best model from all epochs of training to disk when it is done.

Play

The play.py program will use the gym-mupen64plus environment to execute the trained agent against the MarioKart environment. The environment will provide the screenshots of the emulator. These images will be sent to the model to acquire the joystick command to send. The AI joystick commands can be overridden by holding the 'LB' button on the controller.

Future Work / Ideas:

  • Add a reinforcement layer based on lap time or other metrics so that the AI can start to teach itself now that it has a baseline. The environment currently provides a reward signal of -1 per time-step, which gives the AI agent a metric to calculate its performance during each race (episode), the goal being to maximize reward and therefore, minimize overall race duration.
  • Could also have a shadow mode where the AI just draws out what it would do rather than sending actions. A real self driving car would have this and use it a lot before letting it take the wheel.
  • Deep learning is all about data; perhaps a community could form around collecting a large amount of data and pushing the performance of this AI.

Related Projects:

Xbox Game AI - Uses PYXInput for direct control of any Xbox/PC game.

SerpentAI - Game Agent Framework to create AIs for any game.

Donkey Gym - OpenAI Gym Environments for self-driving "Donkey Car".

AirSim - An Unreal Engine simulator for autonoumous vehicles.

Special Thanks To

Contributing

Open a PR! I promise I am friendly :)

More Repositories

1

mupen64plus-input-bot

An input driver for mupen64plus that consumes from a python web server
C
189
star
2

shopify-sinatra-app

"A classy shopify app"
Ruby
78
star
3

arduinoDAQ

use the Arduino as a DAQ with this arduino program and companion python gui
Python
21
star
4

circleDetector

ELEC 824 Assignment #2 - c++ implementation of circle detection using RANSAC based off of "An Ef๏ฌcient Randomized Algorithm for Detecting Circles" by Chen and Chung
C++
20
star
5

pyIPCA

python package for Incremental Prinicpal Component Analysis
Python
18
star
6

shopify-tax-receipts

Shopify app for automatically sending tax receipts when specified products are purchased
Ruby
18
star
7

audiogrep-docker

Dockerfile for audiogrep and pocketsphinx
Shell
11
star
8

ticket-wicket

Create an Event and sell Tickets on the Ethereum blockchain
JavaScript
10
star
9

parity-server

OCUA Parity League Software
Python
9
star
10

shopify-surge-pricing

A demo of surge pricing for Shopify based on cart update webhooks. Live coded at Junction2015
Ruby
7
star
11

github-reviewer-graph

Graphing review activity by user across several repos using Github's GraphQL API
JavaScript
5
star
12

font-patcher

Python
5
star
13

dotfiles

Lua
4
star
14

libBGS

Background Subtraction Library
C++
3
star
15

bss_jade

GSoC 2013 Final Project
3
star
16

ThesisTemplate

Modified Queen's University LaTeX Thesis Template
Python
3
star
17

cs253_blog

The blog I programmed for Udacity's CS 253 Web Development course with Steve Huffman
Python
1
star
18

gmail_todo

A gem for quickly emailing yourself ToDo's from the command line
Ruby
1
star
19

2809_vision2012

FRC Team 2809 Vision Code for 2012 Season (Rebound Rumble)
Java
1
star
20

great-west-life-cli

CLI for submitting online claims to Great West Life
Ruby
1
star
21

quickbooks-sinatra-app

A classy quickbooks online app
Ruby
1
star