def from_json( self, json_str: str, scenes_dir: Optional[str] = None, scene_filename: Optional[str] = None ) -> None: deserialized = json.loads(json_str) if CONTENT_SCENES_PATH_FIELD in deserialized: self.content_scenes_path = deserialized[CONTENT_SCENES_PATH_FIELD] episode_cnt = 0 for episode in deserialized["episodes"]: episode = NavigationEpisode(**episode) if scenes_dir is not None: if episode.scene_id.startswith(DEFAULT_SCENE_PATH_PREFIX): episode.scene_id = episode.scene_id[ len(DEFAULT_SCENE_PATH_PREFIX): ] episode.scene_id = os.path.join(scenes_dir, episode.scene_id) for g_index, goal in enumerate(episode.goals): episode.goals[g_index] = NavigationGoal(**goal) if episode.shortest_paths is not None: for path in episode.shortest_paths: for p_index, point in enumerate(path): path[p_index] = ShortestPathPoint(**point) self.episodes.append(episode) episode_cnt += 1
def from_json(self, json_str: str, scenes_dir: Optional[str] = None) -> None: deserialized = json.loads(json_str) if CONTENT_SCENES_PATH_FIELD in deserialized: self.content_scenes_path = deserialized[CONTENT_SCENES_PATH_FIELD] if "category_to_task_category_id" in deserialized: self.category_to_task_category_id = deserialized[ "category_to_task_category_id"] if "category_to_scene_annotation_category_id" in deserialized: self.category_to_scene_annotation_category_id = deserialized[ "category_to_scene_annotation_category_id"] if "category_to_mp3d_category_id" in deserialized: self.category_to_scene_annotation_category_id = deserialized[ "category_to_mp3d_category_id"] assert len(self.category_to_task_category_id) == len( self.category_to_scene_annotation_category_id) assert set(self.category_to_task_category_id.keys()) == set( self.category_to_scene_annotation_category_id.keys( )), "category_to_task and category_to_mp3d must have the same keys" for episode in deserialized["episodes"]: episode = NavigationEpisode(**episode) if scenes_dir is not None: if episode.scene_id.startswith(DEFAULT_SCENE_PATH_PREFIX): episode.scene_id = episode.scene_id[ len(DEFAULT_SCENE_PATH_PREFIX):] episode.scene_id = os.path.join(scenes_dir, episode.scene_id) for i in range(len(episode.goals)): episode.goals[i] = ObjectGoal(**episode.goals[i]) for vidx, view in enumerate(episode.goals[i].view_points): view_location = ObjectViewLocation(**view) view_location.agent_state = AgentState( **view_location.agent_state) episode.goals[i].view_points[vidx] = view_location if episode.shortest_paths is not None: for path in episode.shortest_paths: for p_index, point in enumerate(path): point = { "action": point, "rotation": None, "position": None, } path[p_index] = ShortestPathPoint(**point) self.episodes.append(episode) for i, ep in enumerate(self.episodes): ep.episode_id = str(i)