Esempio n. 1
0
def get_params(args):
    params_manager = ParamsManager()
    agent_params = params_manager.get_agent_params()
    env_params = params_manager.get_env_params(args.env_params.lower())
    env_params['env_name'] = args.env_name

    custom_region_available = False
    for key, value in env_params['useful_region'].items():
        if key in env_params['env_name']:
            env_params['useful_region'] = value
            custom_region_available = True
            break
    if custom_region_available is not True:
        env_params['useful_region'] = env_params['useful_region']['Default']

    return agent_params, env_params
parser.add_argument(
    "--test",
    help="Tests a saved Agent model to see the performance. Disables learning",
    action='store_true',
    default=False)
parser.add_argument("--gpu-id",
                    help="GPU device ID to use. Default:0",
                    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
Esempio n. 3
0
    action="store_true",
    default=False)
args.add_argument(
    "--record",
    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:
    "--params-file",
    help="Path to the parameters json file. Default is parameters.json",
    default="parameters.json",
    type=str,
    metavar="PFILE")
args.add_argument(
    "--env-name",
    help=
    "ID of the Atari environment available in OpenAI Gym. Default is Pong-v0",
    default="Pong-v0",
    type=str,
    metavar="ENV")
args = args.parse_args()

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_name + "_" + 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")
global_step_num = 0
use_cuda = params_manager.get_agent_params()['use_cuda']
# new in PyTorch 0.4
device = torch.device(
    "cuda" if torch.cuda.is_available() and use_cuda else "cpu")
torch.manual_seed(seed)
Esempio n. 5
0
    help=
    "Modo de testing para jugar sin aprender. Por defecto está desactivado",
    action="store_true",
    default=False)
args.add_argument(
    "--output-dir",
    help=
    " Directorio para almacenar los output. Por defecto = ./trained_models/results",
    default="./trained_models/results")
args = args.parse_args()

# Parámetros globales
manager = ParamsManager(args.params_file)

# Ficheros de logs acerca de la configuración de las ejecuciones
summary_filename_prefix = manager.get_agent_params()["summary_filename_prefix"]
summary_filename = summary_filename_prefix + args.rom + datetime.now(
).strftime("%y-%m-%d-%H-%M-%S")

# Exportación de la configuración del agente y el emulador durante cada ejecución
#manager.export_agent_params(summary_filename + "/" + "agent_params.json")
#manager.export_emulator_params(summary_filename + "/" + "emu_params.json")

# Contador global de las ejecuciones
global_step_num = 0

# Habilitar la semilla aleatoria para poder reproducir el experimento a posteriori
seed = manager.get_agent_params()["seed"]
torch.manual_seed(seed)
np.random.seed(seed)
Esempio n. 6
0
    default=False)
args.add_argument(
    "--record",
    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()

# Parametros globales
manager = ParamsManager(args.params_file)
agent_params = manager.get_agent_params()
global_step_num = 0

#Fichero del log
summary_filename_prefix = agent_params['summary_filename_prefix']
summary_filename = summary_filename_prefix + args.env + datetime.now(
).strftime("%y-%m-%d-%H-%M")

# Sumary writter de TBX
writer = SummaryWriter(summary_filename)

manager.export_agent_params(summary_filename + "/" + "agent_params.json")
manager.export_env_params(summary_filename + "/" + "env_params.json")

# Habilitar entranamiento por GPU
use_cuda = agent_params['use_cuda']