An open-ended driving simulator with infinite scenes
Project description
MetaDrive: AI Research for Generalizable and Interpretable Machine Autonomy
MetaDrive is a driving simulator with the following key features:
- Compositional: It supports generating infinite scenes with various road maps and traffic settings for the research of generalizable RL.
- Lightweight: It is easy to install and run. It can run up to +1000 FPS on a standard PC.
- Realistic: Accurate physics simulation and multiple sensory input including Lidar, RGB images, top-down semantic map and first-person view images.
🛠 Quick Start
Install MetaDrive via:
git clone https://github.com/metadriverse/metadrive.git
cd metadrive
pip install -e .
or
pip install metadrive-simulator
Note that the program is tested on both Linux and Windows. Some control and display issues in MacOS wait to be solved
You can verify the installation of MetaDrive via running the testing script:
# Go to a folder where no sub-folder calls metadrive
python -m metadrive.examples.profile_metadrive
Note that please do not run the above command in a folder that has a sub-folder called ./metadrive
.
🚕 Examples
We provide examples to demonstrate features and basic usages of MetaDrive after the local installation.
There is an .ipynb
example which can be directly opened in Colab.
Also, you can try examples in the documentation directly in Colab! See more details in Documentations.
Single Agent Environment
Run the following command to launch a simple driving scenario with auto-drive mode on. Press W, A, S, D to drive the vehicle manually.
python -m metadrive.examples.drive_in_single_agent_env
Run the following command to launch a safe driving scenario, which includes more complex obstacles and cost to be yielded.
python -m metadrive.examples.drive_in_safe_metadrive_env
Multi-Agent Environment
You can also launch an instance of Multi-Agent scenario as follows
python -m metadrive.examples.drive_in_multi_agent_env --env roundabout
--env
accepts following parmeters: roundabout
(default), intersection
, tollgate
, bottleneck
, parkinglot
, pgmap
.
Adding --top_down
can launch top-down pygame renderer.
Real Environment
Running the following script enables driving in a scenario constructed from nuScenes dataset or Waymo dataset.
python -m metadrive.examples.drive_in_real_env
The default real-world dataset is nuScenes.
Use --waymo
to visualize Waymo scenarios.
Traffic vehicles can not response to surrounding vchicles if directly replaying them.
Add argument --reactive_traffic
to use an IDM policy control them and make them reactive.
Press key r
for loading a new scenario, and b
or q
for switching perspective.
Basic Usage
To build the RL environment in python script, you can simply code in the Farama Gymnasium format as:
from metadrive.envs.metadrive_env import MetaDriveEnv
env = MetaDriveEnv(config={"use_render": True})
obs, info = env.reset()
for i in range(1000):
obs, reward, terminated, truncated, info = env.step(env.action_space.sample())
if terminated or truncated:
env.reset()
env.close()
🏫 Documentations
Please find more details in: https://metadrive-simulator.readthedocs.io
Running Examples in Doc
The documentation is built with .ipynb
so every example can run locally
or with colab. For Colab running, on the Colab interface, click “GitHub,” enter the URL of MetaDrive:
https://github.com/metadriverse/metadrive, and hit the search icon.
After running examples, you are expected to get the same output and visualization results as the documentation!
For example, hitting the following icon opens the source .ipynb
file of the documentation section: Environments.
📎 References
If you use MetaDrive in your own work, please cite:
@article{li2022metadrive,
title={Metadrive: Composing diverse driving scenarios for generalizable reinforcement learning},
author={Li, Quanyi and Peng, Zhenghao and Feng, Lan and Zhang, Qihang and Xue, Zhenghai and Zhou, Bolei},
journal={IEEE Transactions on Pattern Analysis and Machine Intelligence},
year={2022}
}
🎉 Relevant Projects
Learning to Simulate Self-driven Particles System with Coordinated Policy Optimization
Zhenghao Peng, Quanyi Li, Chunxiao Liu, Bolei Zhou
NeurIPS 2021
[Paper]
[Code]
[Webpage]
[Poster]
[Talk]
[Results&Models]
Safe Driving via Expert Guided Policy Optimization
Zhenghao Peng*, Quanyi Li*, Chunxiao Liu, Bolei Zhou
Conference on Robot Learning (CoRL) 2021
[Paper]
[Code]
[Webpage]
[Poster]
Efficient Learning of Safe Driving Policy via Human-AI Copilot Optimization
Quanyi Li*, Zhenghao Peng*, Bolei Zhou
ICLR 2022
[Paper]
[Code]
[Webpage]
[Poster]
[Talk]
Human-AI Shared Control via Policy Dissection
Quanyi Li, Zhenghao Peng, Haibin Wu, Lan Feng, Bolei Zhou
NeurIPS 2022
[Paper]
[Code]
[Webpage]
And more:
-
Yang, Yujie, Yuxuan Jiang, Yichen Liu, Jianyu Chen, and Shengbo Eben Li. "Model-Free Safe Reinforcement Learning through Neural Barrier Certificate." IEEE Robotics and Automation Letters (2023).
-
Feng, Lan, Quanyi Li, Zhenghao Peng, Shuhan Tan, and Bolei Zhou. "TrafficGen: Learning to Generate Diverse and Realistic Traffic Scenarios." (ICRA 2023)
-
Zhenghai Xue, Zhenghao Peng, Quanyi Li, Zhihan Liu, Bolei Zhou. "Guarded Policy Optimization with Imperfect Online Demonstrations." (ICLR 2023)
Acknowledgement
The simulator can not be built without the help from Panda3D community and the following open-sourced projects:
- panda3d-simplepbr: https://github.com/Moguri/panda3d-simplepbr
- panda3d-gltf: https://github.com/Moguri/panda3d-gltf
- RenderPipeline (RP): https://github.com/tobspr/RenderPipeline
- Water effect for RP: https://github.com/kergalym/RenderPipeline
- procedural_panda3d_model_primitives: https://github.com/Epihaius/procedural_panda3d_model_primitives
- DiamondSquare for terrain generation: https://github.com/buckinha/DiamondSquare
- KITSUNETSUKI-Asset-Tools: https://github.com/kitsune-ONE-team/KITSUNETSUKI-Asset-Tools
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for metadrive-simulator-0.4.2.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | bcda7d07146128161b0bc2cc337e01612b9222202706370043b52f7936a8a277 |
|
MD5 | 2a3f322b7269434dcae121d4aa6c4fe6 |
|
BLAKE2b-256 | c47f625567000c2753cfff8454db8baac03df068383e93565f385ec657dc42f7 |
Hashes for metadrive_simulator-0.4.2.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6fff20b931bb956c55e0e81bf1f6b641169a84a4c853435a8b26bd51c8e9876 |
|
MD5 | 27afd7402bd76f55658c5f79aa3f460f |
|
BLAKE2b-256 | 05270ea2b66adc1947a4077699a5e75bd9e7a2751d07075c4a5182c9bc100985 |