forked from brjathu/PHALP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
evaluate_PHALP.py
216 lines (171 loc) · 8.71 KB
/
evaluate_PHALP.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
import matplotlib.pyplot as plt
import numpy as np
import os
from PIL import Image
import cv2
import torch
import json
import pickle
import copy
from tqdm import tqdm
import motmetrics as mm
from utils.utils_measure import _from_dense
import external.TrackEval.trackeval as trackeval
import sys
from tqdm import tqdm
import joblib
def evaluate_trackers(results_dir, method="phalp", dataset="posetrack", make_video=0):
if(dataset=="posetrack"): data_gt = joblib.load('_DATA/posetrack/gt_data.pickle') ; base_dir = "_DATA/posetrack/posetrack_data/"
if(dataset=="mupots"): data_gt = joblib.load('_DATA/mupots/gt_data.pickle') ; base_dir = "_DATA/mupots/mupots_data/"
if(dataset=="ava"): data_gt = joblib.load('_DATA/ava/gt_data.pickle') ; base_dir = "_DATA/ava/ava_data/"
# if(dataset=="ava"):
# data_gt = joblib.load('_DATA/AVA/gt_data.pickle')
# base_dir = ""
# data_old = np.load("_DATA/ava_val_evaluation.npz")
# old_video_names_ = [i for i in os.listdir("_Videos/AVA_2/") if "frame" in i]
# old_video_names = []
# for frame in old_video_names_:
# old_video_names += [frame + "/" + i for i in os.listdir("AVA_2/"+frame+"/") if len(i)>=10]
data_all = {}
total_annoated_frames = 0
total_detected_frames = 0
if(method=='phalp'):
for video_ in data_gt.keys():
try:
PHALP_predictions = joblib.load(results_dir + video_ + ".pkl")
except:
continue
list_of_gt_frames = np.sort(list(data_gt[video_].keys()))
tracked_frames = list(PHALP_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 = PHALP_predictions[frame_]
if(len(data_gt[video_][frame_][0])>0):
if(dataset=="ava"): assert data_gt[video_][frame_][0][0][0].split("/")[-1] == frame_
else: 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], [], [], []]; print("Error!")
print("Total annoated frames ", total_annoated_frames)
print("Total detected frames ", total_detected_frames)
joblib.dump(data_all, results_dir + '/'+str(dataset)+'_'+str(method)+'.pkl')
if(make_video==2): make_videos_for_eval(data_all, base_dir, results_dir, method=method)
# #########################################################################################################
# #########################################################################################################
# ############################### Evaluate #######################################
# #########################################################################################################
# #########################################################################################################
use_hota = True
accumulators = []
TOTAL_AssA = []
TOTAL_DetA = []
TOTAL_HOTA = []
for video in tqdm(list(data_all.keys())):
acc = mm.MOTAccumulator(auto_id=True)
accumulators.append(acc)
############# HOTA evaluation code
if(use_hota):
T = len(data_all[video].keys())
gt_ids_hota = np.zeros((T, 500))
pr_ids_hota = np.zeros((T, 500))
similarity_hota = np.zeros((T, 500, 500))
gt_available = []
hota_metric = trackeval.metrics.HOTA()
start_ = 0
list_of_predictions = []
for t, frame in enumerate(data_all[video].keys()):
data = data_all[video][frame]
pt_ids = data[5]
for p_ in pt_ids:
list_of_predictions.append(p_)
list_of_predictions = np.unique(list_of_predictions)
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]
pt_ids = []
pt_bbox = []
for p_, b_ in zip(pt_ids_, pt_bbox_):
loc= np.where(list_of_predictions==p_)[0][0]
pt_ids.append(loc)
pt_bbox.append(b_)
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_
)
cost_[np.isnan(cost_)] = 1
############# HOTA evaluation code
if(use_hota):
gt_available.append(t)
for idx_gt in gt_ids_new:
gt_ids_hota[t][idx_gt] = 1
for idx_pr in pt_ids:
pr_ids_hota[t][idx_pr] = 1
for i, idx_gt in enumerate(gt_ids_new):
for j, idx_pr in enumerate(pt_ids):
similarity_hota[t][idx_gt][idx_pr] = 1-cost_[i][j]
if(use_hota):
gt_ids_hota = gt_ids_hota[gt_available, :]
pr_ids_hota = pr_ids_hota[gt_available, :]
similarity_hota = similarity_hota[gt_available, :]
data = _from_dense(
num_timesteps = len(gt_available),
num_gt_ids = np.sum(np.sum(gt_ids_hota, 0)>0),
num_tracker_ids= np.sum(np.sum(pr_ids_hota, 0)>0),
gt_present = gt_ids_hota,
tracker_present= pr_ids_hota,
similarity = similarity_hota,
)
results = hota_metric.eval_sequence(data)
TOTAL_AssA.append(np.mean(results['AssA']))
TOTAL_DetA.append(np.mean(results['DetA']))
TOTAL_HOTA.append(np.mean(results['HOTA']))
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)
if(use_hota):
results_AssA = np.mean(TOTAL_AssA)
results_DetA = np.mean(TOTAL_DetA)
results_HOTA = np.mean(TOTAL_HOTA)
print("AssA ", results_AssA)
print("DetA ", results_DetA)
print("HOTA ", results_HOTA)
text_file = open(results_dir + '/str_summary.txt', "w")
n = text_file.write(strsummary)
text_file.close()
return strsummary, summary, TOTAL_AssA, TOTAL_HOTA
if __name__ == '__main__':
results_dir = str(sys.argv[1])
method = str(sys.argv[2])
dataset = str(sys.argv[3])
strsummary, summary, TOTAL_AssA, TOTAL_HOTA = evaluate_trackers(results_dir, method=method, dataset=dataset, make_video=0)