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 create_environment(level_name, seed, is_test=False): """Creates an environment wrapped in a `FlowEnvironment`.""" observations = FLAGS.observations.split(';') tf.logging.info('Observations requested:') tf.logging.info(observations) config = { 'status_height': 0, 'width': FLAGS.width, 'height': FLAGS.height, 'graph_width': FLAGS.graph_width, 'graph_height': FLAGS.graph_height, 'graph_zoom': FLAGS.graph_zoom, 'game_name': FLAGS.game_name, '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, 'timestamp_start_curriculum': FLAGS.timestamp_start_curriculum, 'hours_curriculum_part_1': FLAGS.hours_curriculum_part_1, 'hours_curriculum_part_2': FLAGS.hours_curriculum_part_2, 'min_goal_distance_curriculum': FLAGS.min_goal_distance_curriculum, 'max_goal_distance_curriculum': FLAGS.max_goal_distance_curriculum, 'observations': observations, 'bbox_lat_min': FLAGS.bbox_lat_min, 'bbox_lat_max': FLAGS.bbox_lat_max, 'bbox_lng_min': FLAGS.bbox_lng_min, 'bbox_lng_max': FLAGS.bbox_lng_max, 'min_radius_meters': FLAGS.min_radius_meters, 'max_radius_meters': FLAGS.max_radius_meters, } config = default_config.ApplyDefaults(config) tf.logging.info(config) game = default_config.CreateGame(config['game_name'], config) dataset_path = FLAGS.dataset_paths + '/' + level_name tf.logging.info(dataset_path) p = py_process.PyProcess( StreetLearnImpalaAdapter, dataset_path, config, game) return FlowEnvironment(p.proxy)
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)
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', 'yaw', 'pitch'] } config = default_config.ApplyDefaults(config) # Create as many configs and games as the batch size. games = [] configs = [] for k in range(FLAGS.batch_size): this_config = copy.copy(config) this_config['seed'] = k configs.append(this_config) games.append(courier_game.CourierGame(this_config)) env = batched_streetlearn.BatchedStreetLearn( FLAGS.dataset_path, configs, games, num_env_per_shared_cache=FLAGS.num_env_per_shared_cache) env.reset() pygame.init() screen = pygame.display.set_mode( (FLAGS.width * FLAGS.batch_size, 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, '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)
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)
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, 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 = {}