示例#1
0
def test_preprocessing():
    # make arguments
    args = make_args()

    # prepare dummy wav files
    wavdir = "data/wav"
    if not os.path.exists(wavdir):
        os.makedirs(wavdir)
    for i in range(5):
        make_dummy_wav(wavdir + "/%d.wav" % i, 8000, args.fs)

    # feature extract
    wav_list = find_files(wavdir, "*.wav")
    if not os.path.exists(args.wavdir):
        os.makedirs(args.wavdir)
    world_feature_extract(wav_list, args)

    # calc_stats
    file_list = find_files(args.hdf5dir, "*.h5")
    calc_stats(file_list, args)

    # noise shaping
    wav_list = find_files(args.wavdir, "*.wav")
    if not os.path.exists(args.writedir):
        os.makedirs(args.writedir)
    noise_shaping(wav_list, args)

    # assert list length
    wav_ns_list = find_files(args.writedir, "*.wav")
    assert len(wav_list) == len(file_list)
    assert len(wav_list) == len(wav_ns_list)
示例#2
0
def test_preprocessing():
    # make arguments
    args = make_args()

    # prepare dummy wav files
    wavdir = "data/wav"
    if not os.path.exists(wavdir):
        os.makedirs(wavdir)
    for i in range(5):
        make_dummy_wav(wavdir + "/%d.wav" % i, 8000, args.fs)

    # feature extract
    wav_list = find_files(wavdir, "*.wav")
    if not os.path.exists(args.wavdir):
        os.makedirs(args.wavdir)
    args.feature_type = "world"
    world_feature_extract(wav_list, args)
    args.feature_type = "melspc"
    melspectrogram_extract(wav_list, args)
    args.feature_type = "mcep"
    melcepstrum_extract(wav_list, args)

    # calc_stats
    file_list = find_files(args.hdf5dir, "*.h5")
    args.feature_type = "world"
    calc_stats(file_list, args)
    args.feature_type = "melspc"
    calc_stats(file_list, args)
    args.feature_type = "mcep"
    calc_stats(file_list, args)

    # noise shaping
    wav_list = find_files(args.wavdir, "*.wav")
    args.feature_type = "world"
    args.writedir = "data/wav_ns/world"
    if not os.path.exists(args.writedir):
        os.makedirs(args.writedir)
    world_noise_shaping(wav_list, args)
    args.feature_type = "mcep"
    args.writedir = "data/wav_ns/mcep"
    if not os.path.exists(args.writedir):
        os.makedirs(args.writedir)
    melcepstrum_noise_shaping(wav_list, args)
示例#3
0
def main():
    parser = argparse.ArgumentParser(
        description='Run storage task net experiments.')
    parser.add_argument('--save',
                        type=str,
                        metavar='save-folder',
                        help='prefix to add to save path')
    parser.add_argument('--nRuns',
                        type=int,
                        default=10,
                        metavar='runs',
                        help='number of runs')
    parser.add_argument('--paramSet',
                        type=int,
                        choices=range(4),
                        default=0,
                        metavar='hyperparams',
                        help='(lambda, epsilon) in given row of Table 1')
    args = parser.parse_args()


    save_folder_main = 'params{}'.format(args.paramSet) if args.save is None \
        else '{}-params{}'.format(args.save, args.paramSet)
    save_folder_main = os.path.join('results', save_folder_main)

    setproctitle.setproctitle('storage-{}'.format(args.paramSet))

    # Initialize problem parameters
    params = init_params(args.paramSet)

    bsz = 500

    # Train, test split
    train_frac = 0.8

    input_tensors = get_train_test_split(params, train_frac)
    loaders = get_loaders_tt(input_tensors, bsz)

    if not os.path.exists(save_folder_main):
        os.makedirs(save_folder_main)

    for run in range(args.nRuns):

        save_folder = os.path.join(save_folder_main, str(run))
        if not os.path.exists(save_folder):
            os.makedirs(save_folder)

        # Randomly construct hold-out set for task net training.
        tensors_task = get_train_hold_split(input_tensors, 0.8, save_folder)
        loaders_task = get_loaders_tth(tensors_task, bsz)

        # Run and eval rmse-minimizing net
        model_rmse = model_classes.Net(tensors_task['X_train'],
                                       tensors_task['Y_train'], [200, 200],
                                       params['T'])
        if USE_GPU:
            model_rmse = model_rmse.cuda()
        model_rmse = nets.run_rmse_net(model_rmse, loaders_task, params,
                                       tensors_task)
        nets.eval_net('rmse_net', model_rmse, loaders_task, params,
                      save_folder)

        # Run and eval task-minimizing net
        model_task = model_classes.Net(tensors_task['X_train'],
                                       tensors_task['Y_train'], [200, 200],
                                       params['T'])
        if USE_GPU:
            model_task = model_task.cuda()
        model_task = nets.run_rmse_net(model_task, loaders_task, params,
                                       tensors_task)  # seed with rmse soln
        model_task = \
            nets.run_task_net(model_task, loaders_task, params, args, tensors_task)
        nets.eval_net('task_net', model_task, loaders_task, params,
                      save_folder)

    calc_stats.calc_stats(
        map(lambda x: os.path.join(save_folder_main, str(x)),
            range(args.nRuns)), save_folder_main)