Lerobot框架使用(含本地数据训练)

article/2025/8/14 21:02:12

本文包含从安装环境到完整使用Lerobot框架进行算法复现全流程。

A Install LeRobot

安装miniconda管理python环境

Linux

mkdir -p ~/miniconda3
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda3/miniconda.sh
bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3
rm ~/miniconda3/miniconda.sh

macOS

mkdir -p ~/miniconda3
curl https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-arm64.sh -o ~/miniconda3/miniconda.sh
bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3
rm ~/miniconda3/miniconda.sh

Windows command Prompt

curl https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86_64.exe -o .\miniconda.exe
start /wait "" .\miniconda.exe /S
del .\miniconda.exe
创建并激活conda环境
conda create -y -n lerobot python=3.10 && conda activate lerobot
克隆Lerobot仓库
git clone https://github.com/huggingface/lerobot.git ~/lerobot
安装飞特舵机的驱动
cd ~/lerobot && pip install -e ".[feetech]"

NOTE: If you encounter build errors, you may need to install additional dependencies (cmake, build-essential, and ffmpeg libs). On Linux, run: sudo apt-get install cmake build-essential python3-dev pkg-config libavformat-dev libavcodec-dev libavdevice-dev libavutil-dev libswscale-dev libswresample-dev libavfilter-dev pkg-config.

如果你是Linux用户,还需要安装一些额外的依赖:
conda install -y -c conda-forge ffmpeg
pip uninstall -y opencv-python
conda install -y -c conda-forge "opencv>=4.10.0"

To use Weights and Biases for experiment tracking, log in with

wandb login

B 配置舵机驱动

结合UP主视频操作:B站视频

C 组装机械臂

我买的是组装好的,自己组装可参考视频4-lerobot aloha从臂机械臂的组装步骤_哔哩哔哩_bilibili

D 查找配置端口号

我们通过typeC端口链接机械臂,然后通过hub或者直接连接在电脑主机上

1.首先运行脚本

python lerobot/scripts/find_motors_bus_port.py

2.在不同系统上输出不同

windows上多是COM几

linux上是/dev/ttyACM0

mac为/dev/tty.usbmodem575E0031751

3.之后按照提示指令拔出其中主臂的数据线,按enter键会输出主臂的端口号,从臂的方式同理

在linux上需要给USB端口权限

sudo chmod 666 /dev/ttyACM0
sudo chmod 666 /dev/ttyACM1

4.去文件lerobot-main\lerobot\common\robot_devices\robots\configs.py下,在大致440行处修改

