跳转到内容

C402 实验:追踪 LeRobot 数据集中的动作

每一个在人类数据上训练的策略都依赖于一个很容易弄错的决定:action 列中的数字是什么意思。公开数据集并不共用一种约定(公开数据集如何存储状态和动作)。在这个实验中,你打开一个 LeRobot 格式的、记录人手运动的公开第一人称数据集,找到它的动作定义,用数据核对这个定义,并弄清训练加载器必须对它做什么。B 部分比较一个以不同方式存储动作的手持夹爪数据集。

加载代码是 LeRobot 自己的,来自它的数据集文档和它的加载示例。你在其上添加的检查只用到 NumPy 和 SciPy。方括号标出由你填写的值。先学完第 1 到第 4 课,并把检查清单放在手边。

A 部分:RoboX lerobot-dataset B 部分:UMI-Live
它记录什么 第一人称的人手示范,从视频中追踪得到 两个带腕部相机的手持夹爪
规模(卡片) 28 个 episode,7,730 帧,15 个任务,53.6 MB 3,255 个 episode,39.705 小时
格式 LeRobot v3.0 LeRobot v3
访问 需申请访问:登录后在页面上接受条件 开放
许可协议 robox-commercial-nonexclusive-v1;卡片说允许商业使用 Apache-2.0
卡片 RoboXTechnologies/lerobot-dataset brandonyang/umi-live-dataset

两个数据集在采集时都不涉及机器人。A 部分是从第一人称相机看到的人的徒手。B 部分是人拿着夹爪设备;它的相机在夹爪上。在你的笔记中,把这两种采集方式,以及你之后要为之训练的任何机器人,放在不同的列里。

RoboX 的许可协议不是开源许可协议。它的卡片写明:“This dataset is distributed under its stated commercial terms, not an open-source licence, despite the Hub license: other tag.”(意为:本数据集按其声明的商业条款分发,不是开源许可协议,尽管 Hub 上的标签是 license: other。)完整条款在 meta/robox_export.json 中;在把数据用于本练习之外的任何用途之前先读它们(数据集许可协议与访问方式)。

A 部分:一个第一人称手部数据集

Section titled “A 部分:一个第一人称手部数据集”

LeRobot 需要 Python 3.12 或更高版本。它的安装指南列出了一个 dataset 附加依赖,用于 “Loading & creating datasets”(意为:加载和创建数据集)。在一个新的虚拟环境中:

终端窗口
pip install 'lerobot[dataset]'

记下你安装的版本(pip show lerobot)。本实验中的代码依据的是 LeRobot 仓库的提交 d490e47(版本 0.7.1,2026 年 11 月);导入路径 from lerobot.datasets import LeRobotDataset 是它当前文档所用的路径。

在登录 Hugging Face 的状态下打开数据集页面并接受它的条件。然后从命令行登录,LeRobot 的数据集工具指南说对 “a private or gated dataset”(意为:私有的或需申请访问的数据集)要这样做:

终端窗口
hf auth login

如果失败:加载时出现 401 或 403 错误,意味着你所用令牌对应的账号没有接受这些条件。

在加载任何东西之前,根据卡片填写这张表:

问题 卡片怎么说
状态值从哪里来?
位置在哪个坐标系中?
action[t] 存的是什么?
手腕旋转的变化是怎样写的?
是否做过任何机器人重定向?
帧率是多少,是否经过验证?
哪些帧是插补的,这记录在哪里?

你应该得到:状态来自 MediaPipe 手部追踪,约 3.7% 的帧是插补的,并在 meta/robox_frame_masks.parquet 中标记;手腕位置 “in the egocentric camera frame”(意为:在第一人称相机坐标系中);动作是 “the per-channel delta to the next frame, where the wrist rotation delta is a 3-D relative rotation vector rotvec(q[t+1] . inverse(q[t])) rather than a quaternion subtraction”(意为:各通道到下一帧的增量,其中手腕旋转增量是一个 3 维的相对旋转向量 rotvec(q[t+1] . inverse(q[t])),而不是四元数相减);并且没有重定向:“No robot retargeting is applied. target_embodiment is null and no robot telemetry is present.”(意为:没有做机器人重定向。target_embodiment 为 null,也没有机器人遥测数据。)卡片还补充说:“FPS is declared, not independently verified.”(意为:FPS 是声明值,未经独立验证。)实用指南的模式定义表列出了 15 个状态通道和 14 个动作通道。

LeRobotDatasetMetadata 只读取轻量的元数据文件。下面的代码来自 LeRobot 的加载示例,改了 repo id:

