-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevaluate.py
62 lines (40 loc) · 2.08 KB
/
evaluate.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
import numpy as np
from argparse import ArgumentParser
import pandas as pd
def evaluate_localization(predicted, target):
"""Evaluates localization results.
Input:
predicted: matrix of N x 4 real numbers (x,y,u,v)
representing the predicted 2D location (x,y)
and the orientation (u,v)
target: ground truth locations/orientations in the same form of predicted
Output:
(position_error, orientation_error)"""
position_errors = np.sqrt(((predicted[:,:2]-target[:,:2])**2).sum(1))
def normalize(x):
return x/np.sqrt((x**2).sum(1)).reshape(-1,1)
predicted_orientations = normalize(predicted[:,2:])
target_orientations = normalize(target[:,2:])
orientation_errors = np.degrees(np.arccos((predicted_orientations*target_orientations).sum(1)))
return position_errors.mean(), np.median(position_errors), np.mean(orientation_errors), np.median(orientation_errors)
def main():
parser = ArgumentParser()
parser.add_argument('predicted_locations', type=str, help='Path to the csv containing the predicted locations')
parser.add_argument('target_locations', type=str, help='Path to the csv containing the ground truth locations')
args=parser.parse_args()
names=['img','x','y','u','v']
predicted=pd.read_csv(args.predicted_locations, header=None, names=names)
target=pd.read_csv(args.target_locations, header=None, names=names)
assert len(predicted)==len(target), "The number of predicted and target locations should match"
predicted.sort_values('img',inplace=True)
target.sort_values('img',inplace=True)
predicted = predicted.drop('img',1).values
target = target.drop('img',1).values
errors = evaluate_localization(predicted,target)
print ("Errors:")
print ("Mean Location Error: %0.4f" % (errors[0],))
print ("Median Location Error: %0.4f" % (errors[1],))
print ("Mean Orientation Error: %0.4f" % (errors[2],))
print ("Median Orientation Error: %0.4f" % (errors[3],))
if __name__== "__main__":
main()