Giter VIP home page Giter VIP logo

racer_ai's Introduction

Racer_AI

-----------------------------------------------------

An OpenAI Gym style environment that allows you to create custom racing tracks with checkpoints, and train a car to navigate through them. This environment can be used as a benchmark for various reinforcement learning algorithms and is compatible with Stable Baselines 3.

Action Space Discrete(3)
Observation Shape (12,)
Observation High 1000
Observation Low 0

In this repo, we have trained a PPO agent using Stable Baselines 3 to navigate through various custom race tracks. We then utilized the trained expert agent to help a novice agent traverse a new track using Imitation Learning (DAgger algorithm).

-----------------------------------------------------

Calibrate a Custom Track

Our environment is highly customizable. The calibration feature allows you to design your very own racing track and add checkpoints that the car must sequentially pass through.

python calibrate_track.py

Car Position and Orientation

On running the above script, a pygame window will open up. Start off by defining where you want the car to spawn. This can be achieved by simply left-clicking on the desired location. Once the car is placed, it will point in the direction of the mouse cursor. The angular orientation can be finalized by pressing C on the keyboard.

car

Drawing the Track

Next, we draw the borders of the race track. You can add marker points to the canvas using left-clicks. Walls will be formed between every consecutive set of marker points. The Space key can be used to undo the most recently added marker point.

track_draw

Adding Checkpoints

Checkpoints are used by the agent to gain a sense of direction in which the track must be traversed. Checkpoints must be created across the track in the order that the car must pass through them. To add a checkpoint, simply right-click on 2 points across the width of the track. Note that the sequence of the checkpoints will be the order in which the car passes through them. Be kind to your agent and make sure that the checkpoints are placed in a way that the car can actually reach them. It is recommended to create a larger number of checkpoints across turning points in the track.

checkpoint

The Z key can be used to undo the most recently added checkpoint.

Saving the Track

Once you are satisfied with the track, you can save it by pressing the S key. The track will be saved as a .pkl file in the tracks/training folder.

You can create as many tracks as you want. If any track needs to be used for evaluation rather than training, it's .pkl file should be moved to the tracks/testing folder.

-----------------------------------------------------

Reinforcement Learning Agent

Now that the track is finalized, you can train the agent to navigate through it with your desired RL algorithm.

We have used the Proximal Policy Optimization (PPO) algorithm from Stable Baselines 3 to train our agent.

Training

python train_ppo_agent.py

train_ppo

Testing

Trained PPO model is already included in this repo. To test the agent, run the following command:

python evaluate_ppo_agent.py

test_ppo

-----------------------------------------------------

Imitation Learning Agent

DAgger (Dataset Aggregation) is an iterative policy training algorithm that trains a novice agent by dynamically aggregating trajectories and learning to mimic an expert agent's policy on those trajectories. In this case, the expert agent is the one that we trained using PPO. The main advantage of DAgger is that the expert teaches the learner how to recover from past mistakes.

Training

Before we start training, an initial dataset of state-action pairs representing the expert policy must be generated. This can be done by running the following script.

python generate_expert_data.py

Now, we can train the novice agent using the DAgger algorithm on any custom track. Note that the following script uses the tracks in the tracks/testing folder.

python dagger.py

dagger

-----------------------------------------------------

Authors

Developed by Anirudh Rajiv Menon and Unnikrishnan Menon.

License

License

This project is licensed under the Apache 2.0 License - see the LICENSE file for details

racer_ai's People

Contributors

7entropy7 avatar axe76 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

beanbois

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.