changeset 593:e2a873e08568

non-working clear mot metrics
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Sat, 06 Dec 2014 22:15:56 -0500
parents 985a3021cff2
children 9e39cd95e017
files python/moving.py scripts/compute-clearmot.py
diffstat 2 files changed, 63 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/python/moving.py	Fri Dec 05 17:50:16 2014 -0500
+++ b/python/moving.py	Sat Dec 06 22:15:56 2014 -0500
@@ -1339,6 +1339,59 @@
                     matchTable.append([t, a.getNum(), matchingObject.getNum(), minDist])
     return matchTable
 
+def computeClearMOT(matchTable, nTrackFrames):
+    '''Computes the MOTA/MOTP measures from the matching statistics 
+    between ground truth and tracker output 
+    computed by matchingGroundTruthToTracker
+
+    nTrackFrames is the sum of the number of frames of existence of all tracker output
+
+    Adapted from Dariush Ettehadieh's thesis work'''
+    #Calculate MOTP
+    dist = 0. # total distance between GT and tracker output
+    nAssociatedGTFrames = 0
+    mt = 0 # number of missed GT frames (sum of the number of GT not detected in each frame)
+    for mtab in matchTable:
+        if mtab[2] != None:
+            dist += float(mtab[3])#/T
+            nAssociatedGTFrames += 1
+        else:
+            mt += 1
+    if nAssociatedGTFrames != 0:
+        motp = dist/nAssociatedGTFrames
+    else:
+        return 0,0,0,0,0,0
+
+    #Calculate MOTA
+    gt = len(matchTable) # sum of the number of GT in each frame, or sum of the length of existence of each GT
+    #for sgt in sorted_gt_positions:
+    #    gt += (len(sgt)-1)
+
+    #total_traces = len(object_positions)
+    fpt = nTrackFrames - nAssociatedGTFrames
+
+    # gtobj = 0
+    mme = 0
+    # while gtobj <= n_gt_objects:
+    #     prev = [0,0,-1,0]
+    #     new_match = 0
+    #     for mtab in matchTable:
+    #         if mtab[1] == gtobj:
+    #             if new_match == 0:
+    #                 new_match = 1
+    #                 mme = mme - 1
+    #                 if mtab[2] != prev[2]:
+    #                     mme += 1
+    #                     prev = mtab
+    #                     gtobj += 1
+
+    mota = 1-(float(mt+fpt+mme)/gt)
+
+    print 'MOTP: ' + str(motp)
+    print 'MOTA: ' + str(mota)
+    return motp, mota, dist, mt, mme, fpt
+
+
 def plotRoadUsers(objects, colors):
     '''Colors is a PlottingPropertyValues instance'''
     from matplotlib.pyplot import figure, axis
--- a/scripts/compute-clearmot.py	Fri Dec 05 17:50:16 2014 -0500
+++ b/scripts/compute-clearmot.py	Sat Dec 06 22:15:56 2014 -0500
@@ -27,12 +27,19 @@
 else:
     homography = None
 
+firstInstant = int(args.firstInstant)
+lastInstant = int(args.lastInstant)
+
 objects = storage.loadTrajectoriesFromSqlite(args.trackerDatabaseFilename, 'object')
 annotations = storage.loadGroundTruthFromSqlite(args.groundTruthDatabaseFilename)
 for a in annotations:
     a.computeCentroidTrajectory(homography)
 
-moving.matchingGroundTruthToTracker(objects, annotations, args.matchingDistance, 
-                                    int(args.firstInstant), int(args.lastInstant))
-#storage.deleteFromSqlite(args.databaseFilename, args.dataType)
+matchTable = moving.matchingGroundTruthToTracker(objects, annotations, args.matchingDistance, 
+                                                 firstInstant, lastInstant)
 
+# number of frames of existence of all objects within [firstInstant, lastInstant]
+nTrackFrames = sum([min(o.getLastInstant(),lastInstant)-max(o.getFirstInstant(),firstInstant)+1 for o in objects])
+
+print moving.computeClearMOT(matchTable, nTrackFrames)
+