-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathevaluation.py
More file actions
54 lines (40 loc) · 1.36 KB
/
evaluation.py
File metadata and controls
54 lines (40 loc) · 1.36 KB
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
import json
import numpy as np
from settings import get_args
# preds should be Nx2, gts should be N
def ADE(preds, gts):
point_preds = np.mean(preds, axis=1)
ade = np.abs(point_preds - gts)
return np.mean(ade)
def ALDE(preds, gts):
point_preds = np.mean(preds, axis=1)
alde = np.abs(np.log(point_preds) - np.log(gts))
return np.mean(alde)
def APE(preds, gts):
point_preds = np.mean(preds, axis=1)
ape = np.abs(point_preds - gts) / gts
return np.mean(ape)
def MnRE(preds, gts):
point_preds = np.mean(preds, axis=1)
p_over_t = point_preds / gts
t_over_p = gts / point_preds
ratios = np.vstack([p_over_t, t_over_p])
mnre = np.min(ratios, axis=0)
return np.mean(mnre)
def show_metrics(preds, gts):
print('ADE %.3f' % ADE(preds, gts))
print('ALDE %.3f' % ALDE(preds, gts))
print('APE %.3f' % APE(preds, gts))
print('MnRE %.3f' % MnRE(preds, gts))
if __name__ == '__main__':
args = get_args()
with open(args.preds_json_path, 'r') as f:
preds_dict = json.load(f)
with open(args.gts_json_path, 'r') as f:
gts_dict = json.load(f)
preds = np.zeros((len(preds_dict), 2))
gts = np.zeros(len(preds_dict))
for i, (k, v) in enumerate(preds_dict.items()):
preds[i] = [v[0], v[1]]
gts[i] = gts_dict[k.split('_')[0]]
show_metrics(preds, gts)