-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert_metric.py
41 lines (34 loc) · 1.29 KB
/
convert_metric.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
import json
import sys
config = json.load(open(sys.argv[1], 'r'))
AUC = ['breast_horizontal', 'default_credit_horizontal', 'give_credit_horizontal',
'breast_vertical', 'default_credit_vertical', 'give_credit_vertical', ]
ACC = ['vehicle_scale_horizontal', 'vehicle_scale_vertical', 'femnist', 'reddit']
ERR = ['student_horizontal', 'motor_vertical', 'dvisits_vertical', 'student_vertical']
config = json.load(open(sys.argv[1], 'r'))
if config['dataset'] in AUC:
metrics = 'auc'
elif config['dataset'] in ACC:
metrics = 'accuracy'
elif config['dataset'] in ERR:
metrics = 'mse'
else:
raise NotImplementedError('Dataset {} is not supported.'.format(config['dataset']))
with open('./log/0.log', 'r') as f:
lines = f.readlines()
out = []
for line in lines:
log = json.loads(line)
if log.get('event') is not None and log['event'] == 'model_evaluation' and log['action'] == 'end':
try:
real_metrics = {metrics: log['metrics']['target_metric']}
except:
real_metrics = {metrics: log['metrics'][metrics]}
log['metrics'] = real_metrics
out.append(json.dumps(log)+'\n')
else:
out.append(line)
with open('./log/0.log', 'w') as f:
f.writelines(out)
import flbenchmark.logging
flbenchmark.logging.get_report('./log')