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
If you enjoy this repo, please give it a star. That would be very appreciated!
If you got any bug reports or feature requests, please open an issue here on GitHub.
- Becoma a patron.
- Subscribe to my newsletter.
- Visit by homepage/blog.
- Join me on Slack.
- Add me on LinkedIn.
- Add me on Facebook.
Straightforward:
pip/conda install git+https://github.com/AI-Guru/gym-metacar
Note: Please make sure that chromedriver
is installed on your system.
brew cask install google-chrome
brew cask install chromedriver
apt install chromium-chromedriver
apt-get install -y libglib2.0-0 libnss3 libgconf-2-4 libfontconfig1
!apt install chromium-chromedriver
!pip install git+https://github.com/AI-Guru/gym-metacar.git
Consider moving to Mac/Linux ;)
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
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()
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)
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.
[...]
The examples
folders contains a DQN-agent. Note: This requires stable baselines.
For training:
python metacar_dqn_train.py
For running after training:
python metacar_dqn_enjoy.py
For training:
python metacar_ddpg_train.py
For running after training:
python metacar_dpg_enjoy.py