官方源码链接https://github.com/Physical-Intelligence/openpi# 标准下载 git clone https://github.com/Physical-Intelligence/openpi.git # 备用如果卡住使用的国内代理加速下载指令 git clone https://mirror.ghproxy.com/https://github.com/Physical-Intelligence/openpi.git1.安装miniforgewget https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh bash Miniforge3-$(uname)-$(uname -m).sh2.安装FFmpegsudo apt update sudo apt install -y ffmpeg libavcodec-dev libavformat-dev libavutil-dev libswscale-dev3.安装uv包管理⼯具并拉取依赖包conda create -n uv_envs python3.10 conda activate uv_envspip install uv cd openpi/GIT_LFS_SKIP_SMUDGE1 uv sync如果失败就再次运行上述命令4.启动模型服务server 端conda activate uv_envs cd openpi/ source ./.venv/bin/activateuv run scripts/serve_policy.py --env LIBERO # 启动服务端监听运行上述代码会进行服务端的启动代码主要是检测checkpoint的文件夹下面是否有如下文件没有的话就从谷歌拉取下载下载过慢可以使用如下下载方式并且把文件夹移动过去sudo apt install awscli aws s3 cp s3://openpi-assets/checkpoints/pi0_base/assets ./ -- recursive --no-sign-request aws s3 cp s3://openpi-assets/checkpoints/pi05_libero ./ -- recursive --no-sign-request cp -r {上述下载文件的路径} ~/.cache/openpicp -r assets/ ~/.cache/openpi命令执行成功后不要关闭该终端再开一个新终端完成后续操作5.安装适配的仿真环境 Libero第一步进入项目目录为了确保路径正确我们直接进入你之前下载好的 openpi 文件夹cd /root/openpi第二步创建专属虚拟环境使用 uv 工具为这个客户端创建一个 Python 3.8 的虚拟环境注意如果提示找不到 uv 命令你可能需要先用 pip install uv 安装一下uv venv --python 3.8 examples/libero/.venv第三步激活这个虚拟环境执行下面这行命令后你终端最前面的括号应该会变成类似 (.venv) 或者包含 libero 的字样这就说明激活成功了你已经脱离了 base 环境source examples/libero/.venv/bin/activate第四步安装客户端所需的依赖包uv pip sync examples/libero/requirements.txt third_party/libero/requirements.txt --extra-index-url https://download.pytorch.org/whl/cu113 --index-strategyunsafe-best-match如果出现报错File not found: third_party/libero/requirements.txt在官方的 PDF 教程中明确提到需要使用带有--recurse-submodules参数的git clone命令来克隆仓库 。这个参数的作用是在下载主项目的同时把third_party/aloha和third_party/libero等嵌套的子模组一并下载下来 。因为我们之前使用的是最基础的git clone命令没有带上拉取子模块的参数所以现在third_party/libero文件夹只是一个空壳自然就找不到里面的requirements.txt文件了。补充下载子模块git submodule update --init --recursive(这会去 GitHub 拉取缺失的libero和aloha代码并塞进third_party对应的空文件夹里。)第五步安装客户端与 Libero 本地库核心依赖装好后需要把项目自带的客户端库安装到当前环境中。uv pip install -e packages/openpi-client #安装openpi-client uv pip install -e third_party/libero #安装libero第六步配置环境变量关键防错为了防止运行时提示找不到libero包 必须先将它添加到系统的 Python 路径中 export PYTHONPATH$PYTHONPATH:$PWD/third_party/libero第七步设置图形渲染并启动主程序教程特别提醒为了防止 RoboSuite 处理 EGL 渲染时出现报错 需要强制使用glx进行渲染 。直接运行下面这两行命令export MUJOCO_GLglx python examples/libero/main.py修改测试次数为2次MUJOCO_GLglx python examples/libero/main.py --args.num-trials-per-task 2通常是跑每个任务测试50次总共十个任务如下所示1. 完整名字rollout_pick_up_the_black_bowl_next_to_the_cookie_box_and_place_it_on_the_plate_success.mp4具体操作拿起饼干盒旁边的黑碗并放在盘子上。2. 完整名字rollout_pick_up_the_black_bowl_on_the_stove_and_place_it_on_the_plate_success.mp4具体操作拿起炉子上的黑碗并放在盘子上。3. 完整名字rollout_pick_up_the_black_bowl_on_the_ramekin_and_place_it_on_the_plate_success.mp4具体操作拿起小烤钵ramekin上的黑碗并放在盘子上。4. 完整名字rollout_pick_up_the_black_bowl_next_to_the_ramekin_and_place_it_on_the_plate_success.mp4具体操作拿起小烤钵旁边的黑碗并放在盘子上。5. 完整名字rollout_pick_up_the_black_bowl_between_the_plate_and_the_ramekin_and_place_it_on_the_plate_success.mp4具体操作拿起盘子和小烤钵之间的黑碗并放在盘子上。6. 完整名字rollout_pick_up_the_black_bowl_from_table_center_and_place_it_on_the_plate_success.mp4具体操作拿起桌子中间的黑碗并放在盘子上。7. 完整名字rollout_pick_up_the_black_bowl_in_the_top_drawer_of_the_wooden_cabinet_and_place_it_on_the_plate_success.mp4具体操作拿起木柜顶层抽屉里的黑碗并放在盘子上。8. 完整名字rollout_pick_up_the_black_bowl_next_to_the_plate_and_place_it_on_the_plate_success.mp4具体操作拿起盘子旁边的黑碗并放在盘子上。9. 完整名字rollout_pick_up_the_black_bowl_on_the_cookie_box_and_place_it_on_the_plate_success.mp4具体操作拿起饼干盒上的黑碗并放在盘子上。10. 完整名字rollout_pick_up_the_black_bowl_on_the_wooden_cabinet_and_place_it_on_the_plate_success.mp4具体操作拿起木柜上的黑碗并放在盘子上。微调pi0.5第一步安装LEROBOTgit clone https://github.com/huggingface/lerobot.git cd lerobot创建包含 Python 3.12 的虚拟环境conda create -y -n lerobot python3.12 conda activate lerobot换源pip install cnpip cnpip list cnpip set使用时conda请ffmpeg在您的环境中安装使用时conda请ffmpeg在您的环境中安装conda install ffmpeg -c conda-forge ffmpeg -version # ffmpeg 8.X is not yet supported !以可编辑模式安装库。pip install -e . pip install lerobot安装相关依赖。pip install lerobot[all] # All available features pip install lerobot[aloha,pusht] # Specific features (Aloha Pusht) pip install lerobot[feetech] # Feetech motor support运行以下命令安装 Pi0.5 依赖项pip install -e .[pi]# 如果你之后打算跑 ALOHA 环境的数据集建议一并装上 aloha 依赖 pip install -e .[aloha,pi] # 如果你之后打算跑libero 环境的数据集建议一并装上 libero 依赖 pip install -e .[libero]如果出现代理错误就使用下面程序python -c import urllib.request; print(urllib.request.getproxies()) unset all_proxy unset ALL_PROXY export http_proxyhttp://127.0.0.1:7897 export https_proxyhttp://127.0.0.1:7897 export all_proxyhttp://127.0.0.1:7897 export ALL_PROXYhttp://127.0.0.1:7897继续使用openpi的训练命令阶段 1环境初始化与网络配置首先需要激活虚拟环境并解决国内连接 Hugging Face 容易超时的问题。# 激活虚拟环境 conda activate uv_envs # 配置镜像源确保后续数据集能顺利下载 export HF_ENDPOINThttps://hf-mirror.com阶段 2数据拉取与修补极度关键不要依赖代码自动下载直接手动拉取到本地并补齐缺失的索引文件最后计算归一化参数。# 1. 下载 LIBERO 数据集到本地文件夹 huggingface-cli download physical-intelligence/libero --repo-type dataset --local-dir ./libero_dataset --local-dir-use-symlinks False # 2. 补齐缺失的 tasks.jsonl必须执行这串 Python 代码 python -c import json from pathlib import Path data_dir Path(./libero_dataset) episodes_path data_dir / meta / episodes.jsonl tasks_path data_dir / meta / tasks.jsonl if episodes_path.exists(): tasks_set set() with open(episodes_path) as f: for line in f: ep json.loads(line) task ep.get(task) if task: tasks_set.add(task) tasks sorted(tasks_set) with open(tasks_path, w) as f: for idx, task in enumerate(tasks): f.write(json.dumps({task_index: idx, task: task}) \n) print(f✅ 成功生成 {tasks_path}共 {len(tasks)} 个任务) # 3. 计算归一化统计信息训练前必做防止梯度爆炸 python scripts/compute_norm_stats.py pi05_libero --data.repo_id/home/robot/Lab_repos/Openpi/openpi/libero_dataset阶段 3妥协显存与正式训练由于pi0.5 base会导致爆显存最终换用了pi0的低显存配置成功将batch_size提到了 32。# 登录 wandb 用于监控训练日志 wandb login # 正式启动训练换用了 pi0_libero_low_mem_finetune 方案 python scripts/train.py pi0_libero_low_mem_finetune \ --exp-namepi0training42 \ --data.repo_id/home/robot/Lab_repos/Openpi/openpi/libero_dataset \ --batch_size32 \ --num_train_steps20000 \ --save_interval10000 \ --log_interval10000 \ --overwrite阶段 5服务端与客户端联调评估最后开启两个终端一个跑模型推理服务一个跑 Libero 物理仿真环境两者通过 8000 端口通信。# 配置环境变量指向 LIBERO 环境 export PYTHONPATH${PYTHONPATH}:/home/robot/Lab_repos/Openpi/LIBERO # 运行仿真测试 uv run main.py \ --host 0.0.0.0 \ --port 8000 \ --task-suite-name libero_spatial \ --num-trials-per-task 50 \ --video-out-path ../../data/libero/eval_videos# 挂载训练好的第 19999 步的权重 uv run scripts/serve_policy.py policy:checkpoint \ --policy.configpi0_libero_low_mem_finetune \ --policy.dir/home/robot/Lab_repos/Openpi/openpi/checkpoints/pi0_libero_low_mem_finetune/pi0training42/19999 \