예제 #1
0
def main(argv):
  config = {'width': FLAGS.width,
            'height': FLAGS.height,
            'field_of_view': FLAGS.field_of_view,
            'graph_width': FLAGS.width,
            'graph_height': FLAGS.height,
            'graph_zoom': FLAGS.graph_zoom,
            'graph_black_on_white': FLAGS.graph_black_on_white,
            'goal_timeout': FLAGS.frame_cap,
            'frame_cap': FLAGS.frame_cap,
            'full_graph': (FLAGS.start_pano == ''),
            'start_pano': FLAGS.start_pano,
            'min_graph_depth': FLAGS.graph_depth,
            'max_graph_depth': FLAGS.graph_depth,
            'max_cache_size': FLAGS.max_cache_size,
            'proportion_of_panos_with_coins':
                FLAGS.proportion_of_panos_with_coins,
            'action_spec': 'streetlearn_fast_rotate',
            'observations': ['view_image_hwc', 'graph_image_hwc',
                             'target_latlng', 'prev_reward', 'prev_action']}
  config = default_config.ApplyDefaults(config)
  game = courier_game.CourierGame(config)
  env = streetlearn.StreetLearn(FLAGS.dataset_path, config, game)
  env.reset()
  pygame.init()
  screen = pygame.display.set_mode((FLAGS.width, FLAGS.height * 2))
  loop(env, screen)
def main(argv):
  config = {'width': FLAGS.width,
            'height': FLAGS.height,
            'graph_width': FLAGS.width,
            'graph_height': FLAGS.height,
            'graph_zoom': 1,
            'full_graph': True,
            'proportion_of_panos_with_coins': 0.0,
            'action_spec': 'streetlearn_fast_rotate',
            'observations': ['view_image', 'graph_image', 'yaw']}
  with open(FLAGS.list_pano_ids_yaws, 'r') as f:
    lines = f.readlines()
    pano_ids_yaws = [(line.split('\t')[0], float(line.split('\t')[1]))
                     for line in lines]
  config = default_config.ApplyDefaults(config)
  game = coin_game.CoinGame(config)
  env = streetlearn.StreetLearn(FLAGS.dataset_path, config, game)
  env.reset()
  pygame.init()
  screen = pygame.display.set_mode((FLAGS.width, FLAGS.height * 2))
  loop(env, screen, pano_ids_yaws)
예제 #3
0
def main(argv):
    config = {
        'width':
        FLAGS.width,
        'height':
        FLAGS.height,
        'graph_width':
        FLAGS.width,
        'graph_height':
        FLAGS.height,
        'graph_zoom':
        1,
        'goal_timeout':
        FLAGS.frame_cap,
        'frame_cap':
        FLAGS.frame_cap,
        'full_graph': (FLAGS.start_pano == ""),
        'start_pano':
        FLAGS.start_pano,
        'min_graph_depth':
        FLAGS.graph_depth,
        'max_graph_depth':
        FLAGS.graph_depth,
        'proportion_of_panos_with_coins':
        FLAGS.proportion_of_panos_with_coins,
        'observations': [
            'view_image', 'graph_image', 'yaw', 'pitch', 'latlng',
            'target_latlng'
        ]
    }
    config = default_config.ApplyDefaults(config)
    game = courier_game.CourierGame(config)
    env = streetlearn.StreetLearn(FLAGS.dataset_path, config, game)
    env.reset()
    pygame.init()
    screen = pygame.display.set_mode((FLAGS.width, FLAGS.height * 2))
    loop(env, screen)
