项目简介
🤗 LeRobot 旨在为 PyTorch 中的现实世界机器人提供模型、数据集和工具。目标是降低进入机器人技术的门槛,以便每个人都可以做出贡献并从共享数据集和预训练模型中受益。
🤗 LeRobot 包含最先进的方法,这些方法已被证明可以转移到现实世界,重点是模仿学习和强化学习。
🤗 乐机器人已经提供了一组预训练模型、包含人类收集演示的数据集以及无需组装机器人即可开始使用的模拟环境。在接下来的几周内,该计划将在最实惠、功能最强大的机器人上增加对现实世界机器人技术的越来越多的支持。
🤗 LeRobot 在这个 Hugging Face 社区页面上托管预训练的模型和数据集:huggingface.co/lerobot
模拟环境中预训练模型的示例
|
|
|
ACT 关于 ALOHA env 的策略
|
SimXArm 环境上的 TDMPC 策略
|
PushT 环境上的扩散策略
|
安装
下载我们的源代码:
git clone https://github.com/huggingface/lerobot.git
cd lerobot
使用 Python 3.10 创建虚拟环境并激活它,例如使用miniconda :
conda create -y -n lerobot python=3.10
conda activate lerobot
安装🤗乐机器人:
注意:
根据您的平台,如果在此步骤中遇到任何构建错误,您可能需要安装
cmake
和
build-essential
来构建我们的一些依赖项。在 Linux 上:
sudo apt-get install cmake build-essential
对于模拟,🤗乐机器人配备了可以作为额外安装的体育馆环境:
-
aloha 再见
-
xarm 魅力
-
pusht 粉色的
例如,要安装带有 aloha 和 Pusht 的 🤗 LeRobot,请使用:
pip install ".[aloha, pusht]"
要使用权重和偏差进行实验跟踪,请使用以下身份登录
演练
.
├── examples
| └── advanced
├── lerobot
| ├── configs
| | ├── default.yaml
| | ├── env
| | └── policy
| ├── common
| | ├── datasets
| | ├── envs
| | ├── policies
| | └── utils
| └── scripts
| ├── eval.py
| ├── train.py
| ├── push_dataset_to_hub.py
| └── visualize_dataset.py
├── outputs
└── tests
可视化数据集
查看示例 1 ,它演示了如何使用我们的数据集类自动从 Hugging Face 中心下载数据。
您还可以通过从命令行执行我们的脚本来本地可视化集线器上数据集的剧集:
python lerobot/scripts/visualize_dataset.py \
--repo-id lerobot/pusht \
--episode-index 0
或来自具有根DATA_DIR环境变量的本地文件夹中的数据集(在以下情况下,将在./my_local_data_dir/lerobot/pusht中搜索数据集)
DATA_DIR='./my_local_data_dir' python lerobot/scripts/visualize_dataset.py \
--repo-id lerobot/pusht \
--episode-index 0
它将打开rerun.io并显示相机流、机器人状态和动作,如下所示:
我们的脚本还可以可视化存储在远程服务器上的数据集。有关更多说明,请参阅python lerobot/scripts/visualize_dataset.py --help 。
LeRobotDataset格式
LeRobotDataset格式的数据集使用起来非常简单。它可以从 Hugging Face hub 上的存储库或本地文件夹中加载,例如dataset = LeRobotDataset("lerobot/aloha_static_coffee") ,并且可以像任何 Hugging Face 和 PyTorch 数据集一样进行索引。例如, dataset[0]将从数据集中检索单个时间帧,其中包含观察结果和一个动作,作为准备输入模型的 PyTorch 张量。
LeRobotDataset的特殊性在于,我们不是通过索引检索单个帧,而是可以通过将delta_timestamps设置为相对于索引帧的相对时间列表,根据它们与索引帧的时间关系来检索多个帧。例如,使用delta_timestamps = {"observation.image": [-1, -0.5, -0.2, 0]}对于给定索引,可以检索 4 帧:3 个“前一”帧 1 秒、0.5 秒,以及索引帧之前 0.2 秒以及索引帧本身(对应于 0 条目)。有关delta_timestamps的更多详细信息,请参阅示例1_load_lerobot_dataset.py 。
在幕后, LeRobotDataset格式使用多种方法来序列化数据,如果您打算更密切地使用此格式,这对于理解数据很有用。我们试图制作一种灵活而简单的数据集格式,涵盖强化学习和机器人技术、模拟和现实世界中存在的大多数类型的特征和特性,重点关注相机和机器人状态,但很容易扩展到其他类型的感官只要输入可以用张量表示即可。
以下是使用dataset = LeRobotDataset("lerobot/aloha_static_coffee")实例化的典型LeRobotDataset的重要细节和内部结构组织。确切的特征会随着数据集的不同而改变,但主要方面不会改变:
dataset attributes:
├ hf_dataset: a Hugging Face dataset (backed by Arrow/parquet). Typical features example:
│ ├ observation.images.cam_high (VideoFrame):
│ │ VideoFrame = {'path': path to a mp4 video, 'timestamp' (float32): timestamp in the video}
│ ├ observation.state (list of float32): position of an arm joints (for instance)
│ ... (more observations)
│ ├ action (list of float32): goal position of an arm joints (for instance)
│ ├ episode_index (int64): index of the episode for this sample
│ ├ frame_index (int64): index of the frame for this sample in the episode ; starts at 0 for each episode
│ ├ timestamp (float32): timestamp in the episode
│ ├ next.done (bool): indicates the end of en episode ; True for the last frame in each episode
│ └ index (int64): general index in the whole dataset
├ episode_data_index: contains 2 tensors with the start and end indices of each episode
│ ├ from (1D int64 tensor): first frame index for each episode — shape (num episodes,) starts with 0
│ └ to: (1D int64 tensor): last frame index for each episode — shape (num episodes,)
├ stats: a dictionary of statistics (max, mean, min, std) for each feature in the dataset, for instance
│ ├ observation.images.cam_high: {'max': tensor with same number of dimensions (e.g. `(c, 1, 1)` for images, `(c,)` for states), etc.}
│ ...
├ info: a dictionary of metadata on the dataset
│ ├ codebase_version (str): this is to keep track of the codebase version the dataset was created with
│ ├ fps (float): frame per second the dataset is recorded/synchronized to
│ ├ video (bool): indicates if frames are encoded in mp4 video files to save space or stored as png files
│ └ encoding (dict): if video, this documents the main options that were used with ffmpeg to encode the videos
├ videos_dir (Path): where the mp4 videos or png images are stored/accessed
└ camera_keys (list of string): the keys to access camera features in the item returned by the dataset (e.g. `["observation.images.cam_high", ...]`)
LeRobotDataset的每个部分使用几种广泛使用的文件格式进行序列化,即:
-
hf_dataset 使用 Hugging Face 数据集库序列化存储到 parquet
-
视频以mp4格式存储以节省空间或png文件
-
Episode_data_index 使用safetensor张量序列化格式保存
-
使用safetensor张量序列化格式保存的统计信息
-
信息使用 JSON 保存
数据集可以从 HuggingFace 中心无缝上传/下载。要处理本地数据集,您可以将DATA_DIR环境变量设置为根数据集文件夹,如上面有关数据集可视化的部分所示。
评估预训练策略
查看示例 2 ,该示例演示了如何从 Hugging Face 中心下载预训练策略,并在其相应的环境中运行评估。
我们还提供了一个功能更强大的脚本,可以在同一部署过程中并行评估多个环境。以下是lerobot/diffusion_pusht上托管的预训练模型的示例:
python lerobot/scripts/eval.py \
-p lerobot/diffusion_pusht \
eval.n_episodes=10 \
eval.batch_size=10
注意:训练您自己的策略后,您可以使用以下方法重新评估检查点:
python lerobot/scripts/eval.py -p {OUTPUT_DIR}/checkpoints/last/pretrained_model
有关更多说明,请参阅python lerobot/scripts/eval.py --help 。
训练你自己的政策
查看示例 3 ,它演示了如何使用我们的 Python 核心库来训练模型,示例 4演示了如何从命令行使用我们的训练脚本。
一般来说,您可以使用我们的训练脚本轻松训练任何策略。下面是一个在 Aloha 模拟环境中根据人类收集的轨迹训练 ACT 策略以执行插入任务的示例: