-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathevaluate.py
More file actions
78 lines (61 loc) · 2.27 KB
/
Copy pathevaluate.py
File metadata and controls
78 lines (61 loc) · 2.27 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import numpy as np
N_THRESHOLD = 15
def reset_record():
record = {
'n_threshold': N_THRESHOLD,
'eq_correct_count': np.zeros(N_THRESHOLD),
'not_eq_correct_count': np.zeros(N_THRESHOLD),
'eq_count': 0,
'not_eq_count': 0,
'threshold': 0.1*np.array(range(N_THRESHOLD)),
'WKDR': np.zeros((N_THRESHOLD, 4))
}
return record
def _classify(zA, zB, gt, threshold):
if zA - zB > threshold:
res = 1
elif zA - zB < -threshold:
res = -1
else:
res = 0
return (res == gt)
def _count_correct(output, target, record):
for idx in range(len(target)):
yA = target[idx][0]
xA = target[idx][1]
yB = target[idx][2]
xB = target[idx][3]
zA = output[yA][xA]
zB = output[yB][xB]
gt = target[idx][4]
for tau_idx in range(record['n_threshold']):
if _classify(zA, zB, gt, record['threshold'][tau_idx]):
if gt == 0:
record['eq_correct_count'][tau_idx] += 1
else:
record['not_eq_correct_count'][tau_idx] += 1
if gt == 0:
record['eq_count'] += 1
else:
record['not_eq_count'] += 1
def evaluate(output, target):
"""
Args:
Output: np array, N x height x width x 1
target: np array, N x 800 x 5
"""
record = reset_record()
n_iters = output.shape[0]
for i in range(n_iters):
_count_correct(output[i], target[i], record)
max_min = 0
max_min_k = 1
for tau_idx in range(record['n_threshold']):
record['WKDR'][tau_idx][0] = record['threshold'][tau_idx]
record['WKDR'][tau_idx][1] = float(record['eq_correct_count'][tau_idx]+record['not_eq_correct_count'][tau_idx])/float(record['eq_count']+record['not_eq_count'])
record['WKDR'][tau_idx][2] = float(record['eq_correct_count'][tau_idx])/float(record['eq_count'])
record['WKDR'][tau_idx][3] = float(record['not_eq_correct_count'][tau_idx])/float(record['not_eq_count'])
if min(record['WKDR'][tau_idx][2], record['WKDR'][tau_idx][3]) > max_min:
max_min = min(record['WKDR'][tau_idx][2], record['WKDR'][tau_idx][3])
max_min_k = tau_idx
return 1 - max_min