예제 #1
0
        configs.append(parser.parse_args())
    return configs


if __name__ == "__main__":

    experiments = argparse.ArgumentParser()
    experiments.add_argument('--config_path',
                             default='experiments.json',
                             type=str,
                             help='Path of experiments config file')
    experiments = experiments.parse_args()

    from utils.Pytorch_GPUManager import GPUManager

    index = GPUManager().auto_choice()
    device = torch.device("cuda:" +
                          str(index) if torch.cuda.is_available() else "cpu")
    exp_configs = parse_experiments(experiments.config_path)
    n = 5
    for config in exp_configs:
        logger.info('-' * 80)
        logger.info('Config {} (totally {} configs)'.format(
            exp_configs.index(config) + 1, len(exp_configs)))
        results = []
        max_apc_test_acc, max_apc_test_f1, max_ate_test_f1 = 0, 0, 0
        for i in range(n):
            config.device = device
            config.seed = i + 1
            logger.info('No.{} training process of {}'.format(i + 1, n))
            apc_test_acc, apc_test_f1, ate_test_f1 = main(config)
예제 #2
0
        mean_test_acc_overall = temp_test_acc_overall / (t + 1)
        mean_f1_overall = temp_f1_overall / (t + 1)
        logging.info('max_acc_overall:{}  f1_overall:{}'.format(round(max_acc_overall, 2), round(max_f1_overall, 2)))
        logging.info("mean_acc_overall:{}  mean_f1_overall:{}".format(round(mean_test_acc_overall, 2),
                                                                      round(mean_f1_overall, 2)))
        logging.info("#" * 100)
    return mean_test_acc_overall, mean_f1_overall


if __name__ == '__main__':

    config_parser = argparse.ArgumentParser()
    config_parser.add_argument('--config', default='experiments_apc.json',
                        help='path of the experiments configuration', type=str)

    args = config_parser.parse_args()

    configs = parse_experiments(args.config)
    log_file = 'logs/{}.{}.log'.format(args.config, strftime("%y%m%d.%H%M", localtime()))
    logger.addHandler(logging.FileHandler(log_file))

    from utils.Pytorch_GPUManager import GPUManager

    GM = GPUManager()
    gpu = GM.auto_choice()

    for config in configs:
        config.device = 'cuda:' + str(gpu)
        # config.device = 'cpu'  # Uncomment this line to use CPU
        multi_train(config=config, n=config.repeat)