Example #1
0
    def __init__(self, config):
        """Constructor.

    Panos can be assigned rewards (coins) randomly and the agent will receive
    the reward the first time they visit these panos.

    Args:
      config: config dict of various settings.
    """
        super(CoinGame, self).__init__()

        # Create colors from the input lists.
        self._colors = {
            'coin': color.Color(*config['color_for_coin']),
            'touched': color.Color(*config['color_for_touched_pano']),
        }
        self._reward_per_coin = config['reward_per_coin']

        # List of panos (will be populated using the streetlearn object).
        self._pano_ids = None

        # Association between pano id and color.
        self._pano_id_to_color = {}

        # Panos that (can) contain coins.
        self._proportion_of_panos_with_coins = config[
            'proportion_of_panos_with_coins']
        self._touched_pano_id_set = set()
        self._coin_pano_id_set = []
        self._num_coins = 0
        logging.info('Proportion of panos with coins: %f',
                     self._proportion_of_panos_with_coins)
        logging.info('Reward per coin: %f', self._reward_per_coin)
Example #2
0
    def __init__(self, config):
        """Constructor.

    This coin game gives extra reward for finding the goal pano, and resets the
    goal once the goal has been found (or on timeout). Panos can be assigned
    rewards (coins) randomly and the agent will receive the reward the first
    time they visit these panos.

    Args:
      config: config dict of various settings.
    """
        super(CourierGame, self).__init__(config)
        self._reward_current_goal = config['max_reward_per_goal']
        self._min_radius_meters = config['min_radius_meters']
        self._max_radius_meters = config['max_radius_meters']
        self._goal_timeout = config['goal_timeout']
        self._colors['goal'] = color.Color(*config['color_for_goal'])
        self._colors['shortest_path'] = color.Color(
            *config['color_for_shortest_path'])

        self._num_steps_this_goal = 0
        self._success_inverse_path_len = []
        self._min_distance_reached = np.finfo(np.float32).max
        self._initial_distance_to_goal = np.finfo(np.float32).max
        self._current_goal_id = None
        self._visited_panos = set()
        self._shortest_path = {}
        self._timed_out = False
    def __init__(self, config):
        """Creates an instance of the StreetLearn level.

    Args:
      config: config dict of various settings.
    """
        super(InstructionsBase, self).__init__(config)

        self._colors.update({
            'goal':
            color.Color(*config['color_for_goal']),
            'waypoint':
            color.Color(*config['color_for_waypoint']),
            'shortest_path':
            color.Color(*config['color_for_shortest_path']),
        })
        self._reward_at_waypoint = config['reward_at_waypoint']
        self._reward_at_goal = config['reward_at_goal']
        self._instruction_file = config['instruction_file']
        self._num_instructions = config['num_instructions']
        self._max_instructions = config['max_instructions']
        self._thumbnail_helper = thumbnail_helper.ThumbnailHelper()
        self._thumbnails = np.zeros(
            [self._max_instructions + 1, config['height'], config['width'], 3],
            dtype=np.uint8)
        logging.info('Using %d instructions', self._num_instructions)
        logging.info('Padding to %d instructions', self._max_instructions)
        self._instructions = []
        self._step_counter = 1
        self._reward_pano_id_list = {}
        self._reward_pano_id_to_family = {}
        self._reward_family = {}
        self._pano_id_to_color = {}
        self._goal_pano_id = None
        self._trajectory = None
        self._show_shortest_path = config['show_shortest_path']
        self._calculate_ground_truth = config['calculate_ground_truth']

        # Ground truth direction (for imitation learning agents).
        self._gt_direction = 0

        # Trajectories
        self._num_trajectories = 0
        self._trajectory_data = []
        self._loaded_trajectories = False
