LeRobot 文件
「人在迴路」(Human-In-the-Loop)資料收集
並獲得增強的文件體驗
開始使用
「人在迴路」(Human-In-the-Loop)資料收集
「人在迴路」(Human-In-the-Loop, HIL)資料收集讓您可以透過將已訓練的策略部署到真實機器人上,並由人類操作員進行監控與適時介入來改進策略。介入數據(恢復動作與修正)會與自主執行片段一同記錄,從而產生更豐富的訓練數據集,教導策略如何處理故障。
為什麼需要「人在迴路」?
標準的行為複製(Behavioral Cloning)僅在成功的演示數據上訓練策略。在部署期間,細微的誤差可能會不斷累積,導致機器人進入訓練期間未曾見過的狀態(分佈偏移)。HIL 資料收集透過以下步驟解決此問題:
- 在真實機器人上執行已訓練的策略
- 當機器人即將失敗時,由人類進行介入
- 記錄人類的恢復與修正動作作為訓練數據
- 在合併後的數據集上對策略進行微調
這能產生一個不僅知道如何執行任務,還知道在出錯時如何恢復的策略。
運作原理
在 HIL 會話期間,人類操作員在每個單元(episode)中遵循以下迴圈:
- 觀察策略自動執行
- 暫停:當故障即將發生時按下暫停,機器人會保持當前位置
- 接管控制:透過遠端操作將機器人恢復到良好狀態,並修正行為
- 交還控制權給策略:策略恢復自動執行
- 在單元期間根據需要重複步驟 2–4
- 結束單元:任務完成時儲存並進入下一個執行循環
自主執行與人類控制的片段都會被記錄。策略與人類可以在單個單元內多次交替控制,且每次移交後單元會從當前狀態繼續執行(無需僅因介入而重置)。這能在一個連續的軌跡中捕捉自主執行、恢復與修正。收集完成後,合併後的數據集(原始演示 + HIL 數據)將用於微調策略。
此過程可以迭代重複:部署、收集、微調、再重複。每一輪都會針對當前策略的故障模式進行優化。
┌─────────────────────────────────────────────────────────────────────────┐
│ Policy v0 (trained on demos) │
│ ↓ │
│ HIL Collection (target current failure modes) → Fine-tune → Policy v1 │
│ ↓ │
│ HIL Collection (target new failure modes) → Fine-tune → Policy v2 │
│ ↓ │
│ ... (repeat until satisfactory performance) │
└─────────────────────────────────────────────────────────────────────────┘硬體需求
遠端操作裝置需求
examples/hil HIL 指令碼需要具備主動式馬達的遠端操作裝置,且必須能:
- 以程式方式啟用/停用轉矩(Torque)
- 移動至目標位置(在暫停時與機器人狀態同步)
當前 examples/hil 指令碼支援的遠端操作裝置:
openarm_mini- OpenArm Miniso_leader- SO100 / SO101 引導機械臂(Leader Arm)
提供的
examples/hil指令預設使用bi_openarm_follower+openarm_mini。so_follower+so_leader配置也已註冊,可透過 CLI 旗標使用。
指令碼
單一指令碼可同時處理同步推論與基於 RTC 的推論。可透過 --rtc.enabled=true 切換 RTC。
| 模式 | 旗標 | 模型 (Models) |
|---|---|---|
| 標準(預設) | (無需旗標) | ACT, Diffusion Policy |
| 即時分塊 (RTC) | --rtc.enabled=true | Pi0, Pi0.5, SmolVLA |
逐步指南
步驟 1:預訓練基礎策略
首先,在您的演示數據集上訓練一個策略。
python src/lerobot/scripts/lerobot_train.py \
--dataset.repo_id=your-username/demo-dataset \
--policy.type=pi0 \
--output_dir=outputs/pretrain \
--batch_size=32 \
--steps=50000步驟 2:收集 HIL 數據
標準推論(ACT, Diffusion Policy)
python examples/hil/hil_data_collection.py \
--robot.type=bi_openarm_follower \
--robot.left_arm_config.port=can1 \
--robot.left_arm_config.side=left \
--robot.right_arm_config.port=can0 \
--robot.right_arm_config.side=right \
--robot.cameras='{left_wrist: {type: opencv, index_or_path: "/dev/video0", width: 1280, height: 720, fps: 30}, right_wrist: {type: opencv, index_or_path: "/dev/video4", width: 1280, height: 720, fps: 30}, base: {type: opencv, index_or_path: "/dev/video2", width: 640, height: 480, fps: 30}}' \
--teleop.type=openarm_mini \
--teleop.port_left=/dev/ttyACM0 \
--teleop.port_right=/dev/ttyACM1 \
--policy.path=outputs/pretrain/checkpoints/last/pretrained_model \
--dataset.repo_id=your-username/hil-dataset \
--dataset.single_task="Fold the T-shirt properly" \
--dataset.fps=30 \
--dataset.episode_time_s=1000 \
--dataset.num_episodes=50 \
--interpolation_multiplier=2針對大型模型(Pi0, Pi0.5, SmolVLA)啟用 RTC
對於推論延遲較高的模型,請啟用 RTC 以確保順暢執行。
python examples/hil/hil_data_collection.py \
--rtc.enabled=true \
--rtc.execution_horizon=20 \
--rtc.max_guidance_weight=5.0 \
--rtc.prefix_attention_schedule=LINEAR \
--robot.type=bi_openarm_follower \
--robot.left_arm_config.port=can1 \
--robot.left_arm_config.side=left \
--robot.right_arm_config.port=can0 \
--robot.right_arm_config.side=right \
--robot.cameras='{left_wrist: {type: opencv, index_or_path: "/dev/video0", width: 1280, height: 720, fps: 30}, right_wrist: {type: opencv, index_or_path: "/dev/video4", width: 1280, height: 720, fps: 30}, base: {type: opencv, index_or_path: "/dev/video2", width: 640, height: 480, fps: 30}}' \
--teleop.type=openarm_mini \
--teleop.port_left=/dev/ttyACM0 \
--teleop.port_right=/dev/ttyACM1 \
--policy.path=outputs/pretrain/checkpoints/last/pretrained_model \
--dataset.repo_id=your-username/hil-rtc-dataset \
--dataset.single_task="Fold the T-shirt properly" \
--dataset.fps=30 \
--dataset.episode_time_s=1000 \
--dataset.num_episodes=50 \
--interpolation_multiplier=3控制方式(概念說明)
互動模型如下:
- 暫停輸入(Pause input):暫停自動化策略執行
- 接管輸入(Takeover input):將控制權轉移給人類操作員並記錄介入數據
- 交還輸入(Return-to-policy input):將控制權交還給策略,並在同一單元中繼續執行
- 單元控制輸入:根據需要進行儲存/重錄/停止/重置
確切的按鍵/踏板綁定可能會因指令碼和硬體整合而異。請以每個指令碼輸出的控制資訊作為您設定中具體對應的權威來源。
HIL 協定
- 觀察策略自動執行(遠端操作裝置處於閒置/自由狀態)
- 當您看到即將發生故障時,觸發暫停輸入
- 策略停止
- 遠端操作裝置移動以匹配機器人位置(轉矩已啟用)
- 暫停期間不記錄影格
- 觸發接管輸入以取得控制權
- 遠端操作裝置轉矩已停用,可自由移動
- 恢復:遠端操作機器人回到良好狀態
- 修正:修正行為
- 所有移動過程均會被記錄
- 觸發交還輸入
- 策略從當前狀態恢復自動執行
- 您可以隨時再次介入(重複步驟 2–4)
- 任務完成(或達到單元時間限制)時,結束並儲存該單元
- 重置:遠端操作裝置移動至機器人位置,您可以將機器人移回初始位置
- 開始下一個單元
腳踏板設定(Linux)
如果使用 USB 腳踏板(PCsensor FootSwitch),請確保權限存取正常
sudo setfacl -m u:$USER:rw /dev/input/by-id/usb-PCsensor_FootSwitch-event-kbd步驟 3:微調策略
在合併後的數據集(demo-dataset + hil-dataset 合併)上進行微調。
python src/lerobot/scripts/lerobot_train.py \
--dataset.repo_id=your-username/hil-dataset \
--policy.type=pi0 \
--policy.pretrained_path=outputs/pretrain/checkpoints/last/pretrained_model \
--output_dir=outputs/hil_finetune \
--steps=20000隨後部署微調後的策略,並從步驟 2 重複執行,以針對其剩餘的故障模式進行優化。
有效 HIL 收集的建議
何時該介入
當您觀察到以下情況時請進行介入:
- 機器人即將犯下不可逆的錯誤
- 機器人出現猶豫或不確定的行為
- 機器人偏離了預期軌跡
恢復:遠端操作回到良好狀態
在恢復期間,遠端操作機器人回到以下狀態:
- 機器人處於熟悉、分佈內(in-distribution)的配置中
- 當前子任務仍可完成
- 恢復軌跡本身也是具參考價值的訓練數據
修正品質
在修正期間:
- 提供自信、乾淨的軌跡
- 完整地完成當前子任務
- 避免過度修正或增加不必要的移動
相關工作
此 HIL 資料收集方法建立在互動式模仿學習(Interactive Imitation Learning)的思想之上。
DAgger (Ross et al., 2011) 引入了核心概念:與其僅在專家演示上進行訓練,不如針對學習者造訪的狀態查詢專家的修正。這打破了標準行為複製中的誤差累積循環,透過迭代收集策略內的數據。
HG-DAgger (Kelly et al., 2019) 使其在機器人技術中變得實用:人類專家監控機器人並僅在需要時進行介入,而不是標記每一個狀態。自動化控制與人類控制之間的門控機制,正是此處指令碼所使用的「暫停 → 接管 → 交還控制權」迴圈。
RaC (Hu et al., 2025) 將此迴圈擴展到長視距任務,方法是將介入明確分解為恢復(遠端操作回到良好狀態)與修正(從該處演示正確行為)。這種分解正是
examples/hil中 HIL 指令碼所遵循的協定。π0.6/RECAP (Physical Intelligence, 2025) 將相同的迭代收集與微調迴圈大規模應用於 VLA 模型,表明即使是大型預訓練策略,也能從針對其自身故障模式的人類修正中受益匪淺。π0.6 是使用 RECAP 訓練的。
@article{ross2011dagger,
title={A Reduction of Imitation Learning and Structured Prediction to No-Regret Online Learning},
author={Ross, Stéphane and Gordon, Geoffrey and Bagnell, Drew},
journal={Proceedings of the Fourteenth International Conference on Artificial Intelligence and Statistics},
year={2011}
}
@article{kelly2019hgdagger,
title={HG-DAgger: Interactive Imitation Learning with Human Experts},
author={Kelly, Michael and Sidrane, Chelsea and Driggs-Campbell, Katherine and Kochenderfer, Mykel J},
journal={arXiv preprint arXiv:1810.02890},
year={2019}
}
@article{hu2025rac,
title={RaC: Robot Learning for Long-Horizon Tasks by Scaling Recovery and Correction},
author={Hu, Zheyuan and Wu, Robyn and Enock, Naveen and Li, Jasmine and Kadakia, Riya and Erickson, Zackory and Kumar, Aviral},
journal={arXiv preprint arXiv:2509.07953},
year={2025}
}
@article{pi2025recap,
title={π0.6: a VLA That Learns From Experience},
author={Physical Intelligence},
year={2025}
}