[LeRobot]仓库源码解读(0.3.4版本)

部署运行你感兴趣的模型镜像

[仓库地址]:https://github.com/huggingface/lerobot

[参考阅读]

LeRobot——Hugging Face打造的机器人开源库:包含对顶层script、与dataset的源码分析(含在简易机械臂SO-ARM100上的部署)

LeRobot DP——LeRobot对动作策略Diffusion Policy的封装与解读(含DexCap库中对diffusion_policy的封装与实现)


[代码结构](推荐一个代码仓库结构分析工具:gitdiagram

[杂记]

"""
Initialize placo-based kinematics solver.

Args:
    urdf_path: Path to the robot URDF file
    target_frame_name: Name of the end-effector frame in the URDF
    joint_names: List of joint names to use for the kinematics solver
"""
try:
    import placo
except ImportError as e:
raise ImportError(
    "placo is required for RobotKinematics. "
    "Please install the optional dependencies of `kinematics` in the package."
) from e

self.robot = placo.RobotWrapper(urdf_path)
self.solver = placo.KinematicsSolver(self.robot)
self.solver.mask_fbase(True)  # Fix the base

self.target_frame_name = target_frame_name

# Set joint names
self.joint_names = list(self.robot.joint_names()) if joint_names is None else joint_names

placo扩展阅读:

placo:用于求解机器人运动规划与控制的工具

  • src/lerobot/cameras文件夹下面放支持的摄像头驱动,截至到20250906支持的有:
  • src/lerobot/motors文件夹下放电机的驱动,目前有Dynamixel和Feetech
  • src/lerobot/robots文件夹下支持的机器人项目,截至到20250906有bi_so100_followerhope_jrkoch_followerlekiwireachy2so100_followerso101_followerstretch3viperx
  • src/lerobot/scripts文件夹:命令行工具,各种发号施令。包含一系列数据管理的脚本,涉及将本地数据集推动到hf(push_dataset_to_hub.py移动到datasets文件夹了)、可视化数据集;几个模型相关的脚本,涉及上传预训练模型到hf(应该是移除了,改用hf命令行了)、模型训练train.py、模型评估eval.py;几个机器人控制的脚本,涉及控制实际机器人、配置电机等脚本。
    • rl文件夹:

      The rl directory contains the main scripts and modules for running reinforcement learning (RL) workflows in LeRobot, especially for real-robot and simulation-based training. Key components include:

      actor.py: Implements the actor process in distributed RL (HIL-SERL), which interacts with the robot/environment, collects experience, and sends transitions to the learner.
      learner.py: Implements the learner process, which receives transitions from actors, updates the policy, and periodically sends updated parameters back.
      learner_service.py: Defines the gRPC service for communication between actor(s) and learner.
      gym_manipulator.py: Provides a gym-compatible environment for robot manipulation, supporting teleoperation, recording, replay, and RL training.
      eval_policy.py: Script for evaluating a trained policy in the environment.
      crop_dataset_roi.py: Utility for cropping and resizing dataset images based on regions of interest.
      These scripts enable distributed RL training, human-in-the-loop workflows, dataset collection, and evaluation for robot learning tasks.

    • server文件夹:

      The server directory contains scripts and modules for running the server-side components of LeRobot's distributed control and reinforcement learning infrastructure. Its main responsibilities are to manage communication between robots and policies, handle remote policy inference, and coordinate data exchange for RL workflows. Key components include:

      policy_server.py: Implements the gRPC server that receives observations from robot clients, runs policy inference, and sends actions back. It manages policy loading, observation queues, and supports multiple policy types.
      robot_client.py: Implements the robot-side client that connects to the policy server, sends observations, receives actions, and manages the robot control loop. It supports threading for concurrent action/observation handling.
      configs.py: Contains configuration dataclasses for both the policy server and robot client, including network, device, and policy settings.
      constants.py: Defines constants such as supported policies, robots, and default server parameters.
      helpers.py: Provides utility functions and dataclasses for logging, observation/action formatting, FPS tracking, and feature validation.
      This directory is essential for running LeRobot in distributed or remote-control setups, enabling real robots or simulators to interact with policies over the network.

  • examples文件夹
    • 2_evaluate_pretrained_policy.py:评估已经训练好的策略(lerobot/diffusion_pusht)。目前lerobot版本(0.3.4)下的这个文件还不支持RTX 5070ti,因为0.3.4用的torch>=2.2.1,<2.8.0(pyproject.toml),而支持50系显卡的torch至少要2.8.0(对应cuda 12.8),所以要么维持torch在torch>=2.2.1,<2.8.0然后报:NVIDIA GeForce RTX 5070 with CUDA capability sm_120 is not compatible with the current PyTorch installation、要么把torch升级到2.8.0升级后报别的因为torch版本不匹配导致的错误。

    • 3_train_policy.py:用准备好的数据集(lerobot/pusht),选择对应的策略进行训练。例程用的策略是diffusion policy(train Diffusion Policy on the PushT environment)。目前lerobot版本(0.3.4)下的这个文件还不支持RTX 5070ti,因为0.3.4用的torch>=2.2.1,<2.8.0(pyproject.toml),而支持50系显卡的torch至少要2.8.0(对应cuda 12.8),所以要么维持torch在torch>=2.2.1,<2.8.0然后报:NVIDIA GeForce RTX 5070 with CUDA capability sm_120 is not compatible with the current PyTorch installation、要么把torch升级到2.8.0升级后报别的因为torch版本不匹配导致的错误。

    • 1_load_lerobot_dataset.py:lerobot数据集的线上仓库查看、下载、加载等。

运行这个文件的时候因为要从huggingface上查询和下载一些文件,所以可能要激活一下代理先

export HTTP_PROXY=http://127.0.0.1:7890
export HTTPS_PROXY=http://127.0.0.1:7890

对应的线上数据集:lerobot/aloha_mobile_cabinet

Number of samples/frames: 127500

Number of episodes: 85

Frames per second: 50https://huggingface.co/spaces/lerobot/visualize_dataset?path=%2Flerobot%2Faloha_mobile_cabinet%2Fepisode_0

如果报错:No valid stream found in input file. Is -1 of the desired media type

安装一下ffmpeg

conda install -c conda-forge ffmpeg=6.1.1 -y

  •         

您可能感兴趣的与本文相关的镜像

PyTorch 2.5

PyTorch 2.5

PyTorch
Cuda

PyTorch 是一个开源的 Python 机器学习库,基于 Torch 库,底层由 C++ 实现,应用于人工智能领域,如计算机视觉和自然语言处理

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值