예제 #1
0
def main():
    # Load the agent from the submission
    print('Loading your agent')
    try:
        spec = importlib.util.spec_from_file_location('agent_module',
                                                      '/aaio/agent.py')
        agent_module = importlib.util.module_from_spec(spec)
        spec.loader.exec_module(agent_module)
        submitted_agent = agent_module.Agent()
    except Exception as e:
        print(
            'Your agent could not be loaded, make sure all the paths are absolute, error thrown:'
        )
        raise e
    print('Agent successfully loaded')

    arena_config_in = ArenaConfig('/aaio/test/1-Food.yaml')

    print('Resetting your agent')
    try:
        submitted_agent.reset(t=arena_config_in.arenas[0].t)
    except Exception as e:
        print('Your agent could not be reset:')
        raise e

    env = AnimalAIEnv(
        environment_filename='/aaio/test/env/AnimalAI',
        # seed=0,
        retro=False,
        n_arenas=1,
        worker_id=1,
        docker_training=True,
    )

    env.reset(arenas_configurations=arena_config_in)
    obs, reward, done, info = env.step([0, 0])

    print('Running 5 episodes')

    for k in range(5):
        cumulated_reward = 0
        print('Episode {} starting'.format(k))
        try:
            for i in range(arena_config_in.arenas[0].t):

                action = submitted_agent.step(obs, reward, done, info)
                obs, reward, done, info = env.step(action)
                cumulated_reward += reward
                if done:
                    break
        except Exception as e:
            print('Episode {} failed'.format(k))
            raise e
        print('Episode {0} completed, reward {1}'.format(k, cumulated_reward))

    print('SUCCESS')
예제 #2
0
import cv2

env_path = '../env/AnimalAI'
worker_id = random.randint(1, 100)
arena_config_in = ArenaConfig('ordered_configs/avoid_red/1-25-1.yml')

env = AnimalAIEnv(environment_filename=env_path,
                  worker_id=worker_id,
                  n_arenas=1,
                  arenas_configurations=arena_config_in,
                  docker_training=False,
                  retro=False)


done = False
number_of_episodes = 10
i = 0
SKIPPED_FRAMES = 10
state = env.reset()
print(state[0].shape)
print(state[0].ndim)
print(env.action_space.sample())
numpy_image = state[0] * 255
numpy_image = numpy_image.astype('uint8')
cv_image = cv2.cvtColor(numpy_image, cv2.COLOR_BGR2RGB)
resized = cv2.resize(cv_image, (300, 300), interpolation = cv2.INTER_AREA) 
cv2.imwrite('kk.png', resized)
state, reward, done, info = env.step(env.action_space.sample())
env.close()

예제 #3
0
worker_id = 100

env = AnimalAIEnv(environment_filename=env_path,
                  worker_id=worker_id,
                  n_arenas=1,
                  arenas_configurations=None,
                  docker_training=False,
                  retro=False)
for dir_name in os.listdir(path):
    if not os.path.exists('./datasets/{}'.format(dir_name)):
        os.makedirs('./datasets/{}'.format(dir_name))
    path_to_dir = os.path.join(path, dir_name)
    for file in os.listdir(path_to_dir):
        arena_file_path = os.path.join(path_to_dir, file)
        arena_config_in = ArenaConfig(arena_file_path)
        env.reset(arena_config_in)
        print(arena_file_path)
        i = 0
        done = False
        try:
            while True and i < number_of_images:
                done = False
                state = env.reset(arena_config_in)
                while not done and i < number_of_images:
                    numpy_image = state[0] * 255
                    numpy_image = numpy_image.astype('uint8')
                    cv_image = cv2.cvtColor(numpy_image, cv2.COLOR_BGR2RGB)
                    resized = cv2.resize(cv_image, (300, 300),
                                         interpolation=cv2.INTER_AREA)
                    cv2.imwrite(
                        './datasets/{}/{}_{}.png'.format(