예제 #4
0
def main(argv):
    config = {
        'width':
        FLAGS.width,
        'height':
        FLAGS.height,
        'field_of_view':
        FLAGS.field_of_view,
        'graph_width':
        FLAGS.width,
        'graph_height':
        FLAGS.height,
        'graph_zoom':
        FLAGS.graph_zoom,
        'graph_black_on_white':
        FLAGS.graph_black_on_white,
        'show_shortest_path':
        FLAGS.show_shortest_path,
        'goal_timeout':
        FLAGS.frame_cap,
        'frame_cap':
        FLAGS.frame_cap,
        'full_graph': (FLAGS.start_pano == ''),
        'start_pano':
        FLAGS.start_pano,
        'min_graph_depth':
        FLAGS.graph_depth,
        'max_graph_depth':
        FLAGS.graph_depth,
        'reward_at_waypoint':
        FLAGS.reward_at_waypoint,
        'reward_at_goal':
        FLAGS.reward_at_goal,
        'instruction_file':
        FLAGS.instruction_file,
        'num_instructions':
        FLAGS.num_instructions,
        'max_instructions':
        FLAGS.max_instructions,
        'proportion_of_panos_with_coins':
        FLAGS.proportion_of_panos_with_coins,
        'observations': [
            'view_image_hwc', 'graph_image_hwc', 'yaw', 'thumbnails', 'pitch',
            'instructions', 'latlng', 'target_latlng'
        ]
    }
    if FLAGS.hide_goal:
        config['color_for_goal'] = color.Color(1.0, 1.0, 1.0)
    config = default_config.ApplyDefaults(config)
    if FLAGS.game == 'coin_game':
        game = coin_game.CoinGame(config)
    elif FLAGS.game == 'courier_game':
        game = courier_game.CourierGame(config)
    elif FLAGS.game == 'goal_instruction_game':
        game = goal_instruction_game.GoalInstructionGame(config)
    elif FLAGS.game == 'incremental_instruction_game':
        game = incremental_instruction_game.IncrementalInstructionGame(config)
    elif FLAGS.game == 'step_by_step_instruction_game':
        game = step_by_step_instruction_game.StepByStepInstructionGame(config)
    else:
        print('Unknown game: [{}]'.format(FLAGS.game))
        print('Run with --help for available options.')
        return
    env = streetlearn.StreetLearn(FLAGS.dataset_path, config, game)
    env.reset()

    # Configure pygame.
    pygame.init()
    pygame.font.init()
    if FLAGS.game == 'coin_game' or FLAGS.game == 'courier_game':
        subsampling = 1
        x_max = FLAGS.width
        y_max = FLAGS.height * 2
        logging.info('Rendering images at %dx%d', x_max, y_max)
    else:
        subsampling = int(np.ceil((FLAGS.max_instructions + 1) / 2))
        x_max = FLAGS.width + int(FLAGS.width / subsampling) + FLAGS.width_text
        y_max = FLAGS.height * 2
        logging.info('Rendering images at %dx%d, thumbnails subsampled by %d',
                     x_max, y_max, subsampling)
    screen = pygame.display.set_mode((x_max, y_max))
    font = pygame.font.SysFont('arial', FLAGS.font_size)

    loop(env, screen, x_max, y_max, subsampling, font)