Example #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)
Example #5
0
 'curriculum_num_instructions_part_1': 2,
 'curriculum_bin_distance': 100.0,
 'curriculum_frame_cap': False,
 'curriculum_frame_cap_part_1': 100,
 'max_reward_per_cone': 0.49,
 'cone_radius_meters': 50.0,
 'goal_timeout': 1000,
 'frame_cap': 1000,
 'full_graph': True,
 'sample_graph_depth': True,
 'start_pano': '',
 'graph_zoom': 32,
 'show_shortest_path': False,
 'calculate_ground_truth': False,
 'neighbor_resolution': 8,
 'color_for_touched_pano': color.Color(1.0, 0.5, 0.5),
 'color_for_observer': color.Color(0.5, 0.5, 1.0),
 'color_for_coin': color.Color(1.0, 1.0, 0.0),
 'color_for_goal': color.Color(1.0, 0.0, 0.0),
 'color_for_shortest_path': color.Color(1.0, 0.0, 1.0),
 'color_for_waypoint': color.Color(0, 0.7, 0.7),
 'observations': ['view_image', 'graph_image'],
 'reward_per_coin': 1.0,
 'reward_at_waypoint': 0.5,
 'reward_at_goal': 1.0,
 'instruction_file': None,
 'num_instructions': 5,
 'max_instructions': 5,
 'proportion_of_panos_with_coins': 0.5,
 'game_name': 'coin_game',
 'action_spec': 'streetlearn_fast_rotate',
Example #6
0
  def __init__(self, dataset_path, config, game, engine=None):
    """Construct the StreetLearn environment.

    Args:
      dataset_path: filesystem path where the dataset resides.
      config: dictionary containing various config settings. Will be extended
        with defaults from default_config.DEFAULT_CONFIG.
      game: an instance of Game.
      engine: an instance of the StreetLearn engine (used when cloning an
        environment).
    """
    assert game, "Did not provide game."
    logging.info('dataset_path:')
    logging.info(dataset_path)
    logging.info('config:')
    _log_dictionary(config)
    logging.info('game:')
    logging.info(game)
    self._config = default_config.ApplyDefaults(config)
    self._seed = self._config["seed"]
    self._start_pano_id = self._config["start_pano"]
    self._zoom = self._config["graph_zoom"]
    self._black_on_white = self._config["graph_black_on_white"]
    self._frame_cap = self._config["frame_cap"]
    self._field_of_view = self._config["field_of_view"]
    self._neighbor_resolution = self._config["neighbor_resolution"]
    self._sample_graph_depth = self._config["sample_graph_depth"]
    self._min_graph_depth = self._config["min_graph_depth"]
    self._max_graph_depth = self._config["max_graph_depth"]
    self._full_graph = self._config["full_graph"]
    self._color_for_observer = color.Color(*self._config["color_for_observer"])
    self._action_spec = self._config["action_spec"]
    self._rotation_speed = self._config["rotation_speed"]
    self._auto_reset = self._config["auto_reset"]
    self._action_set = get_action_set(self._action_spec, self._rotation_speed)
    logging.info('Action set:')
    logging.info(self._action_set)
    self._bbox_lat_min = self._config["bbox_lat_min"]
    self._bbox_lat_max = self._config["bbox_lat_max"]
    self._bbox_lng_min = self._config["bbox_lng_min"]
    self._bbox_lng_max = self._config["bbox_lng_max"]

    self._game = game
    self._current_pano_id = None
    self._episode_id = -1
    self._frame_count = 0
    self._prev_reset = time.time()

    if engine:
      logging.info("Cloning an existing StreetLearnEngine.")
      self._engine = engine.Clone(
          width=self._config["width"],
          height=self._config["height"],
          graph_width=self._config["graph_width"],
          graph_height=self._config["graph_height"],
          status_height=self._config["status_height"],
          field_of_view=self._field_of_view,
          min_graph_depth=self._min_graph_depth,
          max_graph_depth=self._max_graph_depth)
    else:
      logging.info("Creating an new StreetLearnEngine.")
      self._engine = streetlearn_engine.StreetLearnEngine.Create(
          dataset_path,
          width=self._config["width"],
          height=self._config["height"],
          graph_width=self._config["graph_width"],
          graph_height=self._config["graph_height"],
          status_height=self._config["status_height"],
          field_of_view=self._field_of_view,
          min_graph_depth=self._min_graph_depth,
          max_graph_depth=self._max_graph_depth,
          max_cache_size=self._config["max_cache_size"])
    assert self._engine, "Could not initialise engine from %r." % dataset_path
    self._observations = []
    for name in self._config["observations"]:
      try:
        self._observations.append(observations.Observation.create(name, self))
      except ValueError as e:
        logging.warning(str(e))

    self._reward = 0
    self._prev_reward = 0
    self._prev_action = self._action_set[0]
    self._done = False
    self._info = {}