Exemplo n.º 1
0
def split_data_by_s5(src_dir,
                     des_dir,
                     keywords=['train_si284', 'test_eval92', 'test_dev93']):
    count = 0
    for key in keywords:
        wav_file_list = os.path.join(src_dir, key + '.flist')
        label_file_list = os.path.join(src_dir, key + '.txt')
        new_path = check_path_exists(os.path.join(des_dir, key))

        with open(wav_file_list, 'r') as wfl:
            wfl_contents = wfl.readlines()
            for line in wfl_contents:
                line = line.strip()
                if os.path.isfile(line):
                    shutil.copyfile(
                        line, os.path.join(des_dir, key,
                                           line.split('/')[-1]))
                    print(line)
                else:
                    tmp = '/'.join(
                        line.split('/')[:-1] + [line.split('/')[-1].upper()])
                    shutil.copyfile(
                        tmp,
                        os.path.join(des_dir, key,
                                     line.split('/')[-1].replace('WV1',
                                                                 'wv1')))
                    print(tmp)

        with open(label_file_list, 'r') as lfl:
            lfl_contents = lfl.readlines()
            for line in lfl_contents:
                label = ' '.join(line.strip().split(' ')[1:])
                with open(
                        os.path.join(des_dir, key,
                                     line.strip().split(' ')[0] + '.label'),
                        'w') as lf:
                    lf.writelines(label)
                print(key, label)
optimizer_fn = optimizer_functions_dict[FLAGS.optimizer]

batch_size = FLAGS.batch_size
num_hidden = FLAGS.num_hidden
num_feature = FLAGS.num_feature
num_classes = get_num_classes(level)
num_epochs = FLAGS.num_epochs
lr = FLAGS.lr
grad_clip = FLAGS.grad_clip
datadir = FLAGS.datadir

logdir = FLAGS.logdir
savedir = os.path.join(logdir, level, 'save')
resultdir = os.path.join(logdir, level, 'result')
loggingdir = os.path.join(logdir, level, 'logging')
check_path_exists([logdir, savedir, resultdir, loggingdir])

mode = FLAGS.mode
keep = FLAGS.keep
keep_prob = 1 - FLAGS.dropout_prob

print('%s mode...' % str(mode))
if mode == 'test':
    batch_size = 100
    num_epochs = 1

train_mfcc_dir = os.path.join(datadir, level, 'train', 'mfcc')
train_label_dir = os.path.join(datadir, level, 'train', 'label')
test_mfcc_dir = os.path.join(datadir, level, 'test', 'mfcc')
test_label_dir = os.path.join(datadir, level, 'test', 'label')
logfile = os.path.join(