-
Notifications
You must be signed in to change notification settings - Fork 0
/
eval_otb.py
156 lines (129 loc) · 6.33 KB
/
eval_otb.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import sys
import json
import os
import glob
from os.path import join as fullfile
import numpy as np
def overlap_ratio(rect1, rect2):
'''
Compute overlap ratio between two rects
- rect: 1d array of [x,y,w,h] or
2d array of N x [x,y,w,h]
'''
if rect1.ndim==1:
rect1 = rect1[None,:]
if rect2.ndim==1:
rect2 = rect2[None,:]
left = np.maximum(rect1[:,0], rect2[:,0])
right = np.minimum(rect1[:,0]+rect1[:,2], rect2[:,0]+rect2[:,2])
top = np.maximum(rect1[:,1], rect2[:,1])
bottom = np.minimum(rect1[:,1]+rect1[:,3], rect2[:,1]+rect2[:,3])
intersect = np.maximum(0,right - left) * np.maximum(0,bottom - top)
union = rect1[:,2]*rect1[:,3] + rect2[:,2]*rect2[:,3] - intersect
iou = np.clip(intersect / union, 0, 1)
return iou
def compute_success_overlap(gt_bb, result_bb):
thresholds_overlap = np.arange(0, 1.05, 0.05)
n_frame = len(gt_bb)
success = np.zeros(len(thresholds_overlap))
iou = overlap_ratio(gt_bb, result_bb)
for i in range(len(thresholds_overlap)):
success[i] = sum(iou > thresholds_overlap[i]) / float(n_frame)
return success
def compute_success_error(gt_center, result_center):
thresholds_error = np.arange(0, 51, 1)
n_frame = len(gt_center)
success = np.zeros(len(thresholds_error))
dist = np.sqrt(np.sum(np.power(gt_center - result_center, 2), axis=1))
for i in range(len(thresholds_error)):
success[i] = sum(dist <= thresholds_error[i]) / float(n_frame)
return success
def get_result_bb(arch, seq):
result_path = fullfile(arch, seq + '.txt')
temp = np.loadtxt(result_path, delimiter=',').astype(np.float)
return np.array(temp)
def convert_bb_to_center(bboxes):
return np.array([(bboxes[:, 0] + (bboxes[:, 2] - 1) / 2),
(bboxes[:, 1] + (bboxes[:, 3] - 1) / 2)]).T
def eval_auc(dataset='OTB2015', tracker_reg='S*', start=0, end=1e6):
list_path = os.path.join('dataset', dataset + '.json')
annos = json.load(open(list_path, 'r'))
seqs = [i for i in annos.keys()]
OTB2013 = ['carDark', 'car4', 'david', 'david2', 'sylvester', 'trellis', 'fish', 'mhyang', 'soccer', 'matrix',
'ironman', 'deer', 'skating1', 'shaking', 'singer1', 'singer2', 'coke', 'bolt', 'boy', 'dudek',
'crossing', 'couple', 'football1', 'jogging_1', 'jogging_2', 'doll', 'girl', 'walking2', 'walking',
'fleetface', 'freeman1', 'freeman3', 'freeman4', 'david3', 'jumping', 'carScale', 'skiing', 'dog1',
'suv', 'motorRolling', 'mountainBike', 'lemming', 'liquor', 'woman', 'faceocc1', 'faceocc2',
'basketball', 'football', 'subway', 'tiger1', 'tiger2']
OTB2015 = ['carDark', 'car4', 'david', 'david2', 'sylvester', 'trellis', 'fish', 'mhyang', 'soccer', 'matrix',
'ironman', 'deer', 'skating1', 'shaking', 'singer1', 'singer2', 'coke', 'bolt', 'boy', 'dudek',
'crossing', 'couple', 'football1', 'jogging_1', 'jogging_2', 'doll', 'girl', 'walking2', 'walking',
'fleetface', 'freeman1', 'freeman3', 'freeman4', 'david3', 'jumping', 'carScale', 'skiing', 'dog1',
'suv', 'motorRolling', 'mountainBike', 'lemming', 'liquor', 'woman', 'faceocc1', 'faceocc2',
'basketball', 'football', 'subway', 'tiger1', 'tiger2', 'clifBar', 'biker', 'bird1', 'blurBody',
'blurCar2', 'blurFace', 'blurOwl', 'box', 'car1', 'crowds', 'diving', 'dragonBaby', 'human3', 'human4_2',
'human6', 'human9', 'jump', 'panda', 'redTeam', 'skating2_1', 'skating2_2', 'surfer', 'bird2',
'blurCar1', 'blurCar3', 'blurCar4', 'board', 'bolt2', 'car2', 'car24', 'coupon', 'dancer', 'dancer2',
'dog', 'girl2', 'gym', 'human2', 'human5', 'human7', 'human8', 'kiteSurf', 'man', 'rubik', 'skater',
'skater2', 'toy', 'trans', 'twinnings', 'vase']
trackers = glob.glob(fullfile('result', dataset, tracker_reg))
trackers = trackers[start:min(end, len(trackers))]
n_seq = len(seqs)
thresholds_overlap = np.arange(0, 1.05, 0.05)
# thresholds_error = np.arange(0, 51, 1)
success_overlap = np.zeros((n_seq, len(trackers), len(thresholds_overlap)))
# success_error = np.zeros((n_seq, len(trackers), len(thresholds_error)))
for i in range(n_seq):
seq = seqs[i]
gt_rect = np.array(annos[seq]['gt_rect']).astype(np.float)
gt_center = convert_bb_to_center(gt_rect)
for j in range(len(trackers)):
tracker = trackers[j]
print('{:d} processing:{} tracker: {}'.format(i, seq, tracker))
bb = get_result_bb(tracker, seq)
center = convert_bb_to_center(bb)
success_overlap[i][j] = compute_success_overlap(gt_rect, bb)
# success_error[i][j] = compute_success_error(gt_center, center)
print('Success Overlap')
if 'OTB2015' == dataset:
OTB2013_id = []
for i in range(n_seq):
if seqs[i] in OTB2013:
OTB2013_id.append(i)
max_auc_OTB2013 = 0.
max_name_OTB2013 = ''
for i in range(len(trackers)):
auc = success_overlap[OTB2013_id, i, :].mean()
if auc > max_auc_OTB2013:
max_auc_OTB2013 = auc
max_name_OTB2013 = trackers[i]
print('%s(%.4f)' % (trackers[i], auc))
max_auc = 0.
max_name = ''
for i in range(len(trackers)):
auc = success_overlap[:, i, :].mean()
if auc > max_auc:
max_auc = auc
max_name = trackers[i]
print('%s(%.4f)' % (trackers[i], auc))
print('\nOTB2013 Best: %s(%.4f)' % (max_name_OTB2013, max_auc_OTB2013))
print('\nOTB2015 Best: %s(%.4f)' % (max_name, max_auc))
else:
max_auc = 0.
max_name = ''
for i in range(len(trackers)):
auc = success_overlap[:, i, :].mean()
if auc > max_auc:
max_auc = auc
max_name = trackers[i]
print('%s(%.4f)' % (trackers[i], auc))
print('\n%s Best: %s(%.4f)' % (dataset, max_name, max_auc))
if __name__ == "__main__":
if len(sys.argv) < 5:
print('python eval_otb.py OTB2015 DCFNet_test* 0 10')
exit()
dataset = sys.argv[1]
tracker_reg = sys.argv[2]
start = int(sys.argv[3])
end = int(sys.argv[4])
eval_auc(dataset, tracker_reg, start, end)