forked from jkuck/KITTI_eval_bug
-
Notifications
You must be signed in to change notification settings - Fork 0
/
current_evaluate_tracking.py
executable file
·830 lines (762 loc) · 36.1 KB
/
current_evaluate_tracking.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
#!/usr/bin/env python
# encoding: utf-8
import sys,os,copy,math
from munkres import Munkres
from collections import defaultdict
try:
from ordereddict import OrderedDict # can be installed using pip
except:
from collections import OrderedDict # only included from python 2.7 on
import mailpy
#########################################################################
# function that does the evaluation
# input:
# - result_sha (sha key where the results are located
# - mail (messenger object for output messages sent via email and to cout)
# output:
# - True if at least one of the sub-benchmarks could be processed successfully
# - False otherwise
# data:
# - at this point the submitted files are located in results/<result_sha>/data
# - the results shall be saved as follows
# -> summary statistics of the method: results/<result_sha>/stats_task.txt
# here task refers to the sub-benchmark (e.g., um_lane, uu_road etc.)
# file contents: numbers for main table, format: %.6f (single space separated)
# note: only files with successful sub-benchmark evaluation must be created
# -> detailed results/graphics/plots: results/<result_sha>/subdir
# with appropriate subdir and file names (all subdir's need to be created)
class tData:
def __init__(self,frame=-1,obj_type="unset",truncation=-1,occlusion=-1,\
obs_angle=-10,x1=-1,y1=-1,x2=-1,y2=-1,w=-1,h=-1,l=-1,\
X=-1000,Y=-1000,Z=-1000,yaw=-10,score=-1000,track_id=-1):
# init object data
self.frame = frame
self.track_id = track_id
self.obj_type = obj_type
self.truncation = truncation
self.occlusion = occlusion
self.obs_angle = obs_angle
self.x1 = x1
self.y1 = y1
self.x2 = x2
self.y2 = y2
self.w = w
self.h = h
self.l = l
self.X = X
self.Y = Y
self.Z = Z
self.yaw = yaw
self.score = score
self.ignored = False
self.valid = False
self.tracker = -1
def __str__(self):
attrs = vars(self)
return '\n'.join("%s: %s" % item for item in attrs.items())
class trackingEvaluation(object):
""" tracking statistics (CLEAR MOT, id-switches, fragments, ML/PT/MT, precision/recall)
MOTA - Multi-object tracking accuracy in [0,100]
MOTP - Multi-object tracking precision in [0,100] (3D) / [td,100] (2D)
MOTAL - Multi-object tracking accuracy in [0,100] with log10(id-switches)
id-switches - number of id switches
fragments - number of fragmentations
MT, PT, ML - number of mostly tracked, partially tracked and mostly lost trajectories
recall - recall = percentage of detected targets
precision - precision = percentage of correctly detected targets
FAR - number of false alarms per frame
falsepositives - number of false positives (FP)
missed - number of missed targets (FN)
"""
def __init__(self, t_sha, gt_path="./data/tracking", min_overlap=0.5, max_truncation = 0.15, mail=None, cls="car"):
# get number of sequences and
# get number of frames per sequence from test mapping
# (created while extracting the benchmark)
filename_test_mapping = "./data/tracking/evaluate_tracking.seqmap"
self.n_frames = []
self.sequence_name = []
with open(filename_test_mapping, "r") as fh:
for i,l in enumerate(fh):
fields = l.split(" ")
self.sequence_name.append("%04d" % int(fields[0]))
self.n_frames.append(int(fields[3]) - int(fields[2])+1)
fh.close()
self.n_sequences = i+1
# mail object
self.mail = mail
# class to evaluate
self.cls = cls
# data and parameter
self.gt_path = os.path.join(gt_path, "label_02")
self.t_sha = t_sha
self.t_path = os.path.join("./results", t_sha, "data")
self.n_gt = 0
self.n_gt_trajectories = 0
self.n_gt_seq = []
self.n_tr = 0
self.n_tr_trajectories = 0
self.n_tr_seq = []
self.min_overlap = min_overlap # minimum bounding box overlap for 3rd party metrics
self.max_truncation = max_truncation # maximum truncation of an object for evaluation
self.n_sample_points = 500
# figures for evaluation
self.MOTA = 0
self.MOTP = 0
self.MOTAL = 0
self.MODA = 0
self.MODP = 0
self.MODP_t = []
self.recall = 0
self.precision = 0
self.F1 = 0
self.FAR = 0
self.total_cost = 0
self.tp = 0
self.fn = 0
self.fp = 0
self.mme = 0
self.fragments = 0
self.id_switches = 0
self.MT = 0
self.PT = 0
self.ML = 0
self.distance = []
self.seq_res = []
self.seq_output = []
# this should be enough to hold all groundtruth trajectories
# is expanded if necessary and reduced in any case
self.gt_trajectories = [[] for x in xrange(self.n_sequences)]
self.ign_trajectories = [[] for x in xrange(self.n_sequences)]
def createEvalDir(self):
"""Creates directory to store evaluation results and data for visualization"""
self.eval_dir = os.path.join("./results/", self.t_sha, "eval", self.cls)
if not os.path.exists(self.eval_dir):
print "create directory:", self.eval_dir,
os.makedirs(self.eval_dir)
print "done"
def loadGroundtruth(self):
"""Helper function to load ground truth"""
try:
self._loadData(self.gt_path, cls=self.cls, loading_groundtruth=True)
except IOError:
return False
return True
def loadTracker(self):
"""Helper function to load tracker data"""
try:
if not self._loadData(self.t_path, cls=self.cls, loading_groundtruth=False):
return False
except IOError:
return False
return True
def _loadData(self, root_dir, cls, min_score=-1000, loading_groundtruth=False):
"""
Generic loader for ground truth and tracking data.
Use loadGroundtruth() or loadTracker() to load this data.
Loads detections in KITTI format from textfiles.
"""
# construct objectDetections object to hold detection data
t_data = tData()
data = []
eval_2d = True
eval_3d = True
seq_data = []
n_trajectories = 0
n_trajectories_seq = []
for seq, s_name in enumerate(self.sequence_name):
i = 0
filename = os.path.join(root_dir, "%s.txt" % s_name)
f = open(filename, "r")
f_data = [[] for x in xrange(self.n_frames[seq])] # current set has only 1059 entries, sufficient length is checked anyway
ids = []
n_in_seq = 0
id_frame_cache = []
for line in f:
# KITTI tracking benchmark data format:
# (frame,tracklet_id,objectType,truncation,occlusion,alpha,x1,y1,x2,y2,h,w,l,X,Y,Z,ry)
line = line.strip()
fields = line.split(" ")
# classes that should be loaded (ignored neighboring classes)
if "car" in cls.lower():
classes = ["car","van"]
elif "pedestrian" in cls.lower():
classes = ["pedestrian","person_sitting"]
else:
classes = [cls.lower()]
classes += ["dontcare"]
if not any([s for s in classes if s in fields[2].lower()]):
continue
# get fields from table
t_data.frame = int(float(fields[0])) # frame
t_data.track_id = int(float(fields[1])) # id
t_data.obj_type = fields[2].lower() # object type [car, pedestrian, cyclist, ...]
t_data.truncation = float(fields[3]) # truncation [0..1]
t_data.occlusion = int(float(fields[4])) # occlusion [0,1,2]
t_data.obs_angle = float(fields[5]) # observation angle [rad]
t_data.x1 = float(fields[6]) # left [px]
t_data.y1 = float(fields[7]) # top [px]
t_data.x2 = float(fields[8]) # right [px]
t_data.y2 = float(fields[9]) # bottom [px]
t_data.h = float(fields[10]) # height [m]
t_data.w = float(fields[11]) # width [m]
t_data.l = float(fields[12]) # length [m]
t_data.X = float(fields[13]) # X [m]
t_data.Y = float(fields[14]) # Y [m]
t_data.Z = float(fields[15]) # Z [m]
t_data.yaw = float(fields[16]) # yaw angle [rad]
if not loading_groundtruth:
if len(fields) == 17:
t_data.score = -1
elif len(fields) == 18:
t_data.score = float(fields[17]) # detection score
else:
self.mail.msg("file is not in KITTI format")
return
# do not consider objects marked as invalid
if t_data.track_id is -1 and t_data.obj_type != "dontcare":
continue
idx = t_data.frame
# check if length for frame data is sufficient
if idx >= len(f_data):
print "extend f_data", idx, len(f_data)
f_data += [[] for x in xrange(max(500, idx-len(f_data)))]
try:
id_frame = (t_data.frame,t_data.track_id)
if id_frame in id_frame_cache and not loading_groundtruth:
self.mail.msg("track ids are not unique for sequence %d: frame %d" % (seq,t_data.frame))
self.mail.msg("track id %d occured at least twice for this frame" % t_data.track_id)
self.mail.msg("Exiting...")
#continue # this allows to evaluate non-unique result files
return False
id_frame_cache.append(id_frame)
f_data[t_data.frame].append(copy.copy(t_data))
except:
print len(f_data), idx
raise
if t_data.track_id not in ids and t_data.obj_type!="dontcare":
ids.append(t_data.track_id)
n_trajectories +=1
n_in_seq +=1
# check if uploaded data provides information for 2D and 3D evaluation
if not loading_groundtruth and eval_2d is True and(t_data.x1==-1 or t_data.x2==-1 or t_data.y1==-1 or t_data.y2==-1):
eval_2d = False
if not loading_groundtruth and eval_3d is True and(t_data.X==-1000 or t_data.Y==-1000 or t_data.Z==-1000):
eval_3d = False
# only add existing frames
n_trajectories_seq.append(n_in_seq)
seq_data.append(f_data)
f.close()
if not loading_groundtruth:
self.tracker=seq_data
self.n_tr_trajectories=n_trajectories
self.eval_2d = eval_2d
self.eval_3d = eval_3d
self.n_tr_seq = n_trajectories_seq
if self.n_tr_trajectories==0:
return False
else:
# split ground truth and DontCare areas
self.dcareas = []
self.groundtruth = []
for seq_idx in range(len(seq_data)):
seq_gt = seq_data[seq_idx]
s_g, s_dc = [],[]
for f in range(len(seq_gt)):
all_gt = seq_gt[f]
g,dc = [],[]
for gg in all_gt:
if gg.obj_type=="dontcare":
dc.append(gg)
else:
g.append(gg)
s_g.append(g)
s_dc.append(dc)
self.dcareas.append(s_dc)
self.groundtruth.append(s_g)
self.n_gt_seq=n_trajectories_seq
self.n_gt_trajectories=n_trajectories
return True
def boxoverlap(self,a,b,criterion="union"):
"""
boxoverlap computes intersection over union for bbox a and b in KITTI format.
If the criterion is 'union', overlap = (a inter b) / a union b).
If the criterion is 'a', overlap = (a inter b) / a, where b should be a dontcare area.
"""
x1 = max(a.x1, b.x1)
y1 = max(a.y1, b.y1)
x2 = min(a.x2, b.x2)
y2 = min(a.y2, b.y2)
w = x2-x1
h = y2-y1
if w<=0. or h<=0.:
return 0.
inter = w*h
aarea = (a.x2-a.x1) * (a.y2-a.y1)
barea = (b.x2-b.x1) * (b.y2-b.y1)
# intersection over union overlap
if criterion.lower()=="union":
o = inter / float(aarea+barea-inter)
elif criterion.lower()=="a":
o = float(inter) / float(aarea)
else:
raise TypeError("Unkown type for criterion")
return o
def compute3rdPartyMetrics(self):
"""
Computes the metrics defined in
- Stiefelhagen 2008: Evaluating Multiple Object Tracking Performance: The CLEAR MOT Metrics
MOTA, MOTAL, MOTP
- Nevatia 2008: Global Data Association for Multi-Object Tracking Using Network Flows
MT/PT/ML
"""
# construct Munkres object for Hungarian Method association
hm = Munkres()
max_cost = 1e9
# go through all frames and associate ground truth and tracker results
# groundtruth and tracker contain lists for every single frame containing lists of KITTI format detections
fr, ids = 0,0
for seq_idx in range(len(self.groundtruth)):
seq_gt = self.groundtruth[seq_idx]
seq_dc = self.dcareas[seq_idx]
seq_tracker = self.tracker[seq_idx]
seq_trajectories = defaultdict(list)
seq_ignored = defaultdict(list)
seqtp = 0
seqfn = 0
seqfp = 0
seqcost = 0
last_ids = [[],[]]
tmp_frags = 0
for f in range(len(seq_gt)):
g = seq_gt[f]
dc = seq_dc[f]
t = seq_tracker[f]
# counting total number of ground truth and tracker objects
self.n_gt += len(g)
self.n_tr += len(t)
# use hungarian method to associate, using boxoverlap 0..1 as cost
# build cost matrix
cost_matrix = []
this_ids = [[],[]]
for gg in g:
# save current ids
this_ids[0].append(gg.track_id)
this_ids[1].append(-1)
gg.tracker = -1
gg.id_switch = 0
gg.fragmentation = 0
cost_row = []
for tt in t:
# overlap == 1 is cost ==0
c = 1-self.boxoverlap(gg,tt)
# gating for boxoverlap
if c<=self.min_overlap:
cost_row.append(c)
else:
cost_row.append(max_cost)
cost_matrix.append(cost_row)
# all ground truth trajectories are initially not associated
# extend groundtruth trajectories lists (merge lists)
seq_trajectories[gg.track_id].append(-1)
seq_ignored[gg.track_id].append(False)
if len(g) is 0:
cost_matrix=[[]]
# associate
association_matrix = hm.compute(cost_matrix)
# mapping for tracker ids and ground truth ids
tmptp = 0
tmpfp = 0
tmpfn = 0
tmpc = 0
this_cost = [-1]*len(g)
for row,col in association_matrix:
# apply gating on boxoverlap
c = cost_matrix[row][col]
if c < max_cost:
g[row].tracker = t[col].track_id
this_ids[1][row] = t[col].track_id
t[col].valid = True
g[row].distance = c
self.total_cost += 1-c
seqcost += 1-c
tmpc += 1-c
seq_trajectories[g[row].track_id][-1] = t[col].track_id
# true positives are only valid associations
self.tp += 1
tmptp += 1
this_cost.append(c)
else:
g[row].tracker = -1
self.fn += 1
tmpfn += 1
# associate tracker and DontCare areas
# ignore tracker in neighboring classes
nignoredtracker = 0
for tt in t:
if (self.cls=="car" and tt.obj_type=="van") or (self.cls=="pedestrian" and tt.obj_type=="person_sitting"):
nignoredtracker+= 1
tt.ignored = True
continue
for d in dc:
overlap = self.boxoverlap(tt,d,"a")
if overlap>0.5 and not tt.valid:
tt.ignored = True
nignoredtracker+= 1
break
# check for ignored FN/TP (truncation or neighboring object class)
ignoredfn = 0
nignoredtp = 0
for gg in g:
if gg.tracker < 0:
# ignored FN due to truncation
if gg.truncation>self.max_truncation:
seq_ignored[gg.track_id][-1] = True
gg.ignored = True
ignoredfn += 1
# ignored FN due to neighboring object class
elif (self.cls=="car" and gg.obj_type=="van") or (self.cls=="pedestrian" and gg.obj_type=="person_sitting"):
seq_ignored[gg.track_id][-1] = True
gg.ignored = True
ignoredfn += 1
elif gg.tracker>=0:
# ignored TP due to truncation
if gg.truncation>self.max_truncation:
seq_ignored[gg.track_id][-1] = True
gg.ignored = True
nignoredtp += 1
# ignored TP due nieghboring object class
elif (self.cls=="car" and gg.obj_type=="van") or (self.cls=="pedestrian" and gg.obj_type=="person_sitting"):
seq_ignored[gg.track_id][-1] = True
gg.ignored = True
nignoredtp += 1
# correct TP by number of ignored TP due to truncation
# ignored TP are shown as tracked in visualization
tmptp -= nignoredtp
self.n_gt -= (ignoredfn + nignoredtp)
# false negatives = associated gt bboxes exceding association threshold + non-associated gt bboxes
tmpfn += len(g)-len(association_matrix)-ignoredfn
self.fn += len(g)-len(association_matrix)-ignoredfn
# false positives = tracker bboxes - associated tracker bboxes
# mismatches (mme_t)
tmpfp += len(t) - tmptp - nignoredtp
self.fp += len(t) - tmptp - nignoredtp
# append single distance values
self.distance.append(this_cost)
# update sequence data
seqtp += tmptp
seqfp += tmpfp
seqfn += tmpfn
# sanity checks
if tmptp + tmpfn is not len(g)-ignoredfn-nignoredtp:
print "seqidx", seq_idx
print "frame ", f
print "TP ", tmptp
print "FN ", tmpfn
print "FP ", tmpfp
print "nGT ", len(g)
print "nAss ", len(association_matrix)
print "ign GT", ignoredfn
print "ign TP", nignoredtp
raise NameError("Something went wrong! nGroundtruth is not TP+FN")
if tmptp+tmpfp+nignoredtp is not len(t):
print seq_idx, f, len(t), tmptp, tmpfp
print len(association_matrix), association_matrix
raise NameError("Something went wrong! nTracker is not TP+FP")
# check for id switches or fragmentations
for i,tt in enumerate(this_ids[0]):
if tt in last_ids[0]:
idx = last_ids[0].index(tt)
tid = this_ids[1][i]
lid = last_ids[1][idx]
if tid != lid and lid != -1 and tid != -1:
if g[i].truncation<self.max_truncation:
g[i].id_switch = 1
ids +=1
if tid != lid and lid != -1:
if g[i].truncation < self.max_truncation:
g[i].fragmentation = 1
tmp_frags +=1
fr +=1
# save current index
last_ids = this_ids
# compute MOTP_t
MODP_t = 0
if tmptp!=0:
MODP_t = tmpc/float(tmptp)
self.MODP_t.append(MODP_t)
# remove empty lists for current gt trajectories
self.gt_trajectories[seq_idx] = seq_trajectories
self.ign_trajectories[seq_idx] = seq_ignored
# compute MT/PT/ML, fragments, idswitches for all groundtruth trajectories
n_ignored_tr_total = 0
for seq_idx, (seq_trajectories,seq_ignored) in enumerate(zip(self.gt_trajectories, self.ign_trajectories)):
if len(seq_trajectories)==0:
continue
tmpMT, tmpML, tmpPT, tmpId_switches, tmpFragments = [0]*5
n_ignored_tr = 0
for g, ign_g in zip(seq_trajectories.values(), seq_ignored.values()):
# all frames of this gt trajectory are ignored
if all(ign_g):
n_ignored_tr+=1
n_ignored_tr_total+=1
continue
if all([this==-1 for this in g]):
tmpML+=1
self.ML+=1
continue
# compute tracked frames in trajectory
last_id = g[0]
# first detection (necessary to be in gt_trajectories) is always tracked
tracked = 1 if g[0]>=0 else 0
lgt = 0 if ign_g[0] else 1
for f in range(1,len(g)):
if ign_g[f]:
last_id = -1
continue
lgt+=1
if last_id != g[f] and last_id != -1 and g[f] != -1 and g[f-1] != -1:
tmpId_switches += 1
self.id_switches += 1
if f < len(g)-1 and g[f-1] != g[f] and last_id != -1 and g[f] != -1 and g[f+1] != -1:
tmpFragments += 1
self.fragments += 1
if g[f] != -1:
tracked += 1
last_id = g[f]
# handle last frame; tracked state is handeled in for loop (g[f]!=-1)
if len(g)>1 and g[f-1] != g[f] and last_id != -1 and g[f] != -1 and not ign_g[f]:
tmpFragments += 1
self.fragments += 1
# compute MT/PT/ML
tracking_ratio = tracked / float(len(g) - sum(ign_g))
if tracking_ratio > 0.8:
tmpMT += 1
self.MT += 1
elif tracking_ratio < 0.2:
tmpML += 1
self.ML += 1
else: # 0.2 <= tracking_ratio <= 0.8
tmpPT += 1
self.PT += 1
if (self.n_gt_trajectories-n_ignored_tr_total)==0:
self.MT = 0.
self.PT = 0.
self.ML = 0.
else:
self.MT /= float(self.n_gt_trajectories-n_ignored_tr_total)
self.PT /= float(self.n_gt_trajectories-n_ignored_tr_total)
self.ML /= float(self.n_gt_trajectories-n_ignored_tr_total)
# precision/recall etc.
if (self.fp+self.tp)==0 or (self.tp+self.fn)==0:
self.recall = 0.
self.precision = 0.
else:
self.recall = self.tp/float(self.tp+self.fn)
self.precision = self.tp/float(self.fp+self.tp)
if (self.recall+self.precision)==0:
self.F1 = 0.
else:
self.F1 = 2.*(self.precision*self.recall)/(self.precision+self.recall)
if sum(self.n_frames)==0:
self.FAR = "n/a"
else:
self.FAR = self.fp/float(sum(self.n_frames))
# compute CLEARMOT
if self.n_gt==0:
self.MOTA = -float("inf")
self.MODA = -float("inf")
else:
self.MOTA = 1 - (self.fn + self.fp + self.id_switches)/float(self.n_gt)
self.MODA = 1 - (self.fn + self.fp) / float(self.n_gt)
if self.tp==0:
self.MOTP = float("inf")
else:
self.MOTP = self.total_cost / float(self.tp)
if self.n_gt!=0:
if self.id_switches==0:
self.MOTAL = 1 - (self.fn + self.fp + self.id_switches)/float(self.n_gt)
else:
self.MOTAL = 1 - (self.fn + self.fp + math.log10(self.id_switches))/float(self.n_gt)
else:
self.MOTAL = -float("inf")
if sum(self.n_frames)==0:
self.MODP = "n/a"
else:
self.MODP = sum(self.MODP_t)/float(sum(self.n_frames))
return True
def summary(self):
mail.msg("tracking evaluation summary".center(80,"="))
mail.msg(self.printEntry("Multiple Object Tracking Accuracy (MOTA)", self.MOTA))
mail.msg(self.printEntry("Multiple Object Tracking Precision (MOTP)", self.MOTP))
mail.msg(self.printEntry("Multiple Object Tracking Accuracy (MOTAL)", self.MOTAL))
mail.msg(self.printEntry("Multiple Object Detection Accuracy (MODA)", self.MODA))
mail.msg(self.printEntry("Multiple Object Detection Precision (MODP)", self.MODP))
mail.msg("")
mail.msg(self.printEntry("Recall", self.recall))
mail.msg(self.printEntry("Precision", self.precision))
mail.msg(self.printEntry("F1", self.F1))
mail.msg(self.printEntry("False Alarm Rate", self.FAR))
mail.msg("")
mail.msg(self.printEntry("Mostly Tracked", self.MT))
mail.msg(self.printEntry("Partly Tracked", self.PT))
mail.msg(self.printEntry("Mostly Lost", self.ML))
mail.msg("")
mail.msg(self.printEntry("True Positives", self.tp))
mail.msg(self.printEntry("False Positives", self.fp))
mail.msg(self.printEntry("Missed Targets", self.fn))
mail.msg(self.printEntry("ID-switches", self.id_switches))
mail.msg(self.printEntry("Fragmentations", self.fragments))
mail.msg("")
mail.msg(self.printEntry("Ground Truth Objects", self.n_gt))
mail.msg(self.printEntry("Ground Truth Trajectories", self.n_gt_trajectories))
mail.msg(self.printEntry("Tracker Objects", self.n_tr))
mail.msg(self.printEntry("Tracker Trajectories", self.n_tr_trajectories))
mail.msg("="*80)
#self.saveSummary()
def printEntry(self, key, val,width=(43,10)):
s_out = key.ljust(width[0])
if type(val)==int:
s = "%%%dd" % width[1]
s_out += s % val
elif type(val)==float:
s = "%%%df" % (width[1])
s_out += s % val
else:
s_out += ("%s"%val).rjust(width[1])
return s_out
def saveSummary(self):
filename = os.path.join("./results", self.t_sha, "3rd_party_metrics.txt")
open(filename, "w").close()
dump = open(filename, "a")
print>>dump, "MOTA,", self.MOTA
print>>dump, "MOTP,", self.MOTP
print>>dump, "MOTAL,", self.MOTAL
print>>dump, "MODA,", self.MODA
print>>dump, "MODP,", self.MODP
#print>>dump, ""
print>>dump, "Recall,", self.recall
print>>dump, "Precision,", self.precision
print>>dump, "F1,", self.F1
print>>dump, "FAR,", self.FAR
#print>>dump, ""
print>>dump, "MT,", self.MT
print>>dump, "PT,", self.PT
print>>dump, "ML,", self.ML
#print>>dump, ""
print>>dump, "TP,", self.tp
print>>dump, "FP,", self.fp
print>>dump, "Misses,", self.fn
print>>dump, "ID-switches,", self.id_switches
print>>dump, "Fragmentations,", self.fragments
#print>>dump, ""
print>>dump, "Ground Truth Objects,", self.n_gt
print>>dump, "Ground Truth Trajectories,", self.n_gt_trajectories
print>>dump, "Tracker Objects,", self.n_tr
print>>dump, "Tracker Trajectories,", self.n_tr_trajectories
dump.close()
def saveToStats(self):
self.summary()
filename = os.path.join("./results", self.t_sha, "stats_%s.txt" % self.cls)
dump = open(filename, "w+")
print>>dump, "%.6f " * 21 \
% (self.MOTA, self.MOTP, self.MOTAL, self.MODA, self.MODP, \
self.recall, self.precision, self.F1, self.FAR, \
self.MT, self.PT, self.ML, self.tp, self.fp, self.fn, self.id_switches, self.fragments, \
self.n_gt, self.n_gt_trajectories, self.n_tr, self.n_tr_trajectories)
dump.close()
filename = os.path.join("./results", self.t_sha, "description.txt")
dump = open(filename, "w+")
print>>dump, "MOTA", "MOTP", "MOTAL", "MODA", "MODP", "recall", "precision", "F1", "FAR",
print>>dump, "MT", "PT", "ML", "tp", "fp", "fn", "id_switches", "fragments",
print>>dump, "n_gt", "n_gt_trajectories", "n_tr", "n_tr_trajectories"
def sequenceSummary(self):
filename = os.path.join("./results", self.t_sha, self.dataset, "sequences.txt")
open(filename, "w").close()
dump = open(filename, "a")
self.printSep("Sequence Evaluation")
self.printSep()
print "seq\t", "\t".join(self.seq_res[0].keys())
print>>dump, "seq\t", "\t".join(self.seq_res[0].keys())
for i,s in enumerate(self.seq_res):
print i,"\t",
print>>dump, i,"\t",
for e in s.values():
if type(e) is int:
print "%d" % e, "\t",
print>>dump,"%d\t" % e,
elif type(e) is float:
print "%.3f" % e, "\t",
print>>dump, "%.3f\t" % e,
else:
print "%s" % e, "\t",
print>>dump, "%s\t" % e,
print ""
print>>dump, ""
self.printSep()
dump.close()
def evaluate(result_sha,mail):
# start evaluation and instanciated eval object
mail.msg("Processing Result for KITTI Tracking Benchmark")
classes = []
for c in ("car", "pedestrian"):
e = trackingEvaluation(t_sha=result_sha, mail=mail,cls=c)
# load tracker data and check provided classes
try:
if not e.loadTracker():
continue
mail.msg("Loading Results - Success")
mail.msg("Evaluate Object Class: %s" % c.upper())
classes.append(c)
except:
mail.msg("Feel free to contact us ([email protected]), if you receive this error message:")
mail.msg(" Caught exception while loading result data.")
break
# load groundtruth data for this class
if not e.loadGroundtruth():
raise ValueError("Ground truth not found.")
mail.msg("Loading Groundtruth - Success")
# sanity checks
if len(e.groundtruth) is not len(e.tracker):
mail.msg("The uploaded data does not provide results for every sequence.")
return False
mail.msg("Loaded %d Sequences." % len(e.groundtruth))
mail.msg("Start Evaluation...")
# create needed directories, evaluate and save stats
try:
e.createEvalDir()
except:
mail.msg("Feel free to contact us ([email protected]), if you receive this error message:")
mail.msg(" Caught exception while creating results.")
if e.compute3rdPartyMetrics():
e.saveToStats()
else:
mail.msg("There seem to be no true positives or false positives at all in the submitted data.")
# finish
if len(classes)==0:
mail.msg("The uploaded results could not be evaluated. Check for format errors.")
return False
mail.msg("Thank you for participating in our benchmark!")
return True
#########################################################################
# entry point of evaluation script
# input:
# - result_sha (unique key of results)
# - user_sha (key of user who submitted the results, optional)
# - user_sha (email of user who submitted the results, optional)
if __name__ == "__main__":
# check for correct number of arguments. if user_sha and email are not supplied,
# no notification email is sent (this option is used for auto-updates)
if len(sys.argv)!=2 and len(sys.argv)!=4:
print "Usage: python eval_tracking.py result_sha [user_sha email]"
sys.exit(1);
# get unique sha key of submitted results
result_sha = sys.argv[1]
# create mail messenger and debug output object
if len(sys.argv)==4:
mail = mailpy.Mail(sys.argv[3])
else:
mail = mailpy.Mail("")
# evaluate results and send notification email to user
success = evaluate(result_sha,mail)
if len(sys.argv)==4: mail.finalize(success,"tracking",result_sha,sys.argv[2])
else: mail.finalize(success,"tracking",result_sha,"")