Пример #1
0
    def __init__(
        self,
        worker_id,
        env_path,
        config_path,
        reduced_actions=False,
        docker_training=False,
    ):
        super(AnimalAIWrapper, self).__init__()
        self.config = ArenaConfig(config_path)
        self.time_limit = self.config.arenas[0].t

        self.env = UnityEnvironment(
            file_name=env_path,
            worker_id=worker_id,
            seed=worker_id,
            n_arenas=1,
            arenas_configurations=self.config,
            docker_training=docker_training,
        )

        lookup_func = lambda a: {"Learner": np.array([a], dtype=float)}
        if reduced_actions:
            lookup = itertools.product([0, 1], [0, 1, 2])
        else:
            lookup = itertools.product([0, 1, 2], repeat=2)
        lookup = dict(enumerate(map(lookup_func, lookup)))
        self.action_map = lambda a: lookup[a]

        self.observation_space = gym.spaces.Box(0,
                                                255, [84, 84, 3],
                                                dtype=np.uint8)
        self.action_space = gym.spaces.Discrete(len(lookup))
        self.t = 0
)

config_dict = {
    1: "1-Food.yaml",
    2: "2-Preferences.yaml",
    3: "3-Obstacles.yaml",
    4: "4-Avoidance.yaml",
    5: "5-SpatialReasoning.yaml",
    6: "6-Generalization.yaml",
    7: "7-InternalMemory.yaml"
}

env_file = config_dict[int(parser.parse_args().env)]

arena_config = ArenaConfig(
    "/home/duju/animal_ai_olympics/duju_animal_ai_olympics/configs/" +
    env_file)

exp_title = "Animal_AI_Baseline4_" + env_file.split(".")[0]
print(exp_title)

exp_dir = "/home/duju/animal_ai_olympics/duju_animal_ai_olympics/baseline_results/" + exp_title
os.makedirs(exp_dir)
txt_path = os.path.join(exp_dir, "results.txt")

action_dict = {
    0: np.array([1, 0]),  # forward
    1: np.array([0, 2]),  # left
    2: np.array([0, 1]),  # right
    #                3 : np.array([2,0]) # backward
}