-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathaggregate.py
74 lines (68 loc) · 2.67 KB
/
aggregate.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
import argparse
parser = argparse.ArgumentParser(description='Aggregate data from evaluated images')
parser.add_argument('-a', '--arch', metavar='ARCH', default='resnet34')
parser.add_argument('--fold-number', default=5, type=int, metavar='N',
help='The fold number in cross validation')
args = parser.parse_args()
result = {
"compressed": {
"auc": 0.0,
"threshold": {
0.1: {
"accuracy": 0.0,
"specificity": 0.0,
"sensitivity": 0.0
},
0.15: {
"accuracy": 0.0,
"specificity": 0.0,
"sensitivity": 0.0
},
0.2: {
"accuracy": 0.0,
"specificity": 0.0,
"sensitivity": 0.0
}
}
},
"uncompressed": {
"auc": 0.0,
"threshold": {
0.1: {
"accuracy": 0.0,
"specificity": 0.0,
"sensitivity": 0.0
},
0.15: {
"accuracy": 0.0,
"specificity": 0.0,
"sensitivity": 0.0
},
0.2: {
"accuracy": 0.0,
"specificity": 0.0,
"sensitivity": 0.0
}
}
}
}
for image_type in ["compressed", "uncompressed"]:
for i in range(1, args.fold_number+1):
with open("{}-{}-{}-{}".format(args.arch, args.fold_number, i, image_type), "r") as f:
lines = f.readlines()
result[image_type]['auc'] += float(lines[-1].split()[-1]) / args.fold_number
for idx, threshold in enumerate([0.1, 0.15, 0.2]):
stat = result[image_type]['threshold'][threshold]
stat['accuracy'] += float(lines[-1-(3-idx)*4+1].split()[-1]) / args.fold_number
stat['specificity'] += float(lines[-1-(3-idx)*4+2].split()[-1]) / args.fold_number
stat['sensitivity'] += float(lines[-1-(3-idx)*4+3].split()[-1]) / args.fold_number
with open("{}-{}fold-result".format(args.arch, args.fold_number), "w") as f:
for image_type in ["compressed", "uncompressed"]:
f.write(image_type+"\n")
for threshold in [0.1, 0.15, 0.2]:
stat = result[image_type]['threshold'][threshold]
f.write(' threshold : {}\n'.format(threshold))
f.write(' calculated accuracy is {}\n'.format(stat['accuracy']))
f.write(' calculated specificity is {}\n'.format(stat['specificity']))
f.write(' calculated sensitivity is {}\n'.format(stat['sensitivity']))
f.write(" calculated auc is {}\n".format(result[image_type]['auc']))