from pprint import pprint
from lerobot.datasets import LeRobotDataset, LeRobotDatasetMetadata
repo_id = "RoboXTechnologies/lerobot-dataset"
ds_meta = LeRobotDatasetMetadata(repo_id)
print(f"Total number of episodes: {ds_meta.total_episodes}")
print(f"Frames per second used during data collection: {ds_meta.fps}")
print(f"Robot type: {ds_meta.robot_type}")
print(f"keys to access images from cameras: {ds_meta.camera_keys=}\n")
pprint(ds_meta.features)

你应该看到与卡片一致的值:28 个 episode,30 fps,机器人类型标签 robox_ego_hand,一个相机键,以及形状为 15 和 14 的 observation.state 和 action。记下任何不一致的值。

如果失败并提示 “Your dataset must be tagged with a codebase version”(意为:你的数据集必须打上代码库版本的标签),说明这个仓库没有 v3.0 这样的版本标签,而 LeRobot 默认会查找它。给 LeRobotDatasetMetadata 和 LeRobotDataset 传入 revision="main";当 revision 不是版本号时,LeRobot 会跳过标签查找(datasets/utils.py 中的 get_safe_version 以及元数据加载器)。错误信息中创建标签的代码需要对仓库的写权限,是给仓库所有者用的,不是给你用的。

这个数据集很小,所以把它整个加载进来,然后像加载示例那样,从 episode 元数据中取出 episode 0 的帧范围:

import numpy as np
dataset = LeRobotDataset(repo_id)
episode_index = 0
from_idx = dataset.meta.episodes["dataset_from_index"][episode_index]
to_idx = dataset.meta.episodes["dataset_to_index"][episode_index]
state = np.stack([dataset[i]["observation.state"].numpy() for i in range(from_idx, to_idx)])
action = np.stack([dataset[i]["action"].numpy() for i in range(from_idx, to_idx)])
print(state.shape, action.shape)

你应该看到两个行数相同的数组,分别为 15 列和 14 列宽。每次 dataset[i] 还会解码视频帧,所以这需要一点时间。

由状态重建卡片所描述的动作,然后比较。SciPy 的 Rotation.from_quat 接受标量在后顺序的四元数,即 (x, y, z, w),也就是卡片列出它们的顺序(SciPy Rotation):

from scipy.spatial.transform import Rotation as R
pos, quat, rest = state[:, 0:3], state[:, 3:7], state[:, 7:15]
exp_pos = pos[1:] - pos[:-1]
exp_rot = (R.from_quat(quat[1:]) * R.from_quat(quat[:-1]).inv()).as_rotvec()
exp_rest = rest[1:] - rest[:-1]
expected = np.concatenate([exp_pos, exp_rot, exp_rest], axis=1)
diff = np.abs(action[:-1] - expected)
print("max |diff| wrist position:", diff[:, 0:3].max())
print("max |diff| wrist rotation:", diff[:, 3:6].max())
print("max |diff| fingers and pinches:", diff[:, 6:14].max())
print("action at the episode's last frame:", action[-1])

R.from_quat(q1) * R.from_quat(q0).inv() 先施加第一个旋转的逆,再施加第二个旋转,也就是 q[t+1] · inverse(q[t])。

记下三个最大差值,以及最后一帧的动作存的是什么;卡片没有说一个 episode 的最后一个动作包含什么。如果差值不接近零,在下任何结论之前先对照 meta/robox_feature_semantics.json 检查通道顺序,并记下哪些通道不一致。

第 7 步:问一问动作在哪个坐标系中

Section titled “第 7 步:问一问动作在哪个坐标系中”

手腕位置在第一人称相机坐标系中,而相机随佩戴者的头部运动。卡片的特征列表中没有相机位姿。所以位置增量把手部运动和头部运动混在了一起:手不动而头转动,仍然会产生一个非零的动作(从手部动作中去除头部运动)。

