robosuite-自建夹具bug

场景:

在 robosuite 中创建自己的夹具

问题描述

bash 复制代码
Traceback (most recent call last):
  File "collect_human_demonstrations_auto.py", line 436, in <module>
    dataset_states_to_obs(output_filename, save_name+"-obs.hdf5")
  File "/home/idm/Shares/imitation/haier_environments/my_envs/utils/dataset_states_to_obs.py", line 221, in dataset_states_to_obs
    traj = extract_trajectory(
  File "/home/idm/Shares/imitation/haier_environments/my_envs/utils/dataset_states_to_obs.py", line 85, in extract_trajectory
    obs = env.reset_to(initial_state)
  File "/home/idm/Shares/imitation/robomimic/robomimic/envs/env_robosuite.py", line 157, in reset_to
    xml = self.env.edit_model_xml(state["model"])
  File "/home/idm/Shares/imitation/robosuite/robosuite/environments/base.py", line 536, in edit_model_xml
    print("old_path:", old_path)
ValueError: max() arg is an empty sequence

原因分析:

下列代码中有相应的代码路径及代码解释,其中,源码中存在一个 val == robosuite 的操作,即所有的文件路径中都需要包含 robosuite 这个词(没有查明原因),考虑这个ind 参数是与 new_path 和 old_path 相关,所以就动态的print 了一下,发现这俩变量是恒等的,暂时没有领悟到作者这样作的意图是什么;

python 复制代码
 def edit_model_xml(self, xml_str):
        """
        This function edits the model xml with custom changes, including resolving relative paths,
        applying changes retroactively to existing demonstration files, and other custom scripts.
        Environment subclasses should modify this function to add environment-specific xml editing features.
        Args:
            xml_str (str): Mujoco sim demonstration XML file as string
        Returns:
            str: Edited xml file as string
        """

        path = os.path.split(robosuite.__file__)[0]
        path_split = path.split("/")

        # replace mesh and texture file paths
        tree = ET.fromstring(xml_str)
        root = tree
        asset = root.find("asset")
        meshes = asset.findall("mesh")
        textures = asset.findall("texture")
        all_elements = meshes + textures

        for elem in all_elements:
            old_path = elem.get("file")
            if old_path is None:
                continue
            old_path_split = old_path.split("/")
            import ipdb; ipdb.set_trace()
            print("old_path:", old_path)
            print("old_path_split:", old_path_split)
            ind = max(loc for loc, val in enumerate(old_path_split) if val == "robosuite")  # last occurrence index
            new_path_split = path_split + old_path_split[ind + 1 :]
            new_path = "/".join(new_path_split)
            # print("new_path:", new_path)
            # if new_path == old_path:
                # print("new_path == old_path")
            # else:
                # print("new_path != old_path")

            # elem.set("file", new_path)
            elem.set("file", old_path)

        return ET.tostring(root, encoding="utf8").decode("utf8")

解决方案:

既然是恒等的,那就直接删掉就好,修改后的代码如下:

python 复制代码
 def edit_model_xml(self, xml_str):
        """
        This function edits the model xml with custom changes, including resolving relative paths,
        applying changes retroactively to existing demonstration files, and other custom scripts.
        Environment subclasses should modify this function to add environment-specific xml editing features.
        Args:
            xml_str (str): Mujoco sim demonstration XML file as string
        Returns:
            str: Edited xml file as string
        """

        path = os.path.split(robosuite.__file__)[0]
        path_split = path.split("/")

        # replace mesh and texture file paths
        tree = ET.fromstring(xml_str)
        root = tree
        asset = root.find("asset")
        meshes = asset.findall("mesh")
        textures = asset.findall("texture")
        all_elements = meshes + textures
        for elem in all_elements:
            old_path = elem.get("file")
            if old_path is None:
                continue
            elem.set("file", old_path)

        return ET.tostring(root, encoding="utf8").decode("utf8")
相关推荐
鱼很腾apoc5 分钟前
【Redis】第4期 详解主从复制、哨兵、集群
linux·redis·学习·集群·主从复制·哨兵
阿策小和尚7 分钟前
4.3GB 依赖树压到 284MB、五进程 500ms 退场:我把 4 万星的 Novu 塞进了 Dopame OS
人工智能·后端·架构
JonaHu7 分钟前
GPT Image 2.6 多参考图改穿搭:输入分工与参考污染排查
图像处理·人工智能·api
hhb_6188 分钟前
AI自动化工作流:一键打通业务协同壁垒
大数据·人工智能·自动化
极客先躯12 分钟前
智能体开发高级面试每日一题|2026-06-04|Agent 的规划(Planning)能力来自哪里?LLM 原生规划有哪些局限?
人工智能·面试·agent·每日一题·高级面试·智能体开发·agenticworkflow
阿策小和尚13 分钟前
把 Python 3.14 + FastAPI + Nuxt 4 压成 164MB 单包迁进 Dopame OS:4 个坑和一份真实体积账单
前端·人工智能·前端框架
极客先躯13 分钟前
智能体开发高级面试每日一题|2026-06-02|为什么说“Agent 的能力上限由 LLM 决定“?工程层面可以做哪些弥补?
人工智能·面试·大模型·llm·agent·高级面试题·智能体开发
kobesdu16 分钟前
RK3588 还是等 RK3668?一次选型窗口的取舍
人工智能·机器人·ros·slam
嗨起飞了22 分钟前
《Finerd:AI产品榜第 1 名的只读核查》
人工智能
爱聊灵光的维C22 分钟前
AI时代下,写博客的意义体现在哪里?
人工智能·学习·技术思考·思想成长