Skip to content

OpenAI Gym wrapper for Metacar: A reinforcement learning environment for self-driving cars in the browser.

Notifications You must be signed in to change notification settings

AI-Guru/gym-metacar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gym-Metacar.

OpenAI Gym wrapper for Metacar: A reinforcement learning environment for self-driving cars in the browser. Uses selenium to wrap the original web-code.

If you want to learn more, go to the official metacar homepage: https://www.metacar-project.com

Always star if you like.

If you enjoy this repo, please give it a star. That would be very appreciated!

Getting in touch.

If you got any bug reports or feature requests, please open an issue here on GitHub.

Installation.

Straightforward:

pip/conda install git+https://github.com/AI-Guru/gym-metacar

Note: Please make sure that chromedriver is installed on your system.

Mac.

brew cask install google-chrome
brew cask install chromedriver

Linux.

apt install chromium-chromedriver
apt-get install -y libglib2.0-0 libnss3 libgconf-2-4 libfontconfig1

Colaboratory.

!apt install chromium-chromedriver
!pip install git+https://github.com/AI-Guru/gym-metacar.git

Windows.

Consider moving to Mac/Linux ;)

Environments.

A total of four different levels are available. Each can be instantiated with either discrete or continous action spaces.

The complete list of environments:

  • metacar-level0-discrete-v0
  • metacar-level0-continuous-v0
  • metacar-level1-discrete-v0
  • metacar-level1-continuous-v0
  • metacar-level2-discrete-v0v0
  • metacar-level2-continuous-v0
  • metacar-level3-discrete-v0
  • metacar-level3-continuous-v0

How to run.

As with all gym-compatible environments, gym-metacar is very easy to run.

import gym
import gym_metacar

env = gym.make("metacar-level0-discrete-v0")
env.reset()
print(env.observation_space)
print(env.action_space)

for step in range(100):
    print(step)
    observation, reward, done, info = env.step(env.action_space.sample())
    env.render()
env.close()

Screenshots.

Level0.

A sceenshot of gym-metacar in action.

Level1.

A sceenshot of gym-metacar in action.

Level2.

A sceenshot of gym-metacar in action.

Level3.

A sceenshot of gym-metacar in action.

Wrappers.

As all good environments, gym-metacar comes with wrappers.

  • gym_metacar.wrappers.LidarObservationWrapper: Just uses the lidar-data in the observations.
  • gym_metacar.wrappers.LinearObservationWrapper: Just uses the linear-data in the observations.
  • gym_metacar.wrappers.TerminateWrapper: Terminates the simulation if the reward is -1.
  • gym_metacar.wrappers.StepLimitTerminateWrapper: Stops the simulation when steps limit exceeded.
  • gym_metacar.wrappers.ClipRewardsWrapper : Clips the rewards to [-1, 1].

Example:

import gym
import gym_metacar
from gym_metacar.wrappers import *

env_id = "metacar-level3-discrete-v0"
env = gym.make(env_id)
env = LinearObservationWrapper(env)
env = ClipRewardsWrapper(env)
env = DummyVecEnv([lambda:env])
env = VecFrameStack(env, n_stack=4)

Rendering with Web-Driver.

Per default, the environment renderer uses PyGame. If you want to use the web-renderer, you have to instantiate it explicitely:

import gym
import gym_metacar
from gym_metacar.wrappers import *

env_id = "metacar-level3-discrete-v0"
env = gym.make(env_id)
env.enable_webrenderer() # This enables the web-renderer.
[...]

Deep Reinforcement Learning.

The examples folders contains a DQN-agent. Note: This requires stable baselines.

Discrete action space.

For training:

python metacar_dqn_train.py

For running after training:

python metacar_dqn_enjoy.py

Continuous action space.

For training:

python metacar_ddpg_train.py

For running after training:

python metacar_dpg_enjoy.py

Thank you!

About

OpenAI Gym wrapper for Metacar: A reinforcement learning environment for self-driving cars in the browser.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published