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
    action='store_true',
    default=False)
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")