forked from joytsay/frvt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
validate.py
75 lines (71 loc) · 3.11 KB
/
validate.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
67
68
69
70
71
72
73
74
75
import os
import numpy as np
import io
import shutil
def load_index_lists(data_dir,file_name):
with open(os.path.join(data_dir,file_name),"r") as f:
lines = f.readlines()
lines = [l.strip('\n') for l in lines]
imgPath = ([l.strip().split(' ')[1] for l in lines])
imgPath.pop(0)
imgName = ([p.strip().split('/')[3] for p in imgPath])
noExtImgName = [n.strip(".ppm") for n in imgName]
enrollId = ([n.strip().split('-')[0] for n in noExtImgName])
return enrollId, imgName
def load_score_lists(data_dir,file_name):
with open(os.path.join(data_dir,file_name),"r") as f:
lines = f.readlines()
lines = [l.strip('\n') for l in lines]
score = ([l.strip().split(' ')[2] for l in lines])
score.pop(0)
return score
def main():
try:
mode=int(input('Give FR confidence threshold: '))
except ValueError:
print ("Not a int number")
FRconfidence = float(mode*0.01)
knownToUnknown = 0
unknownToKnown = 0
Known = 0
Unknown = 0
FR_data_dir = "11/validation"
FR_img_dir = "common/images"
FAR_dir = "11/FAR"
FRR_dir = "11/FRR"
enrollId, enrollImg= load_index_lists(FR_data_dir,"enroll.log")
verifId, verifImg = load_index_lists(FR_data_dir,"verif.log")
matchScore = load_score_lists(FR_data_dir, "match.log")
for i, score in enumerate(matchScore):
if float(score) >= FRconfidence:
if enrollId[i] == verifId[i]:
Known += 1
else:
unknownToKnown += 1
enrollDestFileName = str(unknownToKnown) + "_enrollLine(" + str(i+2) + ")_score(" + str(score) + ")_" + enrollImg[i]
shutil.copy(os.path.join(FR_img_dir,enrollImg[i]),
os.path.join(FAR_dir,enrollDestFileName))
verifDestFileName = str(unknownToKnown) + "_verifLine(" + str(i+2) + ")_score(" + str(score) + ")_" + verifImg[i]
shutil.copy(os.path.join(FR_img_dir,verifImg[i]),
os.path.join(FAR_dir,verifDestFileName))
else:
if enrollId[i] != verifId[i]:
Unknown += 1
else:
knownToUnknown += 1
enrollDestFileName = str(knownToUnknown) + "_enrollLine(" + str(i+2) + ")_score(" + str(score) + ")_" + enrollImg[i]
shutil.copy(os.path.join(FR_img_dir,enrollImg[i]),
os.path.join(FRR_dir,enrollDestFileName))
verifDestFileName = str(knownToUnknown) + "_verifLine(" + str(i+2) + ")_score(" + str(score) + ")_" + verifImg[i]
shutil.copy(os.path.join(FR_img_dir,verifImg[i]),
os.path.join(FRR_dir,verifDestFileName))
print("\n[SUCCESS] NIST frvt validation for confidence: ",FRconfidence,
"\nAll count: ", len(matchScore),
"\nKnown: ", Known,
"\nUnknown: ", Unknown,
"\nknownToUnknown: ", knownToUnknown,
"\nunknownToKnown", unknownToKnown,
"\nFAR: ", unknownToKnown/len(matchScore)*100,
"%\nFRR: ", knownToUnknown/len(matchScore)*100,"%\n")
if __name__ == "__main__":
main()