From a head-camera wrist pose to a robot target The chain of transforms that VideoDex (Shaw et al., 2022) writes out to move a wrist pose seen by a head-worn camera into a robot's frame: M_Robot_Wrist = T_Robot_World times M_World_C1 times M_C1_Ct times M_Ct_Wrist, read right to left as four steps. Step 1, wrist in the current camera frame: fit a MANO hand and solve Perspective-n-Point, or place the root metrically with depth or stereo. Step 2, cancel head motion: camera poses from SLAM relate the current frame to the first. Step 3, align with gravity, because the robot is always upright: an IMU measures gravity directly; for archive video VideoDex fits the normal of floor-parallel surfaces. Step 4, place the trajectory in the robot workspace with a fixed rotation and offset. Below, VideoDex's Table 3 compares gravity-alignment methods on test objects (success on Place, Cover, Uncover): surface normals 0.80, 0.63, 0.92; a fixed pitch 0.55, 0.50, 0.77; the camera's own stabilisation-sensor data 0.70, 0.67, 0.90. From a head-camera wrist pose to a robot target VideoDex's transform chain, applied right to left M_Robot^Wrist = T_Robot^World · M_World^C1 · M_C1^Ct · M_Ct^Wrist 1. Wrist in camera M_Ct^Wrist MANO fit + PnP; depth or stereo places it metrically 2. Cancel head M_C1^Ct SLAM camera poses relate frame t to the first frame 3. Align gravity M_World^C1 IMU gravity vector; archive video: fit floor-parallel normals 4. Robot workspace T_Robot^World fixed rotation and offset into the robot's reach Gravity alignment compared (step 3): VideoDex Table 3, success on test objects 0.80 0.70 0.55 Place 0.63 0.67 0.50 Cover 0.92 0.90 0.77 Uncover surface normals camera stabilisation data fixed pitch
VideoDex's chain from a wrist seen by a head-worn camera to a robot target, applied right to left: wrist in the current camera frame (MANO fit and PnP), head motion cancelled with SLAM poses, gravity alignment, then a fixed placement in the robot's workspace. Below, its Table 3 comparison of gravity alignment on test objects: fitted floor-parallel surface normals scored 0.80 / 0.63 / 0.92 on Place / Cover / Uncover, against 0.55 / 0.50 / 0.77 for a fixed pitch and 0.70 / 0.67 / 0.90 for the camera's own stabilisation-sensor data. Source: Shaw et al., VideoDex (2022).

记下你对这个问题的回答:只靠这个数据集,加载器能否像 EgoMimic 和 EgoVerse 那样,在当前时间步的相机坐标系中表示未来的手腕位置?说出还需要什么(在当前相机坐标系中表示动作)。

策略预测的是一段未来动作组成的动作块。LeRobot 用 delta_timestamps 构建动作块,它是以秒为单位的偏移量,必须是 1/fps 的整数倍。下面的代码来自加载示例:

H = 16 # chunk length, your choice
delta_timestamps = {"action": [t / dataset.fps for t in range(H)]}
dataset = LeRobotDataset(repo_id, delta_timestamps=delta_timestamps)
sample = dataset[from_idx]
print(sample["action"].shape) # (H, 14)
print(sample["action_is_pad"]) # True where the window ran past the episode's end

在一个 episode 接近结尾的地方,窗口会越过最后一帧。这时 LeRobot 重复该 episode 的最后一行,并在 action_is_pad 中标记这些位置(LeRobot 的 datasets/utils.py 中的 delta_window 函数)。在结尾前几帧处的一个样本上检查这一点。

这个动作块的每一行都是一个逐帧增量。练习:把一个动作块变成相对于 t0 处那一帧的轨迹,方法是按顺序对位置增量求和、对旋转向量做复合。写下为什么误差会沿着动作块累积,并与 UMI 的比较中增量那一行相比较,在那里增量动作的成绩是 16/20,相对轨迹是 20/20。LeRobot 的动作表示指南解释了同样的区别。

Relative, delta and absolute actions compared Top: three schematics of the same five-step gripper trajectory written three ways, each with UMI's cup-arrangement result out of 20 trials. Relative trajectory, every pose expressed relative to the gripper pose at t0, the moment the chunk is predicted: 20 of 20. Delta, each pose relative to the step just before it: 16 of 20. Absolute, poses in one fixed frame, here the SLAM map and the robot base calibrated to the same fiducial markers on the table: 5 of 20, which the paper attributes to inaccurate calibration between the two frames. Bottom: VISTA's component ablation on FastUMI Pro data with a vision-language-action model: full model 68.3% success; without proprioceptive state 61.9%; without proprioceptive state and with absolute instead of delta actions 53.1%. The same trajectory, three action spaces (UMI, cup arrangement) Relative trajectory each pose relative to t0 t0 20/20 successful trials Delta each pose relative to the last t0 16/20 successful trials Absolute poses in one fixed frame fixed frame 5/20 successful trials VISTA ablation, FastUMI Pro data (success rate) Full model 68.3% No proprioceptive state 61.9% No state, absolute actions 53.1% 0%25%50%75%100%
Three ways to write the same gripper trajectory as actions, and what each scored. Top: UMI's cup-arrangement ablation, 20 trials each (Chi et al., 2024); the absolute baseline used the SLAM frame and the robot base calibrated to the same table markers. Bottom: VISTA's component ablation on FastUMI Pro data, where the last row removes proprioceptive state and also swaps delta for absolute actions (Yang et al., 2026). The two studies use different tasks and models, so compare within a panel. The trajectory drawn is schematic.

