-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgenerate_scores.py
98 lines (88 loc) · 3.25 KB
/
generate_scores.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import os
import pandas as pd
num = 8
import pandas as pd
# assume that the output information is stored in a "xxx.log"
file_path = r'your_path/xxx.log'
excel_path = file_path[:-3] + 'csv'
data = {
'Layer': [],
# 'Evaluation Type': [],
'Accuracy@1': [],
'Accuracy@5': [],
'Mean Distance FaceNet': [],
'Mean Distance Inception-v3': [],
'Precision': [],
'Recall': [],
'Density': [],
'Coverage': [],
}
# read
with open(file_path, 'r') as file:
flag = True
t = 'unf'
for line in file:
if flag and not line.startswith('Unfilter'):
continue
if 'Evaluation' in line:
if 'best' in line:
continue
flag = False
parts = line.split()
# print(parts)
layer = int(parts[9].rstrip(':'))
# eval_type = 'Unfiltered' if 'Unfiltered' in line else 'Filtered'
accuracy_1 = float(parts[10].rstrip(',')[-8:])
accuracy_5 = float(parts[12].rstrip(',')[-8:])
# update DataFrame
# data['Evaluation Type'].append(eval_type)
if 'Unfiltered' in line:
data['Layer'].append(layer)
data['UnfAccuracy@1'].append(accuracy_1)
data['UnfAccuracy@5'].append(accuracy_5)
else:
data['FAccuracy@1'].append(accuracy_1)
data['FAccuracy@5'].append(accuracy_5)
# data['Correct Confidence'].append(correct_conf)
# data['Total Confidence'].append(total_conf)
elif 'Precision' in line:
parts = line.split()
precision = float(parts[1].rstrip(','))
recall = float(parts[3].rstrip(','))
density = float(parts[5].rstrip(','))
coverage = float(parts[7])
if t == 'unf':
data['UnfPrecision'].append(precision)
data['UnfRecall'].append(recall)
data['UnfDensity'].append(density)
data['UnfCoverage'].append(coverage)
else:
# update DataFrame
data['Precision'].append(precision)
data['Recall'].append(recall)
data['Density'].append(density)
data['Coverage'].append(coverage)
elif 'ean Distance' in line:
parts = line.split()
# layer = int(parts[5])
mean_distance = float(parts[-1])
# print(parts)
# update DataFrame
if 'Unfiltered' in line:
if 'Inception-v3' in line:
data['Unf Mean Distance Inception-v3'].append(mean_distance)
elif 'FaceNet' in line:
data['Unf Mean Distance FaceNet'].append(mean_distance)
else:
if 'Inception-v3' in line:
data['Mean Distance Inception-v3'].append(mean_distance)
elif 'FaceNet' in line:
data['Mean Distance FaceNet'].append(mean_distance)
elif 'Filtered metrics of layer' in line:
t = 'f'
elif 'Unfiltered metrics of layer' in line:
t = 'unf'
for k, v in data.items():
print(f'{k}: {len(v)}')
df = pd.DataFrame(data)
df.to_csv(excel_path, index=False)