예제 #5
0
def main(argv):
    config = {
        'width':
        FLAGS.width,
        'height':
        FLAGS.height,
        'field_of_view':
        FLAGS.field_of_view,
        'status_height':
        0,
        'graph_width':
        FLAGS.width,
        'graph_height':
        FLAGS.height,
        'graph_zoom':
        FLAGS.graph_zoom,
        'show_shortest_path':
        FLAGS.show_shortest_path,
        'calculate_ground_truth':
        True,
        'goal_timeout':
        FLAGS.frame_cap,
        'frame_cap':
        FLAGS.frame_cap,
        'full_graph': (FLAGS.start_pano == ''),
        'start_pano':
        FLAGS.start_pano,
        'min_graph_depth':
        FLAGS.graph_depth,
        'max_graph_depth':
        FLAGS.graph_depth,
        'reward_at_waypoint':
        FLAGS.reward_at_waypoint,
        'reward_at_goal':
        FLAGS.reward_at_goal,
        'instruction_file':
        FLAGS.instruction_file,
        'num_instructions':
        FLAGS.num_instructions,
        'max_instructions':
        FLAGS.max_instructions,
        'proportion_of_panos_with_coins':
        0.0,
        'action_spec':
        'streetlearn_fast_rotate',
        'observations': [
            'view_image', 'graph_image', 'yaw', 'thumbnails', 'instructions',
            'ground_truth_direction'
        ]
    }
    # Configure game and environment.
    config = default_config.ApplyDefaults(config)
    if FLAGS.game == 'goal_instruction_game':
        game = goal_instruction_game.GoalInstructionGame(config)
    elif FLAGS.game == 'incremental_instruction_game':
        game = incremental_instruction_game.IncrementalInstructionGame(config)
    elif FLAGS.game == 'step_by_step_instruction_game':
        game = step_by_step_instruction_game.StepByStepInstructionGame(config)
    else:
        print('Unknown game: [{}]'.format(FLAGS.game))
        print('Run instruction_following_oracle_agent --help.')
        return
    env = streetlearn.StreetLearn(FLAGS.dataset_path, config, game)
    env.reset()

    # Configure pygame.
    pygame.init()
    pygame.font.init()
    subsampling = int(np.ceil((FLAGS.max_instructions + 1) / 2))
    x_max = FLAGS.width + int(FLAGS.width / subsampling) + FLAGS.width_text
    y_max = FLAGS.height * 2
    logging.info('Rendering images at %dx%d, thumbnails subsampled by %d',
                 x_max, y_max, subsampling)
    screen = pygame.display.set_mode((x_max, y_max))
    font = pygame.font.SysFont('arial', FLAGS.font_size)

    loop(env, screen, x_max, y_max, subsampling, font)
    def __init__(self,
                 dataset_path,
                 configs,
                 games,
                 num_env_per_shared_cache=1):
        """Construct the StreetLearn environment.

    Args:
      dataset_path: filesystem path where the dataset resides.
      configs: list of batch_size elements, each element being a dictionary
        containing various config settings, that will be extended with defaults
        from default_config.DEFAULT_CONFIG.
      games: list of batch_size instances of Game.
      num_env_per_shared_cache: number of environments that share the same cache
        By default equal to 1 (no cache sharing).
    """
        # Check that batch_size is a multiple of num_env_per_shared_cache and that
        # the action_spec, rotation_speed and observations are compatible between
        # all environments.
        batch_size = len(games)
        assert batch_size > 0
        assert num_env_per_shared_cache > 0
        num_env_per_shared_cache = min(num_env_per_shared_cache, batch_size)
        num_unique_node_caches = int(batch_size / num_env_per_shared_cache)
        logging.info('batch_size: %d, num_env_per_shared_cache: %d',
                     batch_size, num_env_per_shared_cache)
        logging.info('num_unique_node_caches: %d', num_unique_node_caches)
        assert (num_env_per_shared_cache *
                num_unique_node_caches) == batch_size
        assert len(configs) == batch_size
        for k in range(1, batch_size):
            assert configs[0]['action_spec'] == configs[k]['action_spec']
            assert configs[0]['rotation_speed'] == configs[k]['rotation_speed']
            observations = configs[k]['observations'].sort()
            assert configs[0]['observations'].sort() == observations

        # Instantiate the environments.
        self._envs = []
        k = 0
        for i in range(num_unique_node_caches):
            logging.info('Instantiating environment %d with a new node_cache',
                         k)
            self._envs.append(
                streetlearn.StreetLearn(dataset_path, configs[k], games[k]))
            k += 1
            for j in range(1, num_env_per_shared_cache):
                logging.info(
                    'Instantiating environment %d reusing last node_cache', k)
                self._envs.append(
                    streetlearn.StreetLearn(dataset_path, configs[k], games[k],
                                            self._envs[k - 1].engine))
                k += 1

        # Preallocate the matrices for the batch observations.
        self._observation_batch = {}
        for item in self._envs[0]._observations:
            if item.observation_spec == [0]:
                batched_shape = [
                    batch_size,
                ]
            else:
                batched_shape = [
                    batch_size,
                ] + item.observation_spec
            batched_obs = np.zeros(batched_shape,
                                   dtype=item.observation_spec_dtypes)
            self._observation_batch[item.name] = batched_obs
        self._batch_size = batch_size