Exemplo n.º 1
0
    def __deserialize_goal(serialized_goal: Dict[str, Any]) -> ObjectGoal:
        g = ObjectGoal(**serialized_goal)

        for vidx, view in enumerate(g.view_points):
            view_location = ObjectViewLocation(**view)
            view_location.agent_state = AgentState(**view_location.agent_state)
            g.view_points[vidx] = view_location

        return g
Exemplo n.º 2
0
    def from_json(self,
                  json_str: str,
                  scenes_dir: Optional[str] = None) -> None:
        deserialized = json.loads(json_str)
        self.__dict__.update(deserialized)
        self.answer_vocab = VocabDict(word_list=self.answer_vocab["word_list"])
        self.question_vocab = VocabDict(
            word_list=self.question_vocab["word_list"])

        for ep_index, episode in enumerate(deserialized["episodes"]):
            episode = EQAEpisode(**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)
            episode.question = QuestionData(**episode.question)
            for g_index, goal in enumerate(episode.goals):
                episode.goals[g_index] = ObjectGoal(**goal)
                new_goal = episode.goals[g_index]
                if new_goal.view_points is not None:
                    for p_index, agent_state in enumerate(
                            new_goal.view_points):
                        new_goal.view_points[p_index] = AgentState(
                            **agent_state)
            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[ep_index] = episode
Exemplo n.º 3
0
    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)
def generate_objectnav_goals_by_category(sim: Simulator,
                                         task_category) -> ObjectGoal:

    scene = sim.semantic_annotations()
    target = dict()
    for obj in scene.objects:
        if obj is not None:
            # print(
            #     f"Object id:{obj.id}, category:{obj.category.name()}, Index:{obj.category.index()}"
            #     f" center:{obj.aabb.center}, dims:{obj.aabb.sizes}"
            # )
            if obj.category.name() in task_category.keys():
                if obj.category.index() in target:
                    target[obj.category.index()].append(obj)
                else:
                    target[obj.category.index()] = [obj]

    for i in target:
        # print("target episode len:", len(target[i]))
        object_category = target[i][0].category.name()
        # print("object_category :", object_category)
        str_goal = f"{os.path.basename(sim.config.SCENE)}_{object_category}"
        # print(str_goal)

        goals_by = []
        for j in range(len(target[i])):

            object_view_list = []
            for x in np.arange(
                    target[i][j].aabb.center[0] -
                    target[i][j].aabb.sizes[0] / 2.0,
                    target[i][j].aabb.center[0] +
                    target[i][j].aabb.sizes[0] / 2.0, 0.1):
                for y in np.arange(
                        target[i][j].aabb.center[2] -
                        target[i][j].aabb.sizes[2] / 2.0,
                        target[i][j].aabb.center[2] +
                        target[i][j].aabb.sizes[2] / 2.0, 0.1):
                    # print("x, y: ", type(x)) # np.float6
                    # print("x, y: ", type(target[i][j].aabb.center[1])) # np.floa32 报错
                    object_view_list.append(
                        ObjectViewLocation(
                            agent_state=AgentState(position=[
                                x, target[i][j].aabb.center[1].astype(
                                    np.float64), y
                            ]),
                            iou=0.0,
                        ))
            # print(type(object_view_list))
            goal_by_object = ObjectGoal(
                position=target[i][j].aabb.center,
                radius=0.5,
                object_id=int(re.findall(r"\d+", target[i][j].id)[0]),
                object_name=target[i][j].id,
                object_category=object_category,
                view_points=object_view_list,
            )

            goals_by.append(goal_by_object)

        yield str_goal, goals_by