help="Almacena videos y estados de la performance del agente", action="store_true", default=False) args.add_argument( "--output-dir", help= "Directorio para almacenar los outputs. Por defecto = ./trained_models/results", default="./trained_models/results") args = args.parse_args() manager = ParamsManager(args.params_file) summary_filename_prefix = manager.get_agent_params()['summary_filename_prefix'] summary_filename = summary_filename_prefix + args.env + datetime.now( ).strftime("%y-%m-%d-%H-%M") writer = SummaryWriter(summary_filename) manager.export_agent_params(summary_filename + "/" + "agent_params.json") manager.export_environment_params(summary_filename + "/" + "environment_params.json") global_step_num = 0 use_cuda = manager.get_agent_params()['use_cuda'] device = torch.device( "cuda:" + str(args.gpu_id) if torch.cuda.is_available() and use_cuda else "cpu") seed = manager.get_agent_params()['seed'] torch.manual_seed(seed) np.random.seed(seed) if torch.cuda.is_available() and use_cuda: torch.cuda.manual_seed_all(seed) class DeepQLearner(object):
type=int, default=0, metavar="GPU_ID") args = parser.parse_args() global_step_num = 0 params_manager = ParamsManager(args.params_file) agent_algo = "A2C" summary_file_path_prefix = params_manager.get_agent_params( )['summary_file_path_prefix'] summary_file_path = summary_file_path_prefix + agent_algo + '_' + args.env + "_" + datetime.now( ).strftime("%y-%m-%d-%H-%M") writer = SummaryWriter(summary_file_path) # Export the parameters as json files to the log directory to keep track of the parameters used in each experiment params_manager.export_env_params(summary_file_path + "/" + "env_params.json") params_manager.export_agent_params(summary_file_path + "/" + "agent_params.json") use_cuda = params_manager.get_agent_params()['use_cuda'] # Introduced in PyTorch 0.4 device = torch.device( "cuda:" + str(args.gpu_id) if torch.cuda.is_available() and use_cuda else "cpu") seed = params_manager.get_agent_params()[ 'seed'] # With the intent to make the results reproducible torch.manual_seed(seed) np.random.seed(seed) if torch.cuda.is_available() and use_cuda: torch.cuda.manual_seed_all(seed) Transition = namedtuple("Transition", ["s", "value_s", "a", "log_prob_a"])
# Parameter Manager params_manager = ParamsManager(args.params_file) seed = params_manager.get_agent_params()['seed'] summary_file_path_prefix = params_manager.get_agent_params( )['summary_file_path_prefix'] summary_file_path = summary_file_path_prefix + args.env + \ '_' + datetime.now().strftime('%y-%m-%d-%H-%M') if not exists(summary_file_path): makedirs(summary_file_path) writer = SummaryWriter(summary_file_path) params_manager.export_env_params(join(summary_file_path, 'env_params.json')) params_manager.export_agent_params(join(summary_file_path, 'agent_params.json')) global_step_num = 0 # GPU Setting use_cuda = params_manager.get_agent_params()['use_cuda'] device = torch.device( 'cuda:' + str(args.gpu_id) if torch.cuda.is_available() and use_cuda else 'cpu') torch.manual_seed(seed) np.random.seed(seed) if torch.cuda.is_available() and use_cuda: torch.cuda.manual_seed_all(seed) if __name__ == "__main__": env_conf = params_manager.get_env_params()