官方源码链接: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.安装miniforge
wget "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh" bash Miniforge3-$(uname)-$(uname -m).sh2.安装FFmpeg
sudo apt update sudo apt install -y ffmpeg libavcodec-dev libavformat-dev libavutil-dev libswscale-dev3.安装uv包管理⼯具并拉取依赖包
conda create -n uv_envs python=3.10 conda activate uv_envspip install uv cd openpi/GIT_LFS_SKIP_SMUDGE=1 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-strategy=unsafe-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_GL=glx python examples/libero/main.py修改测试次数为2次
MUJOCO_GL=glx 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
第一步安装LEROBOT
git clone https://github.com/huggingface/lerobot.git cd lerobot创建包含 Python 3.12 的虚拟环境:
conda create -y -n lerobot python=3.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_proxy="http://127.0.0.1:7897" export https_proxy="http://127.0.0.1:7897" export all_proxy="http://127.0.0.1:7897" export ALL_PROXY="http://127.0.0.1:7897"继续使用openpi的训练命令
阶段 1:环境初始化与网络配置
首先需要激活虚拟环境,并解决国内连接 Hugging Face 容易超时的问题。
# 激活虚拟环境 conda activate uv_envs # 配置镜像源,确保后续数据集能顺利下载 export HF_ENDPOINT=https://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-name=pi0training42 \ --data.repo_id=/home/robot/Lab_repos/Openpi/openpi/libero_dataset \ --batch_size=32 \ --num_train_steps=20000 \ --save_interval=10000 \ --log_interval=10000 \ --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.config=pi0_libero_low_mem_finetune \ --policy.dir=/home/robot/Lab_repos/Openpi/openpi/checkpoints/pi0_libero_low_mem_finetune/pi0training42/19999 \