All Projects → xkiwilabs → DQN-using-PyTorch-and-ML-Agents

xkiwilabs / DQN-using-PyTorch-and-ML-Agents

Licence: GPL-3.0 license
A simple example of how to implement vector based DQN using PyTorch and a ML-Agents environment

Programming Languages

python
139335 projects - #7 most used programming language
Jupyter Notebook
11667 projects

Projects that are alternatives of or similar to DQN-using-PyTorch-and-ML-Agents

Pytorch Drl
PyTorch implementations of various Deep Reinforcement Learning (DRL) algorithms for both single agent and multi-agent.
Stars: ✭ 233 (+187.65%)
Mutual labels:  deep-reinforcement-learning, dqn, deep-q-network
rl implementations
No description or website provided.
Stars: ✭ 40 (-50.62%)
Mutual labels:  deep-reinforcement-learning, dqn, deep-q-network
king-pong
Deep Reinforcement Learning Pong Agent, King Pong, he's the best
Stars: ✭ 23 (-71.6%)
Mutual labels:  deep-reinforcement-learning, dqn, deep-q-network
reinforce-js
[INACTIVE] A collection of various machine learning solver. The library is an object-oriented approach (baked with Typescript) and tries to deliver simplified interfaces that make using the algorithms pretty simple.
Stars: ✭ 20 (-75.31%)
Mutual labels:  deep-reinforcement-learning, dqn, deep-q-network
Deep Reinforcement Learning
Repo for the Deep Reinforcement Learning Nanodegree program
Stars: ✭ 4,012 (+4853.09%)
Mutual labels:  deep-reinforcement-learning, dqn, ml-agents
Deep Q Learning
Minimal Deep Q Learning (DQN & DDQN) implementations in Keras
Stars: ✭ 1,013 (+1150.62%)
Mutual labels:  deep-reinforcement-learning, dqn, deep-q-network
Reinforcement Learning
Minimal and Clean Reinforcement Learning Examples
Stars: ✭ 2,863 (+3434.57%)
Mutual labels:  deep-reinforcement-learning, dqn, deep-q-network
Minimalrl
Implementations of basic RL algorithms with minimal lines of codes! (pytorch based)
Stars: ✭ 2,051 (+2432.1%)
Mutual labels:  deep-reinforcement-learning, dqn
Accel Brain Code
The purpose of this repository is to make prototypes as case study in the context of proof of concept(PoC) and research and development(R&D) that I have written in my website. The main research topics are Auto-Encoders in relation to the representation learning, the statistical machine learning for energy-based models, adversarial generation networks(GANs), Deep Reinforcement Learning such as Deep Q-Networks, semi-supervised learning, and neural network language model for natural language processing.
Stars: ✭ 166 (+104.94%)
Mutual labels:  deep-reinforcement-learning, deep-q-network
Deeprl
Modularized Implementation of Deep RL Algorithms in PyTorch
Stars: ✭ 2,640 (+3159.26%)
Mutual labels:  deep-reinforcement-learning, dqn
Machine Learning Is All You Need
🔥🌟《Machine Learning 格物志》: ML + DL + RL basic codes and notes by sklearn, PyTorch, TensorFlow, Keras & the most important, from scratch!💪 This repository is ALL You Need!
Stars: ✭ 173 (+113.58%)
Mutual labels:  deep-reinforcement-learning, dqn
Keras Rl2
Reinforcement learning with tensorflow 2 keras
Stars: ✭ 134 (+65.43%)
Mutual labels:  deep-reinforcement-learning, dqn
Deep Rl Tensorflow
TensorFlow implementation of Deep Reinforcement Learning papers
Stars: ✭ 1,552 (+1816.05%)
Mutual labels:  deep-reinforcement-learning, dqn
Deep Reinforcement Learning Algorithms
31 projects in the framework of Deep Reinforcement Learning algorithms: Q-learning, DQN, PPO, DDPG, TD3, SAC, A2C and others. Each project is provided with a detailed training log.
Stars: ✭ 167 (+106.17%)
Mutual labels:  deep-reinforcement-learning, dqn
Easy Rl
强化学习中文教程,在线阅读地址:https://datawhalechina.github.io/easy-rl/
Stars: ✭ 3,004 (+3608.64%)
Mutual labels:  deep-reinforcement-learning, dqn
Drl
Repository for codes of 'Deep Reinforcement Learning'
Stars: ✭ 172 (+112.35%)
Mutual labels:  deep-reinforcement-learning, dqn
Reinforcement Learning
🤖 Implements of Reinforcement Learning algorithms.
Stars: ✭ 104 (+28.4%)
Mutual labels:  deep-reinforcement-learning, dqn
2048 Deep Reinforcement Learning
Trained A Convolutional Neural Network To Play 2048 using Deep-Reinforcement Learning
Stars: ✭ 169 (+108.64%)
Mutual labels:  deep-reinforcement-learning, deep-q-network
Learning To Communicate Pytorch
Learning to Communicate with Deep Multi-Agent Reinforcement Learning in PyTorch
Stars: ✭ 236 (+191.36%)
Mutual labels:  deep-reinforcement-learning, dqn
Reinforcementlearning.jl
A reinforcement learning package for Julia
Stars: ✭ 192 (+137.04%)
Mutual labels:  deep-reinforcement-learning, deep-q-network

