7.1 模型推理指令

7.1 模型推理指令

训练完成后,使用 lerobot-record 命令加载训练好的模型进行推理测试。该命令在推理的同时也会记录数据集。

基本推理命令

lerobot-record 加上 --policy.path 参数即可将录制模式切换为推理模式。

推理参数说明

参数 说明
--policy.path 训练好的模型路径,格式必须是 name/pretrained_model 两级目录深度
--policy.device 推理设备,cuda(GPU)或 cpu
--dataset.repo_id 推理时新建的数据集名称,不能与训练数据集同名
--dataset.single_task 任务描述,与录制时保持一致
--dataset.push_to_hub=false 不上传推理数据到 HuggingFace

推理前检查清单

  1. 重新检查标定:确认 Follower 和 Leader 的标定参数正确
  2. 确认安全空间:机械臂运动范围内不要有障碍物
  3. 检查模型路径:确认 policy.path 指向正确的训练输出目录
  4. 动作异常时:立即按 Ctrl+C 停止,排查问题

常见问题

机械臂抖动

  • 调整 lerobot/src/lerobot/robots/so101_follower/so101_follower.py 中 set_so100_robot_preset() 函数的 D_Coefficient 参数,改为较小的值(如 0)
  • 检查舵机供电是否充足(7.4V 需 2A 以上电源,12V 需 2A 以上电源)

动作偏移

  • 重新校准关节零点(重新标定)
  • 检查相机画面是否与训练时一致(视角、光照)
  • 确认数据采集质量(数据量是否充足,动作是否连贯)

推理无法启动

  • 确认模型文件完整(pretrained_model 目录存在)
  • 查看终端错误日志定位具体原因

模型推理

linux: lerobot-record \
    --robot.type=so101_follower \
    --robot.port=/dev/ttyACM0 \
    --robot.id=R12252801 \
    --teleop.type=so101_leader \
    --teleop.port=/dev/ttyACM1 \
    --teleop.id=R07252801 \
    --robot.disable_torque_on_disconnect=true \
    --robot.cameras="{'wrist': {'type': 'opencv', 'index_or_path': 0, 'width': 640, 'height': 360, 'fps': 30}}" \
    --display_data=true \
    --dataset.single_task="Put lego brick into the transparent box" \
    --policy.path=outputs/pretrained_model \
    --policy.device=cuda \
    --dataset.repo_id=${HF_USER}/eval_so101 \
    --dataset.push_to_hub=false
macos: lerobot-record \
    --robot.type=so101_follower \
    --robot.port=/dev/tty.usbmodem58760431541 \
    --robot.id=R12252801 \
    --teleop.type=so101_leader \
    --teleop.port=/dev/tty.usbmodem58760431551 \
    --teleop.id=R07252801 \
    --robot.disable_torque_on_disconnect=true \
    --robot.cameras="{'wrist': {'type': 'opencv', 'index_or_path': 0, 'width': 640, 'height': 360, 'fps': 30}}" \
    --display_data=true \
    --dataset.single_task="Put lego brick into the transparent box" \
    --policy.path=outputs/pretrained_model \
    --policy.device=cuda \
    --dataset.repo_id=${HF_USER}/eval_so101 \
    --dataset.push_to_hub=false
windows: lerobot-record `
    --robot.type=so101_follower `
    --robot.port=COM4 `
    --robot.id=R12252801 `
    --teleop.type=so101_leader `
    --teleop.port=COM3 `
    --teleop.id=R07252801 `
    --robot.disable_torque_on_disconnect=true `
    --robot.cameras="{'wrist': {'type': 'opencv', 'index_or_path': 0, 'width': 640, 'height': 360, 'fps': 30}}" `
    --display_data=true `
    --dataset.single_task="Put lego brick into the transparent box" `
    --policy.path=outputs/pretrained_model `
    --policy.device=cuda `
    --dataset.repo_id=${HF_USER}/eval_so101 `
    --dataset.push_to_hub=false