2024-03-22 21:25:23 +08:00
< p align = "center" >
< picture >
< source media = "(prefers-color-scheme: dark)" srcset = "media/lerobot-logo-thumbnail.png" >
< source media = "(prefers-color-scheme: light)" srcset = "media/lerobot-logo-thumbnail.png" >
< img alt = "LeRobot, Hugging Face Robotics Library" src = "media/lerobot-logo-thumbnail.png" style = "max-width: 100%;" >
< / picture >
< br / >
< br / >
< / p >
2024-03-20 00:29:25 +08:00
2024-03-27 19:49:10 +08:00
< div align = "center" >
2024-03-20 00:29:25 +08:00
2024-04-27 15:48:02 +08:00
[](https://github.com/huggingface/lerobot/actions/workflows/nightly-tests.yml?query=branch%3Amain)
2024-03-27 19:49:10 +08:00
[](https://codecov.io/gh/huggingface/lerobot)
[](https://www.python.org/downloads/)
[](https://github.com/huggingface/lerobot/blob/main/LICENSE)
[](https://pypi.org/project/lerobot/)
[](https://pypi.org/project/lerobot/)
[](https://github.com/huggingface/lerobot/tree/main/examples)
2024-04-16 19:37:20 +08:00
[](https://github.com/huggingface/lerobot/blob/main/CODE_OF_CONDUCT.md)
2024-03-27 19:49:10 +08:00
[](https://discord.gg/s3KuuzsPFb)
2024-03-27 00:23:46 +08:00
2024-03-27 19:49:10 +08:00
< / div >
2024-03-27 23:35:32 +08:00
< h3 align = "center" >
< p > State-of-the-art Machine Learning for real-world robotics< / p >
< / h3 >
2024-03-27 19:49:10 +08:00
---
2024-03-20 00:29:25 +08:00
2024-05-05 01:44:39 +08:00
🤗 LeRobot aims to provide models, datasets, and tools for real-world robotics in PyTorch. The goal is to lower the barrier to entry to robotics so that everyone can contribute and benefit from sharing datasets and pretrained models.
2024-03-20 00:29:25 +08:00
2024-03-22 21:25:23 +08:00
🤗 LeRobot contains state-of-the-art approaches that have been shown to transfer to the real-world with a focus on imitation learning and reinforcement learning.
2024-03-20 00:29:25 +08:00
2024-03-22 21:25:23 +08:00
🤗 LeRobot already provides a set of pretrained models, datasets with human collected demonstrations, and simulated environments so that everyone can get started. In the coming weeks, the plan is to add more and more support for real-world robotics on the most affordable and capable robots out there.
2024-03-20 18:19:55 +08:00
2024-05-04 15:58:15 +08:00
🤗 LeRobot hosts pretrained models and datasets on this Hugging Face community page: [huggingface.co/lerobot ](https://huggingface.co/lerobot )
2024-03-20 00:29:25 +08:00
2024-03-22 21:25:23 +08:00
#### Examples of pretrained models and environments
2024-03-20 00:29:25 +08:00
2024-03-22 21:25:23 +08:00
< table >
< tr >
< td > < img src = "http://remicadene.com/assets/gif/aloha_act.gif" width = "100%" alt = "ACT policy on ALOHA env" / > < / td >
< td > < img src = "http://remicadene.com/assets/gif/simxarm_tdmpc.gif" width = "100%" alt = "TDMPC policy on SimXArm env" / > < / td >
< td > < img src = "http://remicadene.com/assets/gif/pusht_diffusion.gif" width = "100%" alt = "Diffusion policy on PushT env" / > < / td >
< / tr >
< tr >
< td align = "center" > ACT policy on ALOHA env< / td >
< td align = "center" > TDMPC policy on SimXArm env< / td >
< td align = "center" > Diffusion policy on PushT env< / td >
< / tr >
< / table >
### Acknowledgment
- ACT policy and ALOHA environment are adapted from [ALOHA ](https://tonyzhaozh.github.io/aloha/ )
- Diffusion policy and Pusht environment are adapted from [Diffusion Policy ](https://diffusion-policy.cs.columbia.edu/ )
- TDMPC policy and Simxarm environment are adapted from [FOWM ](https://www.yunhaifeng.com/FOWM/ )
- Abstractions and utilities for Reinforcement Learning come from [TorchRL ](https://github.com/pytorch/rl )
2024-01-29 20:49:30 +08:00
## Installation
2024-03-28 17:01:33 +08:00
Download our source code:
2024-03-22 21:25:23 +08:00
```bash
2024-04-08 22:20:16 +08:00
git clone https://github.com/huggingface/lerobot.git & & cd lerobot
2024-02-28 17:57:08 +08:00
```
2024-03-28 17:01:33 +08:00
Create a virtual environment with Python 3.10 and activate it, e.g. with [`miniconda` ](https://docs.anaconda.com/free/miniconda/index.html ):
2024-03-22 21:25:23 +08:00
```bash
2024-04-08 22:20:16 +08:00
conda create -y -n lerobot python=3.10 & & conda activate lerobot
2024-02-28 17:57:08 +08:00
```
2024-04-08 22:20:16 +08:00
Install 🤗 LeRobot:
2024-03-22 21:25:23 +08:00
```bash
2024-04-27 15:48:02 +08:00
pip install .
2024-02-28 17:57:08 +08:00
```
2024-04-08 22:20:16 +08:00
For simulations, 🤗 LeRobot comes with gymnasium environments that can be installed as extras:
- [aloha ](https://github.com/huggingface/gym-aloha )
- [xarm ](https://github.com/huggingface/gym-xarm )
- [pusht ](https://github.com/huggingface/gym-pusht )
For instance, to install 🤗 LeRobot with aloha and pusht, use:
```bash
2024-04-27 15:48:02 +08:00
pip install ".[aloha, pusht]"
2024-04-08 22:20:16 +08:00
```
2024-05-04 15:58:15 +08:00
To use [Weights and Biases ](https://docs.wandb.ai/quickstart ) for experiment tracking, log in with
2024-03-22 21:25:23 +08:00
```bash
2024-03-11 20:09:46 +08:00
wandb login
```
2024-03-22 21:25:23 +08:00
## Walkthrough
2024-02-22 20:14:12 +08:00
```
2024-03-22 21:25:23 +08:00
.
2024-05-05 04:25:45 +08:00
├── examples # contains demonstration examples, start here to learn about LeRobot
2024-03-22 21:25:23 +08:00
├── lerobot
| ├── configs # contains hydra yaml files with all options that you can override in the command line
| | ├── default.yaml # selected by default, it loads pusht environment and diffusion policy
2024-04-08 22:20:16 +08:00
| | ├── env # various sim environments and their datasets: aloha.yaml, pusht.yaml, xarm.yaml
2024-03-22 21:25:23 +08:00
| | └── policy # various policies: act.yaml, diffusion.yaml, tdmpc.yaml
| ├── common # contains classes and utilities
2024-04-08 22:20:16 +08:00
| | ├── datasets # various datasets of human demonstrations: aloha, pusht, xarm
| | ├── envs # various sim environments: aloha, pusht, xarm
2024-05-05 04:25:45 +08:00
| | ├── policies # various policies: act, diffusion, tdmpc
| | └── utils # various utilities
| └── scripts # contains functions to execute via command line
| ├── eval.py # load policy and evaluate it on an environment
| ├── train.py # train a policy via imitation learning and/or reinforcement learning
| ├── push_dataset_to_hub.py # convert your dataset into LeRobot dataset format and upload it to the Hugging Face hub
| └── visualize_dataset.py # load a dataset and render its demonstrations
2024-03-22 21:25:23 +08:00
├── outputs # contains results of scripts execution: logs, videos, model checkpoints
└── tests # contains pytest utilities for continuous integration
2024-02-22 20:14:12 +08:00
```
2024-03-22 21:25:23 +08:00
### Visualize datasets
2024-02-22 20:14:12 +08:00
2024-05-06 01:01:50 +08:00
Check out [example 1 ](./examples/1_load_lerobot_dataset.py ) that illustrates how to use our dataset class which automatically download data from the Hugging Face hub.
You can also locally visualize episodes from a dataset by executing our script from the command line:
2024-03-22 21:25:23 +08:00
```bash
2024-02-22 20:14:12 +08:00
python lerobot/scripts/visualize_dataset.py \
2024-05-05 03:02:35 +08:00
--repo-id lerobot/pusht \
--episode-index 0
2024-02-22 20:14:12 +08:00
```
2024-05-06 01:01:50 +08:00
It will open `rerun.io` and display the camera streams, robot states and actions.

2024-05-05 03:02:35 +08:00
2024-05-06 01:01:50 +08:00
Our script can also visualize datasets stored on a distant server. See `python lerobot/scripts/visualize_dataset.py --help` for more instructions.
2024-05-05 03:02:35 +08:00
2024-03-22 21:25:23 +08:00
### Evaluate a pretrained policy
2024-02-22 20:14:12 +08:00
2024-05-06 01:01:50 +08:00
Check out [example 2 ](./examples/2_evaluate_pretrained_policy.py ) that illustrates how to download a pretrained policy from Hugging Face hub, and run an evaluation on its corresponding environment.
2024-02-16 23:13:24 +08:00
2024-05-06 01:01:50 +08:00
We also provide a more capable script to parallelize the evaluation over multiple environments during the same rollout. Here is an example with a pretrained model hosted on [lerobot/diffusion_pusht ](https://huggingface.co/lerobot/diffusion_pusht ):
2024-03-22 21:25:23 +08:00
```bash
python lerobot/scripts/eval.py \
2024-05-05 19:10:48 +08:00
-p lerobot/diffusion_pusht \
2024-05-05 20:46:29 +08:00
eval.n_episodes=10 \
eval.batch_size=10
2024-03-22 21:25:23 +08:00
```
Add Aloha env and ACT policy
WIP Aloha env tests pass
Rendering works (fps look fast tho? TODO action bounding is too wide [-1,1])
Update README
Copy past from act repo
Remove download.py add a WIP for Simxarm
Remove download.py add a WIP for Simxarm
Add act yaml (TODO: try train.py)
Training can runs (TODO: eval)
Add tasks without end_effector that are compatible with dataset, Eval can run (TODO: training and pretrained model)
Add AbstractEnv, Refactor AlohaEnv, Add rendering_hook in env, Minor modifications, (TODO: Refactor Pusht and Simxarm)
poetry lock
fix bug in compute_stats for action normalization
fix more bugs in normalization
fix training
fix import
PushtEnv inheriates AbstractEnv, Improve factory Normalization
Add _make_env to EnvAbstract
Add call_rendering_hooks to pusht env
SimxarmEnv inherites from AbstractEnv (NOT TESTED)
Add aloha tests artifacts + update pusht stats
fix image normalization: before env was in [0,1] but dataset in [0,255], and now both in [0,255]
Small fix on simxarm
Add next to obs
Add top camera to Aloha env (TODO: make it compatible with set of cameras)
Add top camera to Aloha env (TODO: make it compatible with set of cameras)
2024-03-08 17:47:39 +08:00
2024-05-06 01:01:50 +08:00
Note: After training your own policy, you can re-evaluate the checkpoints with:
2024-03-22 21:25:23 +08:00
```bash
python lerobot/scripts/eval.py \
2024-05-05 20:46:29 +08:00
-p PATH/TO/TRAIN/OUTPUT/FOLDER
2024-03-22 21:25:23 +08:00
```
Add Aloha env and ACT policy
WIP Aloha env tests pass
Rendering works (fps look fast tho? TODO action bounding is too wide [-1,1])
Update README
Copy past from act repo
Remove download.py add a WIP for Simxarm
Remove download.py add a WIP for Simxarm
Add act yaml (TODO: try train.py)
Training can runs (TODO: eval)
Add tasks without end_effector that are compatible with dataset, Eval can run (TODO: training and pretrained model)
Add AbstractEnv, Refactor AlohaEnv, Add rendering_hook in env, Minor modifications, (TODO: Refactor Pusht and Simxarm)
poetry lock
fix bug in compute_stats for action normalization
fix more bugs in normalization
fix training
fix import
PushtEnv inheriates AbstractEnv, Improve factory Normalization
Add _make_env to EnvAbstract
Add call_rendering_hooks to pusht env
SimxarmEnv inherites from AbstractEnv (NOT TESTED)
Add aloha tests artifacts + update pusht stats
fix image normalization: before env was in [0,1] but dataset in [0,255], and now both in [0,255]
Small fix on simxarm
Add next to obs
Add top camera to Aloha env (TODO: make it compatible with set of cameras)
Add top camera to Aloha env (TODO: make it compatible with set of cameras)
2024-03-08 17:47:39 +08:00
2024-03-22 21:25:23 +08:00
See `python lerobot/scripts/eval.py --help` for more instructions.
2024-02-10 23:46:24 +08:00
2024-03-22 21:25:23 +08:00
### Train your own policy
2024-02-25 02:18:39 +08:00
2024-05-06 01:01:50 +08:00
Check out [example 3 ](./examples/3_train_policy.py ) that illustrates how to start training a model.
2024-02-25 02:18:39 +08:00
2024-05-06 01:01:50 +08:00
In general, you can use our training script to easily train any policy. To use wandb for logging training and evaluation curves, make sure you ran `wandb login` . Here is an example of training the ACT policy on trajectories collected by humans on the Aloha simulation environment for the insertion task:
2024-02-25 02:18:39 +08:00
```bash
2024-03-22 21:25:23 +08:00
python lerobot/scripts/train.py \
2024-05-05 04:25:45 +08:00
policy=act \
2024-05-06 01:01:50 +08:00
env=aloha \
env.task=AlohaInsertion-v0 \
dataset_repo_id=lerobot/aloha_sim_insertion_human \
2024-05-05 04:25:45 +08:00
hydra.run.dir=outputs/train/aloha_act
2024-02-25 02:18:39 +08:00
```
2024-05-06 01:01:50 +08:00
Here is an example of logs from wandb:

2024-03-15 08:30:11 +08:00
2024-05-06 01:01:50 +08:00
You can deactivate wandb by adding these arguments to the command line:
2024-03-15 08:30:11 +08:00
```
2024-05-06 01:01:50 +08:00
wandb.disable_artifact=true \
wandb.enable=false
2024-03-15 08:30:11 +08:00
```
2024-05-06 01:01:50 +08:00
Note: During training, every checkpoint is evaluated on a low number of episodes for efficiency. After training, you may want to re-evaluate your best checkpoints on more episodes or change the evaluation settings. See `python lerobot/scripts/eval.py --help` for more instructions.
2024-03-20 00:53:07 +08:00
2024-03-15 08:30:11 +08:00
2024-05-06 01:01:50 +08:00
## Contribute
2024-05-05 23:39:09 +08:00
2024-05-06 01:01:50 +08:00
If you would like to contribute to 🤗 LeRobot, please check out our [contribution guide ](https://github.com/huggingface/lerobot/blob/main/CONTRIBUTING.md ).
2024-05-05 23:39:09 +08:00
2024-05-06 01:01:50 +08:00
### Add a new dataset
2024-03-19 23:49:45 +08:00
2024-05-06 01:01:50 +08:00
To add a dataset to the hub, begin by logging in with a token that has write access, which can be generated from the [Hugging Face settings ](https://huggingface.co/settings/tokens ):
2024-03-22 21:25:23 +08:00
```bash
2024-05-06 01:01:50 +08:00
huggingface-cli login --token ${HUGGINGFACE_TOKEN} --add-to-git-credential
2024-03-19 23:49:45 +08:00
```
2024-05-06 01:01:50 +08:00
Then move your dataset folder in `data` directory (e.g. `data/aloha_ping_pong` ), and push your dataset to the hub using the following command:
2024-03-22 21:25:23 +08:00
```bash
2024-05-05 23:39:09 +08:00
python lerobot/scripts/push_dataset_to_hub.py \
--data-dir data \
2024-05-06 01:01:50 +08:00
--dataset-id aloha_ping_ping \
--raw-format aloha_hdf5 \
--community-id lerobot
2024-03-19 23:49:45 +08:00
```
2024-05-06 01:01:50 +08:00
See `python lerobot/scripts/push_dataset_to_hub.py --help` for more instructions.
2024-03-20 00:53:07 +08:00
2024-05-06 01:01:50 +08:00
If your dataset format is not supported, implement your own in `lerobot/common/datasets/push_dataset_to_hub/${raw_format}_format.py` by copying examples like [pusht_zarr ](https://github.com/huggingface/lerobot/blob/main/lerobot/common/datasets/push_dataset_to_hub/pusht_zarr_format.py ), [umi_zarr ](https://github.com/huggingface/lerobot/blob/main/lerobot/common/datasets/push_dataset_to_hub/umi_zarr_format.py ), [aloha_hdf5 ](https://github.com/huggingface/lerobot/blob/main/lerobot/common/datasets/push_dataset_to_hub/aloha_hdf5_format.py ), or [xarm_pkl ](https://github.com/huggingface/lerobot/blob/main/lerobot/common/datasets/push_dataset_to_hub/xarm_pkl_format.py ).
2024-03-20 00:53:07 +08:00
2024-03-22 18:26:55 +08:00
2024-03-27 23:56:21 +08:00
### Add a pretrained policy
2024-03-22 18:26:55 +08:00
2024-04-25 18:23:12 +08:00
```python
# TODO(rcadene, alexander-soare): rewrite this section
```
2024-05-04 15:58:15 +08:00
Once you have trained a policy you may upload it to the Hugging Face hub.
2024-03-22 18:26:55 +08:00
Firstly, make sure you have a model repository set up on the hub. The hub ID looks like HF_USER/REPO_NAME.
2024-05-01 23:17:18 +08:00
Secondly, assuming you have trained a policy, you need the following (which should all be in any of the subdirectories of `checkpoints` in your training output folder, if you've used the LeRobot training script):
2024-03-22 18:26:55 +08:00
2024-05-01 23:17:18 +08:00
- `config.json` : A serialized version of the policy configuration (following the policy's dataclass config).
2024-05-04 15:58:15 +08:00
- `model.safetensors` : The `torch.nn.Module` parameters, saved in [Hugging Face Safetensors ](https://huggingface.co/docs/safetensors/index ) format.
2024-05-01 23:17:18 +08:00
- `config.yaml` : This is the consolidated Hydra training configuration containing the policy, environment, and dataset configs. The policy configuration should match `config.json` exactly. The environment config is useful for anyone who wants to evaluate your policy. The dataset config just serves as a paper trail for reproducibility.
2024-03-22 18:26:55 +08:00
2024-05-01 23:17:18 +08:00
To upload these to the hub, run the following with a desired revision ID.
2024-03-22 18:26:55 +08:00
2024-03-22 21:25:23 +08:00
```bash
2024-05-01 23:17:18 +08:00
huggingface-cli upload $HUB_ID PATH/TO/OUTPUT/DIR --revision $REVISION_ID
2024-03-22 18:26:55 +08:00
```
If you want this to be the default revision also run the following (don't worry, it won't upload the files again; it will just adjust the file pointers):
2024-03-22 21:25:23 +08:00
```bash
2024-05-01 23:17:18 +08:00
huggingface-cli upload $HUB_ID PATH/TO/OUTPUT/DIR
2024-03-22 18:26:55 +08:00
```
2024-03-22 21:25:23 +08:00
See `eval.py` for an example of how a user may use your policy.
2024-03-27 23:56:21 +08:00
### Improve your code with profiling
2024-03-22 21:25:23 +08:00
An example of a code snippet to profile the evaluation of a policy:
```python
from torch.profiler import profile, record_function, ProfilerActivity
def trace_handler(prof):
prof.export_chrome_trace(f"tmp/trace_schedule_{prof.step_num}.json")
with profile(
activities=[ProfilerActivity.CPU, ProfilerActivity.CUDA],
schedule=torch.profiler.schedule(
wait=2,
warmup=2,
active=3,
),
on_trace_ready=trace_handler
) as prof:
with record_function("eval_policy"):
for i in range(num_episodes):
prof.step()
# insert code to profile, potentially whole body of eval_policy function
```