def play(): _vzd_path = os.path.dirname(vizdoom.__file__) parser = argparse.ArgumentParser(description='Doom Network') parser.add_argument('--action_set', default='noset', help='model to work with') parser.add_argument('--doom_instance', default='map', choices=('basic', 'cig', 'map'), help='doom instance type') parser.add_argument('--vizdoom_config', default='../environments/cig_test.cfg', help='vizdoom config path') parser.add_argument('--vizdoom_path', default=_vzd_path, help='path to vizdoom') parser.add_argument('--wad_path', default=_vzd_path + '/freedoom2.wad', help='wad file path') parser.add_argument('--skiprate', type=int, default=1, help='number of skipped frames') parser.add_argument('--frame_num', type=int, default=1, help='number of frames per input') parser.add_argument('--checkpoint_file', default=None, help='check point file name') parser.add_argument('--checkpoint_rate', type=int, default=500, help='number of batches per checkpoit') parser.add_argument('--bot_cmd', default=None, help='command to launch a bot') parser.add_argument('--h5_path', default=None, help='hd5 files path') args = parser.parse_args() print(args) init_doom_env(args) game = args.instance_class(args.vizdoom_config, args.wad_path, args.skiprate, visible=True, mode=vizdoom.Mode.PLAYER, actions=args.action_set) step_state = game.get_state_normalized() for i in range(50): step_state, _, finished = game.step_normalized([0, 0, 0, 0]) pose = game.get_pose() state = game.get_state_normalized() objects = game.get_objects(state) sim = Simulator(pose, objects) k = 1
default=_vzd_path, help='path to vizdoom') parser.add_argument('--wad_path', default=_vzd_path + '/doom2.wad', help='wad file path') parser.add_argument('--skiprate', type=int, default=1, help='number of skipped frames') parser.add_argument('--frame_num', type=int, default=4, help='number of frames per input') args = parser.parse_args() print(args) init_doom_env(args) torch.set_default_tensor_type('torch.FloatTensor') torch.manual_seed(args.seed) if USE_CUDA: torch.cuda.manual_seed_all(args.seed) model_class = { 'aac': AdvantageActorCritic, 'aac_lstm': AdvantageActorCriticLSTM, 'aac_intrinsic': AdvantageActorCriticIntrinsic, 'aac_duel': AdvantageActorCriticDuel } model = model_class[args.model](args) if args.load is not None and os.path.isfile(args.load):
parser.add_argument('--epoch_game_steps', type=int, default=10000, help='number of steps per epoch') parser.add_argument('--episode_discount', type=float, default=0.95, help='number of episodes for training') parser.add_argument('--seed', type=int, default=1, help='seed value') parser.add_argument( '--model', default='aac', choices=('aac', 'aac_lstm', 'aac_noisy', 'aac_depth', 'aac_map', 'mb_map'), help='model to work with') parser.add_argument('--base_model', default=None, help='path to base model file') parser.add_argument('--action_set', default=None, help='model to work with') parser.add_argument('--load', default=None, help='path to model file') parser.add_argument('--vizdoom_config', default='environments/basic.cfg', help='vizdoom config path') parser.add_argument('--vizdoom_path', default=_vzd_path, help='path to vizdoom') parser.add_argument('--wad_path', default=_vzd_path + '/freedoom2.wad', help='wad file path') parser.add_argument('--skiprate', type=int, default=1, help='number of skipped frames') parser.add_argument('--frame_num', type=int, default=1, help='number of frames per input') parser.add_argument('--checkpoint_file', default=None, help='check point file name') parser.add_argument('--checkpoint_rate', type=int, default=500, help='number of batches per checkpoit') parser.add_argument('--bot_cmd', default=None, help='command to launch a bot') parser.add_argument('--h5_path', default=None, help='hd5 files path') args = parser.parse_args() print(args) init_doom_env(args) model = get_model(args) if args.mode == 'train': model.run_train(args) else: model.run_test(args)
def main(_config): """ Main script which for running a non-stationary doom environments composed of multiple maps. """ # Setting logger log = ex.logger log.setLevel(_config['log_level'].upper()) # Printing the conf for visual check log.debug( 'Exp. configurations:\n' '----------------------------------------------------------------\n' + pprint.pformat(_config) + '\n' + '----------------------------------------------------------------\n' ) init_doom_env(_config) random.seed(_config['seed']) np.random.seed(_config['seed']) model = get_model(_config) if _config['mode'] == 'train': test_crew = [[] for j in range(_config['num_runs'])] test_std = [[] for j in range(_config['num_runs'])] runs_avg_crew = [[[] for i in range(len(_config['vizdoom_maps']))] for j in range(len(_config['vizdoom_maps']))] # train with multiple runs for run_id in range(_config['num_runs']): ex.info[str(run_id)] = {'test_crew': [], 'test_std': []} print("\n------------------ RUN {0} -------------------" .format(run_id)) for task_id in range(len(_config['vizdoom_maps'])): crew, std, movavg_stats = model.run_train(task_id=task_id) test_crew[run_id].append(crew[-1]) test_std[run_id].append(std[-1]) # save results into mongodb ex.info[str(run_id)]['test_crew'].append(crew[-1]) ex.info[str(run_id)]['test_std'].append(std[-1]) ex.info[str(run_id)]['mov_avg_stats'] = movavg_stats ex.info[str(run_id)]['tot_crew'] = crew ex.info[str(run_id)]['tot_std'] = std # prepare for next run del model model = get_model(_config) # printing results print( '----------------------------------------------------------------\n' ' RESULTS\n' + '----------------------------------------------------------------\n' ) for run_id in range(_config['num_runs']): print("\n------------------ RUN {0} -------------------" .format(run_id)) for task_id in range(len(_config['vizdoom_maps'])): avg_crew = 0 avg_std = 0 for map_id in range(len(_config['vizdoom_maps'])): # print(test_crew[run_id][task_id]) # print(test_std[run_id][task_id]) print( "[run %d], [task: %d], [map: %d], " "[avg. cumulated reward: %f.2f], " "[dev.std: %.2f]" % (run_id, task_id, map_id, test_crew[run_id][task_id][map_id], test_std[run_id][task_id][map_id]) ) avg_crew += test_crew[run_id][task_id][map_id] avg_std += test_std[run_id][task_id][map_id] runs_avg_crew[task_id][map_id].append( test_crew[run_id][task_id][map_id] ) avg_crew /= len(_config['vizdoom_maps']) avg_std /= len(_config['vizdoom_maps']) print("[run %d] [avg_maps_crew %.3f], [avg_maps_std %.3f]\n" % (run_id, avg_crew, avg_std)) print( '----------------------------------------------------------------\n' ' AVG RUNS RESULTS\n' + '----------------------------------------------------------------\n' ) for task_id in range(len(_config['vizdoom_maps'])): tot_avg_crew = [] for map_id in range(len(_config['vizdoom_maps'])): print("[task %d], [map: %d], [runs avg_crew %.3f]," " [runs std %.3f]" % (task_id, map_id, float(np.mean(runs_avg_crew[task_id][map_id])), float(np.std(runs_avg_crew[task_id][map_id])))) tot_avg_crew.append(np.mean(runs_avg_crew[task_id][map_id])) print("[avg_runs_maps_crew %.3f], [std %.3f]\n" % (float(np.mean(tot_avg_crew)), float(np.std(tot_avg_crew)))) else: # we assume to have a list in load for test res = {} for model_path in _config['load']: res[model_path] = [] for task_id in range(len(_config['vizdoom_maps'])): crew, std = model.run_test( num_test_ep=_config['num_test_ep'], load=model_path, seed=_config['seed'], task_id=task_id) res[model_path].append((crew, std)) res = OrderedDict(sorted(res.items(), key=lambda t: t[0])) for model_name, vec in res.items(): avg_crew = 0 avg_std = 0 for i, (crew, std) in enumerate(vec): print( "[name %s], [map: %d], [avg. cumulated reward: %f.2f]," "[dev.std: %.2f]" % (model_name, i, crew, std) ) avg_crew += crew avg_std += std avg_crew /= len(res[model_name]) avg_std /= len(res[model_name]) print("[avg_crew %.3f], [avg_std %.3f]\n" % (avg_crew, avg_std))