Deep Q-Network (DQN) Reinforcement Learning using PyTorch and Unity ML-Agents

A simple example of how to implement vector based DQN using PyTorch and a ML-Agents environment. Project for Udacity Danaodgree in Deep Reinforcement Learning (DRL)

The repository includes the following DQN related files:

  • dqn_agent.py -> dqn-agent implementation
  • replay_memory.py -> dqn-agent's replay buffer implementation
  • model.py -> example PyTorch neural network for vector based DQN learning
  • train.py -> initializes and implements the training processes for a DQN-agent.
  • test.py -> testes a trained DQN-agent

Code expanded and adapted from code examples provided by Udacity DRL Team, 2018.

The repository also includes Mac/Linux/Windows versions of a simple Unity environment, Banana, for testing. This Unity application and testing environment was developed using ML-Agents Beta v0.4. The version of the Banana environment employed for this project was developed for the Udacity Deep Reinforcement Nanodegree course. For more information about this course visit: https://www.udacity.com/course/deep-reinforcement-learning-nanodegree--nd893

The files in the python/. directory are the ML-Agents toolkit files and dependencies required to run the Banana environment. For more information about the Unity ML-Agents Toolkit visit: https://github.com/Unity-Technologies/ml-agents

For further details about DQN see: Mnih, V., Kavukcuoglu, K., Silver, D., Rusu, A. A., Veness, J., Bellemare, M. G., ... & Petersen, S. (2015). Human-level control through deep reinforcement learning. Nature, 518(7540), 529.

Example Unity Environment - Banana's

The example uses a modified version of the Unity ML-Agents Banana Collection example Environment. The environment includes a single agent, who can turn left or right and move forward or backward. The agent's task is to collect yellow bananas (reward of +1) that are scattered around a square game area, while avoiding purple bananas (reward of -1). For the version of Bananas employed here, the environment is considered solved when the average score over the last 100 episodes > 13.

Trained DQN-Agent Collecting Yellows Banana's

Action Space

At each time step, the agent can perform four possible actions:

  • 0 - walk forward
  • 1 - walk backward
  • 2 - turn left
  • 3 - turn right

State Spaces

The agent is trained from vector input data (not pixel input data) The state space has 37 dimensions and contains the agent's velocity, along with ray-based perception of objects around agent's forward direction. A reward of +1 is provided for collecting a yellow banana, and a reward of -1 is provided for collecting a purple banana.

Installation and Dependencies

  1. Anaconda Python 3.6: Download and installation instructions here: https://www.anaconda.com/download/

  2. Create (and activate) a new conda (virtual) environment with Python 3.6.

    • Linux or Mac:

      conda create --name yourenvnamehere python=3.6

      source activate yourenvnamehere

    • Windows:

      conda create --name yourenvnamehere python=3.6

      activate yourenvnamehere

  3. Download and save this GitHub repository.

  4. To install required dependencies (torch, ML-Agents trainers (v.4), etc...)

    • Naviagte to where you downloaded and saved this GitHub repository (e.g., yourpath/thisgithubrepository)

    • Change to the '.python/' subdirectory and run from the command line:

      pip3 install .

Download the Unity Environment

For this example project, you will not need to install Unity - this is because you can use a version of the Banana's unity environment that is already built (compiled) as a standalone application.

Download the relevant environment zip file from one of the links below. You need only to download the environment that matches your operating system:

After you have downloaded the relevant zip file, navigate to where you downloaded and saved this GitHub repository and place the file in the main folder of the repository, then unzip (or decompress) the file.

NOTE: The Banana environment is similar to, but not identical to the Banana Collector environment on the Unity ML-Agents GitHub page.

Training

  • activate the conda environment you created above

  • change the directory to the 'yourpath/thisgithubrepository' directory.

  • open train.py, find STEP 2 (lines 55 to 65) and set the relevant version of Banana to match your operating system.

  • run the following command:

    python train.py

  • training will complete once the agent reaches solved_score in train.py.

  • after training a dqnAgent_Trained_Model_datetime.path file will be saved with the trained model weights

  • a dqnAgent_scores_datetime.csv file will also be saved with the scores received during training. You can use this file to plot or assess training performance (see below figure).

  • It is recommended that you train multiple agents and test different hyperparameter settings in train.py and dqn_agent.py.

  • For more information about the DQN training algorithm and the training hyperparameters see the included Report.pdf file.

Example of agent performance (score) as a function of training episodes

Testing

  • activate the conda environment you created above

  • change the directory to the 'yourpath/thisgithubrepository' directory.

  • run the following command:

    python test.py

  • An example model weights file is included in the repository (dqnAgent_Trained_Model.pth).

  • A different model weights file can be tested by changing the model file name defined in test.py on line 109.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].