コード例 #1
0
def test_load_save():

    scr1 = create_scores()[0]
    scr1.sort()

    file_h5 = output_dir + '/test.h5'
    scr1.save(file_h5)
    scr2 = TrialScores.load(file_h5)
    assert (scr1 == scr2)

    file_txt = output_dir + '/test.txt'
    scr1.score_mask[:, :] = False
    scr1.score_mask[0, :] = True
    scr1.score_mask[:, 0] = True
    scr1.scores[scr1.score_mask == False] = 0
    scr1.save(file_txt)
    scr2 = TrialScores.load(file_txt)

    assert (scr1 == scr2)
コード例 #2
0
def eval_2class_performance(score_file, key_file, output_path):

    scr = TrialScores.load(score_file)
    key = TrialKey.load(key_file)

    output_dir = os.path.dirname(output_path)
    if not (os.path.isdir(output_dir)):
        os.makedirs(output_dir, exist_ok=True)

    tar, non = scr.get_tar_non(key)
    eer = compute_eer(tar, non)

    output_file = output_path + '.res'
    with open(output_file, 'w') as f:
        f.write('EER %.4f\nNTAR %d\nNNON %d\n' % (eer, len(tar), len(non)))
コード例 #3
0
def convert(input_file, output_file, test_list, class_file, add_ext):

    scores = TrialScores.load(input_file)

    if test_list is None:
        seg_set = scores.seg_set
    else:
        with open(test_list, 'r') as f:
            seg_set = [
                seg for seg in [line.rstrip().split(' ')[0] for line in f]
                if seg != 'segmentid'
            ]
            if add_ext:
                exts = [os.path.splitext(seg)[1] for seg in seg_set]
                seg_set = [os.path.splitext(seg)[0] for seg in seg_set]

    if class_file is None:
        model_set = scores.model_set
    else:
        with open(class_file, 'r') as f:
            model_set = [line.rstrip().split()[0] for line in f]

    ndx = TrialNdx(model_set, seg_set)
    scores = scores.set_missing_to_value(ndx, -100)

    if add_ext:
        scores.seg_set = [seg + ext for seg, ext in zip(scores.seg_set, exts)]

    with open(output_file, 'w') as f:
        f.write('segmentid\t')
        for model in scores.model_set[:-1]:
            f.write('%s\t' % model)
        f.write('%s\n' % scores.model_set[-1])
        for i in xrange(scores.scores.shape[1]):
            f.write('%s\t' % scores.seg_set[i])
            for j in xrange(scores.scores.shape[0] - 1):
                f.write('%f\t' % scores.scores[j, i])
            f.write('%f\n' % scores.scores[-1, i])