示例#1
0
def main():
    parser = argparse.ArgumentParser(
        description='xvector-GMM for spoof detection')
    parser.add_argument('--train-txt',
                        required=True,
                        help='train xvector in txt')
    parser.add_argument('--eval-txt',
                        required=True,
                        help='eval xvector in txt')
    parser.add_argument('--logging-dir',
                        required=True,
                        help='log save directory')
    parser.add_argument('--suffix',
                        default='',
                        help='suffix for run name, not required')
    parser.add_argument('--model-dir',
                        default=None,
                        help='model save directory')
    args = parser.parse_args()

    # set up loggers
    run_name = "gmm-xvector" + time.strftime(
        "-%Y-%m-%d_%H_%M_%S") + args.suffix
    logger = setup_logs(args.logging_dir, run_name)

    np.random.seed(0)

    global_start = timer()
    # train
    gmm_genuine, gmm_spoof = train(args.train_txt, logger)

    if args.model_dir:
        save_name_g = os.path.join(args.model_dir, run_name + '-genuine.pkl')
        pickle.dump(gmm_genuine, open(save_name_g, 'wb'))
        save_name_s = os.path.join(args.model_dir, run_name + '-spoof.pkl')
        pickle.dump(gmm_spoof, open(save_name_s, 'wb'))

    # eval
    y_true, scores = pred(args.eval_txt, gmm_genuine, gmm_spoof, logger)

    eer = compute_eer(y_true, scores)
    logger.info("====>> Prediction EER: %s" % eer)

    global_end = timer()
    logger.info("#### Total elapsed time: %s" % (global_end - global_start))
示例#2
0
def main():
    parser = argparse.ArgumentParser(
        description='CQCC-GMM for spoof detection')
    parser.add_argument('--eval-dir', required=True, help='eval feature dir')
    parser.add_argument('--eval-utt2label',
                        required=True,
                        help='train utt2label')
    parser.add_argument('--logging-dir',
                        required=True,
                        help='log save directory')
    parser.add_argument('--suffix',
                        default='',
                        help='suffix for run name, not required')
    parser.add_argument('--model-genuine',
                        required=True,
                        help='pretrained genuine model file (pickle file)')
    parser.add_argument('--model-spoof',
                        required=True,
                        help='pretrained spoof model file (pickle file)')
    args = parser.parse_args()

    # set up loggers
    run_name = "gmm-cqcc" + time.strftime(
        "-%Y-%m-%d_%H_%M_%S") + "-pred_only" + args.suffix  # noqa
    logger = setup_logs(args.logging_dir, run_name)

    np.random.seed(0)

    global_start = timer()
    # load models
    logger.info("====> Loading pretrained models")
    gmm_genuine = load_model(args.model_genuine)
    gmm_spoof = load_model(args.model_spoof)

    # eval
    y_true, scores = pred(args.eval_dir, args.eval_utt2label, gmm_genuine,
                          gmm_spoof, logger)  # noqa

    eer = compute_eer(y_true, scores)
    logger.info("====>> Prediction EER: %s" % eer)

    global_end = timer()
    logger.info("#### Total elapsed time: %s" % (global_end - global_start))
示例#3
0
    if args.game not in ['atari', 'doom', 'picolmaze']:
        raise ValueError("Choose game between 'doom', 'atari' or 'picolmaze'.")

    if args.game == 'doom':
        args.max_episode_length = 2100
        args.max_episode_length_test = 2100
    elif args.game == 'picolmaze':
        args.max_episode_length = 500
        args.max_episode_length_test = 500
        args.num_stack = 3
    else:
        args.max_episode_length_test = 100
        args.num_stack = 1

    setup_logs(args)

    if args.random_seed:
        random_seed = torch.randint(0, 1000, (1, ))
        logging.info(f"Seed: {int(random_seed)}")
        torch.manual_seed(random_seed)
    else:
        torch.manual_seed(args.seed)

    if args.game == 'doom':
        env = create_doom_env(args.env_name,
                              0,
                              num_skip=args.num_skip,
                              num_stack=args.num_stack)
    elif args.game == 'atari':
        env = create_atari_env(args.env_name)