插补标记在一个单独的文件中。用 Hugging Face Hub 客户端的 hf_hub_download 取得它,并用 pandas 打开:

import pandas as pd
from huggingface_hub import hf_hub_download
path = hf_hub_download(repo_id=repo_id, filename="meta/robox_frame_masks.parquet", repo_type="dataset")
masks = pd.read_parquet(path)
print(masks.columns.tolist())
print(masks.head())

记下列名,然后数出 episode 0 中插补的帧,并检查其中是否有落在你在第 8 步构建的动作块之内的。卡片给出的插补帧比例总体约为 3.7%。跨越一个插补帧计算出的动作,是估计值之间的增量,而不是测量值之间的增量。

写一段训练工程师可以依赖的文字:状态布局和单位;action[t] 存的是什么,以及它在一个 episode 的最后一帧存的是什么;位置所在的坐标系,以及头部运动能否去除;旋转是怎样写的;插补的比例;许可协议;以及没有做重定向,所以机器人要先经过第 2 课中的步骤,才能使用这些动作。

B 部分:一个采用不同约定的手持夹爪数据集

Section titled “B 部分:一个采用不同约定的手持夹爪数据集”

UMI-Live 是开放的,采用 Apache-2.0,但 3,255 个 episode 对一个练习来说下载量太大,所以这一部分读卡片和元数据,并在浏览器中查看一个 episode。

UMI-Live 的卡片用直白的话定义了它的约定。状态是 14 个值,两个夹爪按先左后右的顺序,每个为 [x, y, z, rx, ry, rz, gripper],是相对于该夹爪自己的 episode 起点的位姿,朝向用旋转向量表示,夹爪开口归一化为从 0(闭合)到 1(张开)。它的动作是状态在同一帧的副本:“It is not the previous or next row, a velocity, or a precomputed action chunk. Training loaders must select future target frames, respect episode boundaries, and convert them to the desired policy representation.”(意为:它不是上一行或下一行,不是速度,也不是预先计算好的动作块。训练加载器必须选取未来的目标帧,遵守 episode 边界,并把它们转换成所需的策略表示。)它还提醒说,它的各个夹爪是按不同的行程范围归一化的:“These calibration ranges are source-specific, not interchangeable.”(意为:这些标定范围因来源而异,不能互换。)(UMI-Live 卡片)。

用 repo_id = "brandonyang/umi-live-dataset" 运行第 4 步的元数据代码,并传入 revision="main":在 2026-11-08,这个仓库没有 v3.0 标签,所以默认的查找会失败。当天用 LeRobot 0.7.0 检查,这次调用返回了 3,255 个 episode、30 fps、没有机器人类型、两个相机键(observation.images.umi1 和 observation.images.umi2)以及 14 个值的状态和动作。然后在 LeRobot Dataset Visualizer 中打开 episode 0,这是 LeRobot 的数据集工具指南所描述的浏览器内查看器,它播放各路相机,并把状态和动作画在一起。

你应该看到两路腕部相机视频,以及形状相同的状态图和动作图,因为一个是另一个的副本。如果查看器加载不出来,元数据输出和卡片对 B3 来说就够了。

RoboX(A 部分) UMI-Live(B 部分)
追踪的是什么 一只徒手,从视频中追踪 两个夹爪设备
位置坐标系 每一帧的第一人称相机 每个夹爪自己的 episode 起点
状态中的旋转 单位四元数 旋转向量
action[t] 到下一帧的增量 状态在同一帧的副本
手指或夹持通道 5 个手指弯曲度和 3 个捏合距离 归一化宽度,0 为闭合,1 为张开
加载器必须做什么 还原或保留增量;处理头部运动 选取未来的帧并转换它们,就像 UMI 的相对轨迹动作那样

练习:对 UMI-Live,写出加载器为一个夹爪在索引 t0 处构建相对轨迹动作块所要采取的步骤,不跨越 episode 边界。UMI 策略页面有一条能起草这段代码的提示词;对照你的步骤检查它的输出。