Giter Site home page Giter Site logo

wmlu / gym-metacar Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ai-guru/gym-metacar

0.0 0.0 0.0 457 KB

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

Python 85.37% HTML 14.63%

gym-metacar's Introduction

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!

gym-metacar's People

Contributors

ai-guru avatar phlipse avatar

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.