@RobotConfig.register_subclass("so100")
@dataclass
class So100RobotConfig(ManipulatorRobotConfig):calibration_dir: str = ".cache/calibration/so100"# `max_relative_target` limits the magnitude of the relative positional target vector for safety purposes.# Set this to a positive scalar to have the same value for all motors, or a list that is the same length as# the number of motors in your follower arms.max_relative_target: int | None = Noneleader_arms: dict[str, MotorsBusConfig] = field(default_factory=lambda: {"main": FeetechMotorsBusConfig(
-                port="/dev/tty.usbmodem58760431091",
+                port="{ADD YOUR LEADER PORT}",motors={# name: (index, model)"shoulder_pan": [1, "sts3215"],"shoulder_lift": [2, "sts3215"],"elbow_flex": [3, "sts3215"],"wrist_flex": [4, "sts3215"],"wrist_roll": [5, "sts3215"],"gripper": [6, "sts3215"],},),})follower_arms: dict[str, MotorsBusConfig] = field(default_factory=lambda: {"main": FeetechMotorsBusConfig(
-                port="/dev/tty.usbmodem585A0076891",
+                port="{ADD YOUR FOLLOWER PORT}",motors={# name: (index, model)"shoulder_pan": [1, "sts3215"],"shoulder_lift": [2, "sts3215"],"elbow_flex": [3, "sts3215"],"wrist_flex": [4, "sts3215"],"wrist_roll": [5, "sts3215"],"gripper": [6, "sts3215"],},),})

E 校准机械臂

首先运行脚本

python lerobot/scripts/control_robot.py \--robot.type=so100 \--robot.cameras='{}' \--control.type=calibrate \--control.arms='["main_follower"]'

按照提示去进行校准,严格按照校准提示去校准,如果校准位置不对,会出现舵机发烫的现象

You will need to move the follower arm to these positions sequentially, note that the rotated position is on the right side of the robot and you have to open the gripper fully.

同样运行校准主臂指令

python lerobot/scripts/control_robot.py \--robot.type=so100 \--robot.cameras='{}' \--control.type=calibrate \--control.arms='["main_leader"]'

校准好的json文件会保存在根目录的.cache文件夹下,需要重新标定的话,只需要删除了重新执行脚本。

F 遥操作

先运行不带摄像头的进行简单的遥操作示例

python lerobot/scripts/control_robot.py \--robot.type=so100 \--robot.cameras='{}' \--control.type=teleoperate

完成基本的操作是没什么问题的,但是在进行精细操作的时候还是些许抖动,在此调整了PID参数使更加顺滑一些,在文件lerobot-main/lerobot/common/robot_devices/robots/manipulator.py下修改

# Set P_Coefficient to lower value to avoid shakiness (Default is 32)
self.follower_arms[name].write("P_Coefficient", 12)
# Set I_Coefficient and D_Coefficient to default value 0 and 32
self.follower_arms[name].write("I_Coefficient", 0)
self.follower_arms[name].write("D_Coefficient", 0)

G 配置相机并使用rerun监控相机与机械臂数据

The OpenCVCamera class allows you to efficiently record frames from most cameras using the opencv2 library. For more details on compatibility, see Video I/O with OpenCV Overview.

To instantiate an OpenCVCamera, you need a camera index (e.g. OpenCVCamera(camera_index=0)). When you only have one camera like a webcam of a laptop, the camera index is usually 0 but it might differ, and the camera index might change if you reboot your computer or re-plug your camera. This behavior depends on your operating system.

To find the camera indices, run the following utility script, which will save a few frames from each detected camera:

python lerobot/common/robot_devices/cameras/opencv.py \--images-dir outputs/images_from_opencv_cameras

这个脚本会在目录output下生成随机个数张图片,在此你可以寻找你的相机index一般是0或1或2等

输出类似这种

Mac or Windows detected. Finding available camera indices through scanning all indices from 0 to 60
[...]
Camera found at index 0
Camera found at index 1
[...]
Connecting cameras
OpenCVCamera(0, fps=30.0, width=1920.0, height=1080.0, color_mode=rgb)
OpenCVCamera(1, fps=24.0, width=1920.0, height=1080.0, color_mode=rgb)
Saving images to outputs/images_from_opencv_cameras
Frame: 0000        Latency (ms): 39.52
[...]
Frame: 0046        Latency (ms): 40.07
Images have been saved to outputs/images_from_opencv_cameras

再去lerobot-main\lerobot\common\robot_devices\robots\configs.py下修改相机配置,通常是配置index,还可以配置个数等等

    cameras: dict[str, CameraConfig] = field(default_factory=lambda: {"above": OpenCVCameraConfig(camera_index=0,fps=30,width=640,height=480,),"wrist": OpenCVCameraConfig(camera_index=1,fps=30,width=640,height=480,),})

之后便可以运行

python lerobot/scripts/control_robot.py \--robot.type=so100 \--control.type=teleoperate

NOTE: To visualize the data, enable --control.display_data=true. This streams the data using rerun.

我在windows上是没有出现问题的,在linux上可能会出现ffmpeg冲突等问题,具体解决办法在github上issue上有人提出可以参考https://github.com/huggingface/lerobot/pull/883,不知道现在修复了没有。

H 记录数据集

数据传输到huggingface

这可能涉及到网络连接的问题具体配置方法如下

If you want to use the Hugging Face hub features for uploading your dataset and you haven't previously done it, make sure you've logged in using a write-access token, which can be generated from the Hugging Face settings:

huggingface-cli login --token ${HUGGINGFACE_TOKEN} --add-to-git-credential

Store your Hugging Face repository name in a variable to run these commands:

HF_USER=$(huggingface-cli whoami | head -n 1)
echo $HF_USER

记录两组数据集

python lerobot/scripts/control_robot.py \--robot.type=so100 \表示机械臂类型--control.type=record \--control.fps=30 \--control.single_task="Grasp a lego block and put it in the bin." \--control.repo_id=${HF_USER}/so100_test \--control.tags='["so100","tutorial"]' \--control.warmup_time_s=5 \--control.episode_time_s=30 \一组的时间--control.reset_time_s=30 \环境重置的时间--control.num_episodes=2 \录制两组数据--control.push_to_hub=true  传到huggingface hub上
记录在本地

我是把每次的数据放在了根目录的data文件夹下

其中你需要改的事repo id 还要定义root根目录不然,系统会自动把你的文件存在系统的.cache文件夹下,windows下存在c盘,linux系统,需要点击ctrl+h找到隐藏文件

之后我们为了方便录制多组数据可以将数据存在目录data/repoid下面需要修改源码

obj.root.mkdir(parents=True, exist_ok=False)改为

obj.root.mkdir(parents=True, exist_ok=True)

self.root = Path(root) if root else HF_LEROBOT_HOME / repo_id改为

self.root = Path(root/repo_id) if root else HF_LEROBOT_HOME / repo_id

运行脚本为

python lerobot/scripts/control_robot.py \--robot.type=so100 \--control.type=record \--control.fps=30 \--control.single_task="Grasp a pen." \--control.repo_id=robotxxx/so100_first \--control.root=./data \--control.tags='["so100","pencil"]' \--control.warmup_time_s=5 \--control.episode_time_s=12 \--control.reset_time_s=10 \--control.num_episodes=5 \--control.push_to_hub=false
播放可视化数据集

If you uploaded your dataset to the hub with --control.push_to_hub=true, you can visualize your dataset online by copy pasting your repo id given by:

echo ${HF_USER}/so100_test

If you didn't upload with --control.push_to_hub=false, you can also visualize it locally with (a window can be opened in the browser http://127.0.0.1:9090 with the visualization tool):

python lerobot/scripts/visualize_dataset_html.py \--repo-id ${HF_USER}/so100_test \--local-files-only 1

Now try to replay the first episode on your robot:

python lerobot/scripts/control_robot.py \--robot.type=so100 \--control.type=replay \--control.fps=30 \--control.repo_id=${HF_USER}/so100_test \--control.episode=0
记录期间的键盘控制

按键 Key

操作 Action

Right Arrow

Skip to next step (exit current episode or reset phase)

Left Arrow

Re-record current episode

Escape

Stop recording entirely

I 选择合适策略训练

  python lerobot/scripts/train.py \--dataset.root=./data \--dataset.repo_id=robotxxx/so100_act--policy.type=act \--output_dir=outputs/train/act_so100_test \--job_name=act_so100_test \--policy.device=cuda \--wandb.enable=true \

其中repoid对应你收集数据时候写的,如果是上传了huggingface使用

python lerobot/scripts/train.py \--dataset.repo_id=${HF_USER}/so100_test \--policy.type=act \--output_dir=outputs/train/act_so100_test \--job_name=act_so100_test \--policy.device=cuda \--wandb.enable=true

其中我们可以分析train.py文件和不同policy的config文件去改训练参数或模型参数以适配好的训练效果

  • 策略配置包括:

  • 模型架构参数(维度、层数等)

  • 训练专用参数

  • 设备规格(CPU/GPU/MPS)

  • 预训练模型路径(如果从检查点加载)等

J 评估你的策略

You can use the record function from lerobot/scripts/control_robot.py but with a policy checkpoint as input. For instance, run this command to record 10 evaluation episodes:

python lerobot/scripts/control_robot.py \--robot.type=so100 \--control.type=record \--control.fps=30 \--control.single_task="Grasp a lego block and put it in the bin." \--control.repo_id=${HF_USER}/eval_act_so100_test \--control.tags='["tutorial"]' \--control.warmup_time_s=5 \--control.episode_time_s=30 \--control.reset_time_s=30 \--control.num_episodes=10 \--control.push_to_hub=true \--control.policy.path=outputs/train/act_so100_test/checkpoints/last/pretrained_model

路径记得改一下,如果没问题的话,你的机械臂应该能自己动起来执行推理任务了。


http://www.hkcw.cn/article/CDgvyPqfZR.shtml

相关文章

小红书 web x-s x-t X-Mns 分析

声明: 本文章中所有内容仅供学习交流使用,不用于其他任何目的,抓包内容、敏感网址、数据接口等均已做脱敏处理,严禁用于商业用途和非法用途,否则由此产生的一切后果均与作者无关! 逆向分析 cp execjs.compile(open(v…

国产化中间件基本使用_东方通(TongWeb7.0.E.6_P2)

tongweb开发操作文档 1、前期准备 进入官网申请使用,官网地址:https://www.tongtech.com 若提供的安装程序的授权文件已过期,请去官方网站重新申请。 2、安装部署 2.1、下载安装Tongweb 进入官网申请试用,官方会提供响应的嵌入式安装包及试用授权证书(3个月) 申请…

010302-oss_反向代理_负载均衡-web扩展2-基础入门-网络安全

文章目录 1 OSS1.1 什么是 OSS 存储?1.2 OSS 核心功能1.3 OSS 的优势1.4 典型使用场景1.5 如何接入 OSS?1.6 注意事项1.7 cloudreve实战演示1.7.1 配置cloudreve连接阿里云oss1.7.2 常见错误1.7.3 安全测试影响 2 反向代理2.1 正向代理和反向代理2.2 演示…

FREERTOS+LWIP+IAP实现TCP、HTTP、网页访问并固件升级、更新配置 (三)lwip实现httpd服务并在web访问

前言 在前两篇文章中配置freeRTOS和,并实现了TCP、UDP的通信协议,现在终于轮到重头戏lwip的httpd服务,LWIP官方例程中是有很多自带的网页的,但是远远不够满足实际项目的使用需求,因此我也是踩了很多坑,从前…

lighthouse(灯塔)前端性能测试工具

前端性能测试工具之lighthouse灯塔 介绍下载链接使用方法前端性能指标解读 介绍 Lighthouse 是一个开源的自动化工具,用来测试前端页面性能,反馈页面问题以提升页面体验。可以联合谷歌浏览器,作为插件导入,开启后可测试页面性能 …

Ai智能体四:互动式 AI 聊天助手:前端实现

在现代 web 应用中,集成智能对话功能已经成为提升用户体验的重要手段之一。本文将介绍如何通过 Vue 3 和 Element Plus 构建一个高效的 AI 聊天助手界面,并详细讲解其实现原理和功能。 1. 整体架构 该聊天界面分为 左侧边栏 和 右侧内容区域,实现了清晰的布局结构,左侧边…

Spring Boot 3.x 引入springdoc-openapi (内置Swagger UI、webmvc-api)

接触的原因 因开发自己的项目时,写接口文档很繁琐,查到后端都在用swagger等接口工具来记录接口文档,于是学习了一下,本文记录个人配置过程,有问题欢迎指正交流😁 Swagger: Swagger是一种Rest AP…

OpenWebUI配置异常的外部模型导致页面无法打开

一、使用Ollama关闭OpenAI OpenWebUI自带OpenAI的API设置,且默认是打开的,默认情况下,启动后,会不断的去连https://api.openai.com/v1,但是无法连上,会报错,但是不会影响页面,能正常…

Postman(Apifox)调用WebServicer接口

postman调用WebServicer接口 前言 Postman使用方法Apifox使用方法参数与配置请求代码(当然一般开发会给一个样例)步骤 前言 之前都是使用SoapUI测试WebServicer接口,由于工作所需,需要使用Postman测试工具 Postman使用方法 可以直接在请求里写全部的wsdl地址 ,参数会自动带进…

DeepSeek本地化部署实践:Xinference框架+OpenWebUI实现DeepSeek-r1推理跑在国产GPU之上

近日,我部门从供应商那儿借来一台高算力服务器,用来尝试本地化部署DeepSeek。该服务器型号为ASUS ESC8000A-E11,具体配置如下: CPU:AMD EPYC 7702(64核)* 2 GPU:(天数智…

Android WebRTC集成及JNI性能优化实战指南

本文还有配套的精品资源,点击获取 简介:WebRTC是一个开源项目,旨在实现浏览器间无需插件的实时通信,包括音频、视频通话及数据共享。在Android平台上,其实施涉及使用JNI接口进行Java与C/C代码的交互。本压缩包内容预…

【前端】超链接标签(a标签)之href属性、target属性

文章目录 一、a标签1、href属性(1)跳转至网络链接页面(2)跳转至其它工程页面(3)跳转至本界面 2、target属性 二、感谢观看! 一、a标签 a标签即超链接标签,根据名字我们就能知道它是…

【前端开发】一文带你快速入门JavaScript(下)Web 前端必备程序语言 | 条件语句与循环结构

💯 欢迎光临清流君的博客小天地,这里是我分享技术与心得的温馨角落 💯 🔥 个人主页:【清流君】🔥 📚 系列专栏: 运动控制 | 决策规划 | 机器人数值优化 📚 🌟始终保持好奇心&…

教你在.Net8.0的WinForm中使用WebView2,实现C#和JavaScript的实时双向互操作

1. 前言 随着 Web 技术的发展,使用网页内容(HTML、JavaScript、CSS 等)作为桌面应用程序的一部分变得越来越常见。在 C# WinForm 中,Microsoft 提供的 WebView2 控件让我们可以轻松地嵌入 Chromium 浏览器,并实现 C# …

【多线程初阶】synchronized锁

文章目录 🌅synchronized关键字🌊 synchronized 的互斥🌊 synchronized 的变种写法🏄‍♂️synchronized 修饰代码块 :明确指定锁哪个对象🏄‍♂️synchronized 修饰方法 🌊 synchronized 的可重入性&#…

使用 Cython 编译将.py文件加密成.so文件

文章目录 1. .so文件的核心意义和优势2. 使用 Cython 编译,将.py文件加密成.so文件 最近在学习在服务器上如何部署Python模型,不学不知道,一学吓一跳,要学好多啊,最近看到什么就记录一下什么吧。 1. .so文件的核心意义…

环赛里木湖公路自行车赛开赛 速度与激情点燃丝路热土

5月31日上午10时,中国新疆第十七届环赛里木湖(国际)公路自行车赛在精河县鸣枪开赛。首段比赛全长83.1公里,以速度与激情点燃了“中国枸杞之乡”精河县的丝路热土。骑手们从精河县出发,沿精阿高速疾驰,穿越艾比湖湿地和甘家湖梭梭林国家级自然保护区。开赛后仅10分钟,在顺…

南京大学通报施工方偷窃物品 施工单位被罚2000元

5月29日,南京大学基本建设处发布了一份关于对南京诚善科技有限公司执行合同违约金的通报。通报指出,南京大学三校区公共区域饮水机采购及安装项目的施工单位南京诚善科技有限公司的一名员工于5月13日在学校宿舍楼内偷窃学生物品。根据施工合同相关规定并经处办公会研究确认,…

java 反射 枚举与lambda表达式

目录 一.反射 1.概念:在运⾏时检查、访问和修改类、接⼝、字段和⽅法的机制 2.Class类 3.反射相关的类型 4.各类型对应的方法 ​编辑 5.代码示例 (1).class类方法 (2).Field类方法 (3).Constructor类方法 (4).Method类方法 6.总结 二.枚举 1.概念&#x…

【AI大模型】Ollama部署本地大模型DeepSeek-R1,交互界面Open-WebUI,RagFlow构建私有知识库

文章目录 DeepSeek介绍公司背景核心技术产品与服务应用场景优势与特点访问与体验各个DeepSeek-R系列模型的硬件需求和适用场景 Ollama主要特点优势应用场景安装和使用配置环境变量总结 安装open-webui下载和安装docker desktop配置镜像源安装open-webui运行和使用 RagFlow介绍主…