if __name__ == '__main__':
    # data splitting
    train_file_names = list(os.listdir(os.path.join(DATA_DIR, 'train-jpg')))
    train_labels_df = pd.read_csv(os.path.join(DATA_DIR, 'train_v2.csv'))
    train_IDs = [f.split('.')[0] for f in train_file_names]

    # K fold
    kf = KFold(n_splits=N_FOLDS, random_state=SEED, shuffle=True)

    for fold, (train_index, test_index) in enumerate(kf.split(train_IDs)):
        if not os.path.exists(os.path.join(MODEL_DIR, 'fold_%s' % (fold + 1))):
            os.makedirs(os.path.join(MODEL_DIR, 'fold_%s' % (fold + 1)))
        inner_train_IDs = [train_IDs[index] for index in train_index]
        val_IDs = [train_IDs[index] for index in test_index]
        partition = {'inner_train': inner_train_IDs, 'validation': val_IDs}
        # set up logs
        run_name = time.strftime("%Y-%m-%d_%H%M-") + "VGG19"
        logger = setup_logs(LOG_DIR, run_name)
        # train model
        with mlflow.start_run(run_name=run_name):
            mlflow.log_param('model', MODEL.name)
            mlflow.log_param('fold', (fold + 1))
            with open('/tmp/lr.txt', 'w') as f:
                f.write('Optimizer:\t %s\n' % BASE_OPTIMIZER)
                f.write('LR Group Factors:\t %s\n' % str(DIFF_LR_FACTORS))
            mlflow.log_artifact('/tmp/lr.txt')
            for key, value in vars(args).items():
                mlflow.log_param(key, value)
            main(MODEL, run_name, partition, args.batch_size, args.epochs,
                 fold + 1)
示例#5
0
文件: runner.py 项目: sjultra/mctv2
            output = err.output
            print(err.output)
            print("Test result: FAIL", "({0})".format(err.returncode))
        finally:
            with open(
                    os.path.join(test_dir, "{0}_result.log".format(test_name)),
                    'w') as log_file:
                log_file.write(output)


if __name__ == "__main__":
    os.system('clear')
    print("MCTv2")
    parameters = get_parameters()
    parameters = check_parameters(parameters)
    setup_logs(parameters.log_path, parameters.id, parameters.debug)

    config = Configuration()
    config.parse_config(parameters.config_path, parameters.secrets_path)
    config.resolve_custom_fields(parameters)
    config.replace_parameters(parameters)
    config.resolve_secrets()

    config_environment(config.content, parameters.terraform_workspace)

    provider = TerraformProvider(config.content,
                                 parameters.terraform_workspace)

    for step in config.content["steps"]:
        if step == "deploy":
            provider.deploy()
示例#6
0
def main():
    global_timer = timer()  # global timer
    logger = setup_logs(logging_dir, run_name)  # setup logs
    device = torch.device("cuda")
    model = Transposed().to(device)
    params = {'num_workers': 0, 'pin_memory': False}

    encoder = CDCK2(timestep, batch, audio_window).to(device)
    encoder.load_state_dict(torch.load(encoder_path)['state_dict'])
    encoder.eval()
    for param in encoder.encoder.parameters():
        param.requires_grad = False

    logger.info('===> loading train, validation and eval dataset')
    training_set = Dataset(train_raw, train_list, audio_window)
    validation_set = Dataset(validation_raw, validation_list, audio_window)
    train_loader = data.DataLoader(training_set,
                                   batch_size=batch,
                                   shuffle=True,
                                   **params)
    validation_loader = data.DataLoader(validation_set,
                                        batch_size=batch,
                                        shuffle=True,
                                        **params)

    optimizer = ScheduledOptim(
        optim.Adam(filter(lambda p: p.requires_grad, model.parameters()),
                   betas=(0.9, 0.98),
                   eps=1e-09,
                   weight_decay=1e-4,
                   amsgrad=True), n_warmup_steps)

    model_params = sum(p.numel() for p in model.parameters()
                       if p.requires_grad)
    logger.info('### Model summary below###\n {}\n'.format(str(model)))
    logger.info('===> Model total parameter: {}\n'.format(model_params))

    # Start training
    best_loss = np.inf
    best_epoch = -1

    for epoch in range(1, epochs + 1):
        epoch_timer = timer()
        train(log_interval, model, device, train_loader, optimizer, epoch,
              encoder)
        val_acc, val_loss = validation(model, device, validation_loader,
                                       encoder)

        # Save
        if val_loss < best_loss:
            best_loss = min(val_loss, best_loss)
            snapshot(
                logging_dir, run_name, {
                    'epoch': epoch + 1,
                    'validation_acc': val_acc,
                    'state_dict': model.state_dict(),
                    'validation_loss': val_loss,
                    'optimizer': optimizer.state_dict(),
                })
            best_epoch = epoch + 1
        elif epoch - best_epoch > 2:
            optimizer.increase_delta()
            best_epoch = epoch + 1

        end_epoch_timer = timer()
        logger.info("#### End epoch {}/{}, elapsed time: {}".format(
            epoch, epochs, end_epoch_timer - epoch_timer))

    # End
    end_global_timer = timer()
    logger.info("################## Success #########################")
    logger.info("Total elapsed time: %s" % (end_global_timer - global_timer))