@bash (993-1017) 我已经在代码中添加了openpi的路径,为何仍然无法导入对应文件夹下的脚本? @teleavatar 找出核心问题并简洁回答,不要写说明文档…
- User
@bash (993-1017) 我已经在代码中添加了openpi的路径,为何仍然无法导入对应文件夹下的脚本? @teleavatar 找出核心问题并简洁回答,不要写说明文档 @bash (523-1017) @bash (933-1017)
Assistant
核心问题:添加的路径错误
python# 第44行添加的路径错误 OPENPI_PATH = "/home/[user]/Robotics/RLinf/openpi/src/openpi"examples文件夹在openpi/下,不在openpi/src/openpi/下。修复:
[tool: search_replace — Tool use: search_replace • Edit file: /home/[user]/Robotics/RLinf/examples/embodiment/collect_teleavatar_rollouts.py]
已修复。你原来添加的路径是
openpi/src/openpi,但examples文件夹在openpi/下,所以导入失败。现在改为正确的openpi根目录路径。- User
现在我已经成功运行,但实际运行中机器人并没有运动,请检查脚本是否能正常推理pytorch模型并发布ros消息@bash (751-1017)
Assistant
看到问题了!错误在行995-1000:
pythonTypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.policy.infer()返回的actions是CUDA tensor,但ROS发布需要numpy数组。需要在使用action前转换。[tool: read_file — Tool use: read_file • Read file: /home/[user]/Robotics/RLinf/examples/embodiment/collect_teleavatar_rollouts.py]
问题找到了!
action_chunk和progress都是CUDA tensor,需要转换:[tool: search_replace — Tool use: search_replace • Edit file: /home/[user]/Robotics/RLinf/examples/embodiment/collect_teleavatar_rollouts.py]
还需要修复final_progress的转换:
[tool: search_replace — Tool use: search_replace • Edit file: /home/[user]/Robotics/RLinf/examples/embodiment/collect_teleavatar_rollouts.py]
检查
build_policy_observation函数是否正确处理了tensor/numpy:[tool: read_file — Tool use: read_file • Read file: /home/[user]/Robotics/RLinf/examples/embodiment/collect_teleavatar_rollouts.py]
- User
@bash (933-1017) 现在仍然有报错,另外为何会进入到/home/[user]/Robotics/openpi路径而不是当前项目的openpi文件夹?
Assistant
看到两个问题:
- 错误在
policy.infer()内部发生(在我们能转换之前) - openpi路径错误:使用了
/home/[user]/Robotics/openpi而不是/home/[user]/Robotics/RLinf/openpi
需要修复openpi的
transforms.py来支持PyTorch tensor:[tool: read_file — Tool use: read_file • Read file: /home/[user]/Robotics/RLinf/openpi/src/openpi/transforms.py]
找到问题了!
transforms.py的_unnormalize_quantile不支持PyTorch tensor。修复:[tool: search_replace — Tool use: search_replace • Edit file: /home/[user]/Robotics/RLinf/openpi/src/openpi/transforms.py]
现在检查路径问题。查看脚本的sys.path设置:
[tool: read_file — Tool use: read_file • Read file: /home/[user]/Robotics/RLinf/examples/embodiment/collect_teleavatar_rollouts.py]
问题找到了!需要将openpi的
src目录加到路径:[tool: search_replace — Tool use: search_replace • Edit file: /home/[user]/Robotics/RLinf/examples/embodiment/collect_teleavatar_rollouts.py]
已修复两个问题:
1. ✅ 修复了支持PyTorch tensor
- 错误在