def main(): global VIDEO_WRITER parser = argparse.ArgumentParser(description='Interactive interface to Simulator') parser.add_argument('--navmap', action='store_true', default=False, help='Use navigation map') group = parser.add_mutually_exclusive_group() group.add_argument('--state_set_file', help='State set file') group.add_argument('--replay', help='Load and replay action trace from file') group.add_argument('--replay_mode', choices=REPLAY_MODES, default='positions', help='Use actions or positions for replay') group.add_argument('--show_goals', action='store_true', default=False, help='show goal observations') args = parse_sim_args(parser) args.visualize_sensors = True sim = Simulator(vars(args)) common.attach_exit_handler(sim) if 'state_set_file' in args and args.state_set_file is not None: args.state_set = StateSet(args.state_set_file, 1) if 'save_video' in args and len(args.save_video): filename = args.save_video if type(args.save_video) is str else 'out.mp4' is_rgb = args.color_encoding == 'rgba' VIDEO_WRITER = VideoWriter(filename, framerate=24, resolution=(args.width, args.height), rgb=is_rgb) if 'replay' in args and args.replay is not None: print('Initializing simulator using action traces %s...' % args.replay) args.action_traces = ActionTraces(args.replay) action_trace = args.action_traces.next_trace() sim.init() start_state = action_trace.start_state() print('start_state', start_state) sim.configure(start_state) else: args.action_traces = None args.replay = None try: print('Starting simulator...') ep_info = sim.start() if ep_info: print('observation_space', sim.get_observation_space()) sim.episode_info = ep_info print('Simulator started.') interactive_loop(sim, args) except: traceback.print_exc() print('Error running simulator. Aborting.') if sim is not None: sim.kill() del sim if VIDEO_WRITER is not None: VIDEO_WRITER.close()
def configure(self, sim_args): print("varrrr") print(vars(sim_args)) self.arg = sim_args self.set_scene(number='11be354e8dbd5d7275c486a5037ea949') self.set_goal() self._sim = Simulator(vars(sim_args)) common.attach_exit_handler(self._sim) self._sim.start()
def main(): parser = argparse.ArgumentParser(description='MINOS gym wrapper') args = parse_sim_args(parser) sim = RoomSimulator(args) common.attach_exit_handler(sim.sim) try: print('Starting RoomSimulator...') sim.init() print('RoomSimulator started.') interactive_loop(sim, args) except: traceback.print_exc() print('Error running simulator. Aborting.') if sim is not None: sim.close_game() del sim
def run(args): if args.scenes: scenes = edict(common.load_scenes_file(args.scenes)) scene_ids = [ r.id for r in scenes[args.split] if args.min_rooms < r.nrooms < args.max_rooms ] else: scene_ids = args.scene_ids sim = Simulator(vars(args)) common.attach_exit_handler(sim) sim.init() sim.seed(random.randint(0, 12345678)) f = open(args.output, 'w') n_scenes = len(scene_ids) for i in range(0, n_scenes): process_scene(sim, args.scene.dataset, scene_ids[i], f, args.level, args.num_levels, args.samples_per_scene, i)
def main(): parser = argparse.ArgumentParser(description='MINOS gym wrapper') add_sim_args_basic(parser) parser.add_argument('--env_config', default='objectgoal_suncg_sf', help='Environment configuration file') args = parser.parse_args() sim_args = sim_config.get(args.env_config, vars(args)) sim = RoomSimulator(sim_args) common.attach_exit_handler(sim.sim) try: print('Starting RoomSimulator...') sim.init() print('RoomSimulator started.') interactive_loop(sim, args) except: traceback.print_exc() print('Error running simulator. Aborting.') if sim is not None: sim.close_game() del sim
nscenes = args.num_scenes or len(scene_ids) async = args. async print( 'Benchmarking %d simulators (%s) with %d scenes, %d episodes each scene, %d steps each episode' % (nsims, 'async' if async else 'sync', nscenes, nepisodes, nsteps)) total_secs_from_start = 0 total_secs_from_init = 0 total_steps = 0 episode = 0 sims = [] for i in range(0, nsims): sims.append(Simulator(vars(args))) common.attach_exit_handler(sims) process_simulators(sims, act=lambda s: s.init(), async=async) init_time = timer() print( 'scene,episode,nsteps,secs_no_setup,fps_no_setup,secs_with_setup,fps_with_setup' ) try: def start_sim(sim, reset_only): sim.seed(random.randint(0, 12345678)) if reset_only: sim.reset() else: sim.start()
def main(): global VIDEO_WRITER parser = argparse.ArgumentParser(description='Interactive interface to Simulator') parser.add_argument('--navmap', action='store_true', default=False, help='Use navigation map') group = parser.add_mutually_exclusive_group() group.add_argument('--state_set_file', help='State set file') group.add_argument('--replay', help='Load and replay action trace from file') parser.add_argument('--rightcamera', default='True', help='Right camera setting') parser.add_argument('--depthright', default='True', help='Right camera setting') parser.add_argument('--leftcamera', default='True', help='Left camera setting') parser.add_argument('--depthleft', default='True', help='Left camera setting') parser.add_argument('--replay_mode', choices=REPLAY_MODES, default='positions', help='Use actions or positions for replay') group.add_argument('--show_goals', action='store_true', default=False, help='show goal observations') parser.add_argument('--patch_len', action='store_true', default=30, help='patch_length used to calculate toc in center of the image') parser.add_argument('--save_toc', action='store_true', default=True, help='associates images with time of contact') parser.add_argument('--save_rootdir', default="/media/fadhil/ThirdPartition/3_3DVision/2_Dataset/minosdata/", help='save rootdir for the generated dataset') args = parse_sim_args(parser) args.visualize_sensors = True sim = Simulator(vars(args)) common.attach_exit_handler(sim) if 'state_set_file' in args and args.state_set_file is not None: args.state_set = StateSet(args.state_set_file, 1) if 'save_video' in args and len(args.save_video): filename = args.save_video if type(args.save_video) is str else 'out.mp4' is_rgb = args.color_encoding == 'rgba' VIDEO_WRITER = VideoWriter(filename, framerate=24, resolution=(args.width, args.height), rgb=is_rgb) if 'replay' in args and args.replay is not None: print('Initializing simulator using action traces %s...' % args.replay) args.action_traces = ActionTraces(args.replay) action_trace = args.action_traces.next_trace() sim.init() sim.seed(random.randint(0, 12345678)) start_state = action_trace.start_state() print('start_state', start_state) sim.configure(start_state) else: args.action_traces = None args.replay = None try: print('Starting simulator...') ep_info = sim.start() if ep_info: print('observation_space', sim.get_observation_space()) sim.episode_info = ep_info print('Simulator started.') interactive_loop(sim, args) except: traceback.print_exc() print('Error running simulator. Aborting.') if sim is not None: sim.kill() del sim if VIDEO_WRITER is not None: VIDEO_WRITER.close()
def _interactive_loop(stdscr, sim, scene_ids, scene_index): common.attach_exit_handler(sim) stdscr.timeout(1000) # Set timeout to 1 second before running loop again curses.cbreak() stdscr.keypad(1) stdscr.addstr(0, 10, "Interactive mode (WASD + UP/DOWN). Hit 'q' to quit") stdscr.refresh() stdscr.move(1, 15) action_strength = 1 # Acceleration multiplier for actions look_angle = math.radians(15) # Look up/down increment in radians print( 'IJKL+Arrows = move agent, N = next_scene, Q = quit, other keys = idle' ) while sim.running: key = stdscr.getch() if key < 0: continue # check if we should exit elif key == ord('q'): break action = { 'name': 'idle', 'strength': action_strength, 'angle': look_angle } stdscr.clrtobot() stdscr.refresh() if key == ord('i'): stdscr.addstr(1, 20, 'forward ') action['name'] = 'forwards' elif key == ord('k'): stdscr.addstr(1, 20, 'backward ') action['name'] = 'backwards' elif key == ord('j'): stdscr.addstr(1, 20, 'turn_left ') action['name'] = 'turnLeft' elif key == ord('l'): stdscr.addstr(1, 20, 'turn_right ') action['name'] = 'turnRight' elif key == ord('n'): scene_index = (scene_index + 1) % len(scene_ids) stdscr.addstr(1, 20, 'next_scene loading %s ...' % scene_ids[scene_index]) sim.set_scene(scene_ids[scene_index]) stdscr.refresh() sim.start() stdscr.addstr(1, 20, 'next_scene %s' % scene_ids[scene_index]) stdscr.clrtoeol() stdscr.refresh() elif key == ord('r'): sim.restart(randomize_ports=True) elif key == curses.KEY_LEFT: stdscr.addstr(1, 20, 'strafe_left ') action['name'] = 'strafeLeft' elif key == curses.KEY_RIGHT: stdscr.addstr(1, 20, 'strafe_right ') action['name'] = 'strafeRight' elif key == curses.KEY_UP: stdscr.addstr(1, 20, 'look_up ') action['name'] = 'lookUp' elif key == curses.KEY_DOWN: stdscr.addstr(1, 20, 'look_down ') action['name'] = 'lookDown' else: stdscr.addstr(1, 20, 'idling ') action['name'] = 'idle' stdscr.clrtobot() stdscr.move(1, 15) stdscr.refresh() response = sim.step(action, 1) observation = response.get( 'observation') if response is not None else None if observation is not None: nrow = 3 simple_observations = { k: v for k, v in observation.items() if k not in ['measurements', 'sensors'] } dicts = [ simple_observations, observation.get('measurements'), observation.get('sensors') ] for d in dicts: for k, v in d.items(): if type(v) is not dict: info = '%s: %s' % (k, v) stdscr.addstr(nrow, 20, info[:75] + (info[75:] and '..')) nrow += 1 else: stdscr.addstr( nrow, 20, '%s: %s' % (k, str({ i: v[i] for i in v if type(v[i]) is not bytearray and type(v[i]) is not np.ndarray }))) nrow += 1 stdscr.move(1, 15)