Giter Site home page Giter Site logo

tennis's Introduction

Tennis

Tennis Unity Environment

In this project, I used DDPG model to train 2 agents playing tennis. This environment has 24 states per agent. And each agent has 2 continuous actions or degrees of freedom. The environment is episodic, and to solve it, one of the agents must attain a average score of +0.5 over 100 consecutive episodes.

Summary

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

Install Python

I have tested this repo with Python 3.9 and 3.10. To continue, install either of these versions on your local machine. With Python installed, I suggest you create a virtual environment to install required libraries:

python -m venv desired_path_for_env

Activate this environment before moving to next step. For addirional help, check Python documentation here.

Install PIP Packages

The required packages for this project are listed in requirements file. To install these libraries, from the repo folder, run the following command in your virtual env:

python -m pip install -r requirements.txt

Download Unity Tennis

The already built Unity environment for this project is accessible from following links:

Linux: click here

Mac OSX: click here

Windows (32-bit): click here

Windows (64-bit): click here

Decompress (unzip) the downloaded file and copy it to the repo folder.

Running the scripts

The training and testing scripts are located in scripts folder.

Training

To train the model, use train_agent.py script. This script accepts the following arguments:

  • Path to downloaded Unity App: --unity-app
  • Target Score to save trained model: --target-score
cd scripts
python train_agent.py --unity-app Tennis.app --target-score 0.5

On my machine, the environment was solved in 722 episodes:

Episode 100	Average Score: 0.00400
Episode 200	Average Score: 0.00780
Episode 300	Average Score: 0.00600
Episode 400	Average Score: 0.02550
Episode 500	Average Score: 0.04760
Episode 600	Average Score: 0.12620
Episode 700	Average Score: 0.31120

Environment solved in 722 episodes!	Average Score: 0.50260
Trained model weights saved to: checkpoint_722.pth

Saved Trained Actor Checkpoint

Saved Trained Critic Checkpoint

Trained Model Scores

Testing

To compare a trained agent with a untrained one, use [test_agent.py] script. This script accepts the following arguments:

  • Path to downloaded Unity App: --unity-app
  • Path to saved actor model checkpoint: --actor-checkpoint-file
  • Path to saved critic model checkpoint: --critic-checkpoint-file
cd scripts
python test_agent.py --unity-app Tennis.app --actor-checkpoint-file ../checkpoints/actor_checkpoint_722.pth --critic-checkpoint-file ../checkpoints/critic_checkpoint_722.pth

Output:

[>] Try untrained Tennis agents.
[-] Score: 0.2700000088661909
[>] Try a trained DDPG agent to play tennis.
[-] Score: 0.7650000127032399

Watch Youtube Video

Click on below GIF animation to open youtube video:

Watch the video

Author

License

This project is open source under MIT License and free to use. It is for educational purposes only and provided as is.

I have used parts of DDPG_Pendulum scripts in Udacity DRL repo under MIT License. Scripts in mlagents are based on Udacity DRL repo with minor modifications.

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.