Exemple #1
0
def main(_):
    pygame.init()
    try:
        pygame.mixer.quit()
    except NotImplementedError:
        pass
    pygame.display.set_caption('Fast Language Learning Tasks Human Agent')

    if 'with_distractors' in FLAGS.level_name:  # for the tasks from the HTM paper
        episode_length_seconds = 450.0
    else:
        episode_length_seconds = 120.0
    env_settings = dm_fast_mapping.EnvironmentSettings(
        seed=FLAGS.seed,
        level_name=FLAGS.level_name,
        episode_length_seconds=episode_length_seconds)
    with dm_fast_mapping.load_from_docker(name=FLAGS.docker_image_name,
                                          settings=env_settings) as env:
        screen = pygame.display.set_mode(
            (int(FLAGS.screen_size[0]), int(FLAGS.screen_size[1])))

        rgb_spec = env.observation_spec()['RGB_INTERLEAVED']
        surface = pygame.Surface((rgb_spec.shape[1], rgb_spec.shape[0]))

        actions = _NO_ACTION
        score = 0
        clock = pygame.time.Clock()
        while True:
            # Do not close with CTRL-C as otherwise the docker container may be left
            # running on exit.
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    return
                elif event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_ESCAPE:
                        return
                    key_actions = _KEYS_TO_ACTION.get(event.key, {})
                    for name, action in key_actions.items():
                        actions[name] += action
                elif event.type == pygame.KEYUP:
                    key_actions = _KEYS_TO_ACTION.get(event.key, {})
                    for name, action in key_actions.items():
                        actions[name] -= action

            timestep = env.step(actions)
            frame = np.swapaxes(timestep.observation['RGB_INTERLEAVED'], 0, 1)
            font = pygame.font.SysFont('Sans', 10)
            pygame.surfarray.blit_array(surface, frame)
            text = font.render(timestep.observation['TEXT'], True, (0, 0, 0))
            surface.blit(text, (0, 0))
            pygame.transform.smoothscale(surface, screen.get_size(), screen)

            pygame.display.update()

            if timestep.reward:
                score += timestep.reward
                logging.info('Total score: %1.1f, reward: %1.1f', score,
                             timestep.reward)
            clock.tick(_FRAMES_PER_SECOND)
def main(_):
    if 'with_distractors' in FLAGS.level_name:  # for the tasks from the HTM paper
        episode_length_seconds = 450.0
    else:
        episode_length_seconds = 120.0

    env_settings = dm_fast_mapping.EnvironmentSettings(
        seed=FLAGS.seed,
        level_name=FLAGS.level_name,
        episode_length_seconds=episode_length_seconds)
    with dm_fast_mapping.load_from_docker(name=FLAGS.docker_image_name,
                                          settings=env_settings) as env:
        agent = RandomAgent(env.action_spec())

        timestep = env.reset()
        score = 0
        while not timestep.last():
            action = agent.act()
            timestep = env.step(action)

            if timestep.reward:
                score += timestep.reward
                logging.info('Total score: %1.1f, reward: %1.1f', score,
                             timestep.reward)
Exemple #3
0
                        default="fast_slow/fast_map_three_objs")
    parser.add_argument("--episode_max_time", type=int, default=1202)
    parser.add_argument("--language_dim", type=int, default=108)
    parser.add_argument("--num_embeddings", type=int, default=50)
    parser.add_argument("--embedding_dim", type=int, default=32)
    parser.add_argument("--memory_hidden_dim", type=int, default=512)
    parser.add_argument("--action_dim", type=int, default=1)
    parser.add_argument("--max_episodes", type=int, default=100)
    parser.add_argument("--train_steps", type=int, default=1)
    parser.add_argument("--eval_freq", type=int, default=5)
    parser.add_argument("--start_episodes", type=int, default=10)
    parser.add_argument("--buffer_size", type=int, default=1000)
    parser.add_argument("--batch_size", type=int, default=1)
    args = parser.parse_args()

    settings = dm_fast_mapping.EnvironmentSettings(seed=0,
                                                   level_name=args.level_name)
    env = dm_fast_mapping.load_from_docker(settings)
    wrapped_env = FastSlowEnvWrapper(env)

    temp_timestep = wrapped_env.reset()
    vision_dim = temp_timestep.observation["RGB_INTERLEAVED"].shape

    tokenizer = BertWordPieceTokenizer(
        DIR_PATH + "/embedding_files/bert-base-uncased-vocab.txt",
        lowercase=True)
    tokenizer.enable_padding(pad_id=3,
                             length=args.language_dim,
                             pad_token="[PAD]")

    policy = Agent(
        language_dim=args.language_dim,
 def test_load_level(self, level_name):
     self.assertIsNotNone(
         dm_fast_mapping.load_from_disk(
             FLAGS.path,
             settings=dm_fast_mapping.EnvironmentSettings(
                 seed=123, level_name=level_name)))
 def make_object_under_test(self):
     return dm_fast_mapping.load_from_disk(
         FLAGS.path,
         settings=dm_fast_mapping.EnvironmentSettings(
             seed=123,
             level_name='architecture_comparison/fast_map_three_objs'))
Exemple #6
0
 def test_load_level(self, level_name):
     self.assertIsNotNone(
         dm_fast_mapping.load_from_docker(
             name=FLAGS.docker_image_name,
             settings=dm_fast_mapping.EnvironmentSettings(
                 seed=123, level_name=level_name)))