forked from TakHemlata/SSL_Anti-spoofing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevaluate_2021_DF.py
66 lines (52 loc) · 2.23 KB
/
evaluate_2021_DF.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python
"""
Script to compute pooled EER for ASVspoof2021 DF.
Usage:
$: python PATH_TO_SCORE_FILE PATH_TO_GROUDTRUTH_DIR phase
-PATH_TO_SCORE_FILE: path to the score file
-PATH_TO_GROUNDTRUTH_DIR: path to the directory that has the CM protocol.
Please follow README, download the key files, and use ./keys
-phase: either progress, eval, or hidden_track
Example:
$: python evaluate.py score.txt ./keys eval
"""
import sys, os.path
import numpy as np
import pandas
import eval_metrics_DF as em
from glob import glob
if len(sys.argv) != 4:
print("CHECK: invalid input arguments. Please read the instruction below:")
print(__doc__)
exit(1)
submit_file = sys.argv[1]
truth_dir = sys.argv[2]
phase = sys.argv[3]
cm_key_file = os.path.join(truth_dir, 'CM/trial_metadata.txt')
def eval_to_score_file(score_file, cm_key_file):
cm_data = pandas.read_csv(cm_key_file, sep=' ', header=None)
submission_scores = pandas.read_csv(score_file, sep=' ', header=None, skipinitialspace=True)
if len(submission_scores) != len(cm_data):
print('CHECK: submission has %d of %d expected trials.' % (len(submission_scores), len(cm_data)))
exit(1)
if len(submission_scores.columns) > 2:
print('CHECK: submission has more columns (%d) than expected (2). Check for leading/ending blank spaces.' % len(submission_scores.columns))
exit(1)
cm_scores = submission_scores.merge(cm_data[cm_data[7] == phase], left_on=0, right_on=1, how='inner') # check here for progress vs eval set
bona_cm = cm_scores[cm_scores[5] == 'bonafide']['1_x'].values
spoof_cm = cm_scores[cm_scores[5] == 'spoof']['1_x'].values
eer_cm = em.compute_eer(bona_cm, spoof_cm)[0]
out_data = "eer: %.2f\n" % (100*eer_cm)
print(out_data)
return eer_cm
if __name__ == "__main__":
if not os.path.isfile(submit_file):
print("%s doesn't exist" % (submit_file))
exit(1)
if not os.path.isdir(truth_dir):
print("%s doesn't exist" % (truth_dir))
exit(1)
if phase != 'progress' and phase != 'eval' and phase != 'hidden_track':
print("phase must be either progress, eval, or hidden_track")
exit(1)
_ = eval_to_score_file(submit_file, cm_key_file)