-
Notifications
You must be signed in to change notification settings - Fork 0
/
evaluate_t3dp.py
145 lines (107 loc) · 6.03 KB
/
evaluate_t3dp.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
import matplotlib.pyplot as plt
import numpy as np
import os
from PIL import Image
# from matplotlib.pyplot import imshow
import cv2
import torch
import json
import pickle
import copy
from tqdm import tqdm
import motmetrics as mm
import sys
from tqdm import tqdm
import joblib
from torchvision.utils import save_image, make_grid
RGB_tuples = np.vstack([np.loadtxt("utils/colors.txt", skiprows=1) , np.random.uniform(0, 255, size=(1000, 3))])
b = np.where(RGB_tuples==0)
RGB_tuples[b] = 1
# # # #########################################################################################################
# # # #########################################################################################################
# # # ############################### attach predicted data - T3PO #################################
# # # #########################################################################################################
# # # #########################################################################################################
def evaluate_trackers(results_dir, method="phalp", dataset="posetrack", make_video=0):
if(dataset=="posetrack"): data_gt = joblib.load('_DATA/posetrack_gt.pickle') ; base_dir = "_DATA/Posetrack_2018/"
if(dataset=="mupots"): data_gt = joblib.load('_DATA/mupots_gt.pickle') ; base_dir = "_DATA/MuPoTs/"
if(dataset=="ava"): data_gt = joblib.load('_DATA/ava_gt.pickle') ; base_dir = "_DATA/AVA/"
data_all = {}
total_annoated_frames = 0
total_detected_frames = 0
if(method=='t3dp'):
for video_ in data_gt.keys():
try:
if(dataset=="ava"): T3DP_predictions = joblib.load(results_dir + video_.split("/")[0] + ".pkl")
else: T3DP_predictions = joblib.load(results_dir + video_ + ".pkl")
except: continue
list_of_gt_frames = np.sort(list(data_gt[video_].keys()))
tracked_frames = list(T3DP_predictions.keys())
data_all[video_] = {}
for i in range(len(list_of_gt_frames)):
frame_ = list_of_gt_frames[i]
total_annoated_frames += 1
if(frame_ in tracked_frames):
tracked_data = T3DP_predictions[frame_]
if(len(data_gt[video_][frame_][0])>0):
assert data_gt[video_][frame_][0][0].split("/")[-1] == frame_
if(len(tracked_data[0])==0):
data_all[video_][frame_] = [data_gt[video_][frame_][0], data_gt[video_][frame_][1], data_gt[video_][frame_][2], data_gt[video_][frame_][3], [], [], []]
else:
data_all[video_][frame_] = [data_gt[video_][frame_][0], data_gt[video_][frame_][1], data_gt[video_][frame_][2], data_gt[video_][frame_][3], frame_, tracked_data[0], tracked_data[1]]
total_detected_frames += 1
else:
data_all[video_][frame_] = [data_gt[video_][frame_][0], data_gt[video_][frame_][1], data_gt[video_][frame_][2], data_gt[video_][frame_][3], [], [], []];
joblib.dump(data_all, results_dir + '/'+str(dataset)+'_'+str(method)+'.pkl')
# #########################################################################################################
# #########################################################################################################
# ############################### Evaluate #######################################
# #########################################################################################################
# #########################################################################################################
accumulators = []
for video in tqdm(list(data_all.keys())):
acc = mm.MOTAccumulator(auto_id=True)
accumulators.append(acc)
for t, frame in enumerate(data_all[video].keys()):
data = data_all[video][frame]
gt_ids = data[1]
gt_ids_new = data[3]
gt_bbox = data[2]
pt_ids = data[5]
pt_bbox = data[6]
if(len(gt_ids_new)>0):
cost_ = mm.distances.iou_matrix(gt_bbox, pt_bbox, max_iou=0.99)
accumulators[-1].update(
gt_ids_new, # Ground truth objects in this frame
pt_ids, # Detector hypotheses in this frame
cost_
)
mh = mm.metrics.create()
summary = mh.compute_many(
accumulators,
metrics=mm.metrics.motchallenge_metrics,
generate_overall=True
)
ID_switches = summary['num_switches']['OVERALL']
MOTA = summary['mota']['OVERALL']
PRCN = summary['precision']['OVERALL']
RCLL = summary['recall']['OVERALL']
strsummary = mm.io.render_summary(
summary,
formatters = mh.formatters,
namemap = mm.io.motchallenge_metric_names
)
results_ID_switches = summary['num_switches']['OVERALL']
results_mota = summary['mota']['OVERALL']
print(strsummary)
print("ID switches ", results_ID_switches)
print("MOTA ", results_mota)
text_file = open(results_dir + '/str_summary.txt', "w")
n = text_file.write(strsummary)
text_file.close()
return strsummary, summary
if __name__ == '__main__':
results_dir = str(sys.argv[1])
method = str(sys.argv[2])
dataset = str(sys.argv[3])
strsummary, summary = evaluate_trackers(results_dir, method=method, dataset=dataset, make_video=0)