def test_scene(dump_file, test_cnt): config = Configuration() scene = os.path.basename(dump_file).split('.')[0] if scene not in TASK_LIST: env = THORDiscreteEnvironment({ 'h5_file_path': dump_file, }) task_list = np.random.choice(list(range(env.n_locations)), test_cnt) else: task_list = TASK_LIST[scene] logging.info( "testing scene %(scene)s task_list=%(task_list)s from dump file %(dump_file)s" % locals()) for t in task_list: target = int(t) env = THORDiscreteEnvironment({ 'h5_file_path': dump_file, 'terminal_state_id': target, }) start = time.time() expert = Expert(env) logging.debug("building policy takes %f s" % (time.time() - start)) assert expert.verify_distance_matrix() for _ in range(test_cnt): env.reset() logging.debug("scene=%s target=%d source=%d" % (scene, target, env.current_state_id)) steps = [] orig_state = env.current_state_id while not env.terminal: a = expert.get_next_action() logging.debug("state=%d action=%d" % (env.current_state_id, a)) env.step(a) steps.append((env.current_state_id, a)) assert len( steps ) < config.max_steps_per_e, "current steps is beyond max_steps_per_e" logging.debug( str(orig_state) + ''.join([expert.get_a_str(a) + str(s) for (s, a) in steps])) assert len( steps) == env.shortest_path_distances[orig_state][target]
viewer.imshow(env.observation) if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument("-s", "--scene_dump", type=str, default="./data/bedroom_04.h5", help="path to a hdf5 scene dump file") args = parser.parse_args() print("Loading scene dump {}".format(args.scene_dump)) env = THORDiscreteEnvironment({'h5_file_path': args.scene_dump}) # manually disable terminal states env.terminals = np.zeros_like(env.terminals) env.terminal_states, = np.where(env.terminals) env.reset() human_agent_action = None human_wants_restart = False stop_requested = False viewer = SimpleImageViewer() viewer.imshow(env.observation) viewer.window.on_key_press = key_press print("Use arrow keys to move the agent.")
parser.add_argument( "-a", "--action", type=str, help="specify a sequence of action the agent should take") parser.add_argument("--start", type=int, help="initial location of the agent") parser.add_argument("--save-dir", type=str, help="directory to which image at each state is saved") args = parser.parse_args() print("Loading scene dump {}".format(args.scene_dump)) env = THORDiscreteEnvironment({ 'h5_file_path': args.scene_dump, 'initial_state': args.start, }) # manually disable terminal states env.terminals = np.zeros_like(env.terminals) env.terminal_states, = np.where(env.terminals) env.reset() human_agent_action = None human_wants_restart = False stop_requested = False action_list = [int(i) for i in args.action.split(',')] if args.action else None action_idx = 0 save_img = None
help="path to a hdf5 scene dump file") args = parser.parse_args() print("Loading scene dump {}".format(args.scene_dump)) # env = THORDiscreteEnvironment({ # 'h5_file_path': args.scene_dump # }) # # # manually disable terminal states # env.terminals = np.zeros_like(env.terminals) # env.terminal_states, = np.where(env.terminals) # env.reset() env = THORDiscreteEnvironment({ 'scene_name': 'living_room_08', 'terminal_state_id': 26 }) env.reset() human_agent_action = None human_wants_restart = False stop_requested = False viewer = SimpleImageViewer() viewer.imshow(env.observation) viewer.window.on_key_press = key_press print("Use arrow keys to move the agent.") print("Press R to reset agent\'s location.") print("Press Q to quit.")