本文主要是介绍robosuite-自建夹具bug,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
场景:
在 robosuite
中创建自己的夹具
问题描述
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_obstraj = extract_trajectory(File "/home/idm/Shares/imitation/haier_environments/my_envs/utils/dataset_states_to_obs.py", line 85, in extract_trajectoryobs = env.reset_to(initial_state)File "/home/idm/Shares/imitation/robomimic/robomimic/envs/env_robosuite.py", line 157, in reset_toxml = self.env.edit_model_xml(state["model"])File "/home/idm/Shares/imitation/robosuite/robosuite/environments/base.py", line 536, in edit_model_xmlprint("old_path:", old_path)
ValueError: max() arg is an empty sequence
原因分析:
下列代码中有相应的代码路径及代码解释,其中,源码中存在一个 val
== robosuite
的操作,即所有的文件路径中都需要包含 robosuite
这个词(没有查明原因),考虑这个ind
参数是与 new_path
和 old_path
相关,所以就动态的print
了一下,发现这俩变量是恒等的,暂时没有领悟到作者这样作的意图是什么;
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 stringReturns:str: Edited xml file as string"""path = os.path.split(robosuite.__file__)[0]path_split = path.split("/")# replace mesh and texture file pathstree = ET.fromstring(xml_str)root = treeasset = root.find("asset")meshes = asset.findall("mesh")textures = asset.findall("texture")all_elements = meshes + texturesfor elem in all_elements:old_path = elem.get("file")if old_path is None:continueold_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 indexnew_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")
解决方案:
既然是恒等的,那就直接删掉就好,修改后的代码如下:
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 stringReturns:str: Edited xml file as string"""path = os.path.split(robosuite.__file__)[0]path_split = path.split("/")# replace mesh and texture file pathstree = ET.fromstring(xml_str)root = treeasset = root.find("asset")meshes = asset.findall("mesh")textures = asset.findall("texture")all_elements = meshes + texturesfor elem in all_elements:old_path = elem.get("file")if old_path is None:continueelem.set("file", old_path)return ET.tostring(root, encoding="utf8").decode("utf8")
这篇关于robosuite-自建夹具bug的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!