-
Notifications
You must be signed in to change notification settings - Fork 0
/
outputs_to_csv.py
executable file
·164 lines (133 loc) · 7.54 KB
/
outputs_to_csv.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
"""
Converts track output pickle file metrics into a csv file with aggregate metrics
"""
import _pickle as pickle
import csv
import os
directories = {
"MOTA_SORT":"C:\\Users\\derek\\Desktop\\Results 2021 Detrac LBT\\DETRAC OUTPUTS 2021\\temp_outputs_sort",
"MOTA_KIOU":"C:\\Users\\derek\\Desktop\\Results 2021 Detrac LBT\\DETRAC OUTPUTS 2021\\temp_outputs_conf08",
"MOTA_SKIP":"C:\\Users\\derek\\Desktop\\Results 2021 Detrac LBT\\DETRAC OUTPUTS 2021\\temp_outputs_skip",
"MOTA_SKIP1_LOC":"C:\\Users\\derek\\Desktop\\Results 2021 Detrac LBT\\DETRAC OUTPUTS 2021\\temp_outputs_skip1",
"MOTA_SKIP2_LOC":"C:\\Users\\derek\\Desktop\\Results 2021 Detrac LBT\\DETRAC OUTPUTS 2021\\temp_outputs_skip2",
"MOTA_SKIP3_LOC":"C:\\Users\\derek\\Desktop\\Results 2021 Detrac LBT\\DETRAC OUTPUTS 2021\\temp_outputs_skip3",
"MOTA_SKIP4_LOC":"C:\\Users\\derek\\Desktop\\Results 2021 Detrac LBT\\DETRAC OUTPUTS 2021\\temp_outputs_skip4",
"MOTA_DOWNSAMPLE":"C:\\Users\\derek\\Desktop\\Results 2021 Detrac LBT\\DETRAC OUTPUTS 2021\\temp_outputs_test_downsampling",
"PRMOTA_TRAIN":"C:\\Users\\derek\\Desktop\\Results 2021 Detrac LBT\\DETRAC OUTPUTS 2021\\temp_outputs_train",
"PRMOTA_TEST":"C:\\Users\\derek\\Desktop\\Results 2021 Detrac LBT\\DETRAC OUTPUTS 2021\\temp_outputs_test_PRMOTA_1_9"
}
directories = {
"MOTA_SORT" :"/home/worklab/Data/cv/DETRAC OUTPUTS 2021/temp_outputs_sort",
"MOTA_KIOU" :"/home/worklab/Data/cv/DETRAC OUTPUTS 2021/temp_outputs_conf08",
"MOTA_SKIP" :"/home/worklab/Data/cv/DETRAC OUTPUTS 2021/temp_outputs_skip",
"MOTA_SKIP1_LOC" :"/home/worklab/Data/cv/DETRAC OUTPUTS 2021/temp_outputs_skip1",
"MOTA_SKIP2_LOC" :"/home/worklab/Data/cv/DETRAC OUTPUTS 2021/temp_outputs_skip2",
"MOTA_SKIP3_LOC" :"/home/worklab/Data/cv/DETRAC OUTPUTS 2021/temp_outputs_skip3",
"MOTA_SKIP4_LOC" :"/home/worklab/Data/cv/DETRAC OUTPUTS 2021/temp_outputs_skip4",
"MOTA_DOWNSAMPLE" :"/home/worklab/Data/cv/DETRAC OUTPUTS 2021/temp_outputs_test_downsampling",
"PRMOTA_TRAIN" :"/home/worklab/Data/cv/DETRAC OUTPUTS 2021/temp_outputs_train",
"PRMOTA_TEST" :"/home/worklab/Data/cv/DETRAC OUTPUTS 2021/temp_outputs_test_PRMOTA_1_9"
}
directories = {
"_TRAIN_IOU_SKIP0" : "/home/worklab/Documents/derek/detrac-lbt/results/rerun_skip_test",
"_TRAIN_IOU_SKIP1" : "/home/worklab/Documents/derek/detrac-lbt/results/rerun_skip_test",
"_TRAIN_IOU_SKIP2" : "/home/worklab/Documents/derek/detrac-lbt/results/rerun_skip_test",
"_TRAIN_IOU_SKIP3" : "/home/worklab/Documents/derek/detrac-lbt/results/rerun_skip_test",
"_TRAIN_IOU_SKIP4" : "/home/worklab/Documents/derek/detrac-lbt/results/rerun_skip_test",
"_TRAIN_IOU_SKIP5" : "/home/worklab/Documents/derek/detrac-lbt/results/rerun_skip_test",
}
#directories = {"PRTEST_IOU" : "/home/worklab/Documents/derek/detrac-lbt/results/PRMOTA_retest"}
#directories = {"SKIP_IOU" :"/home/worklab/Documents/derek/detrac-lbt/results/PR_MOTA_train_iou"}
directories = {"PRMOTA_TRAIN_SORT":"/home/worklab/Documents/derek/detrac-lbt/results/PR_MOTA_train_sort"}
directories = {"PRMOTA_TEST_SORT":"/home/worklab/Documents/derek/detrac-lbt/results/PR_MOTA_test_sort"}
directories = {
"_TRAIN_sort_SKIP0" : "/home/worklab/Documents/derek/detrac-lbt/results/TEST_skipping_sort",
"_TRAIN_sort_SKIP1" : "/home/worklab/Documents/derek/detrac-lbt/results/TEST_skipping_sort",
"_TRAIN_sort_SKIP2" : "/home/worklab/Documents/derek/detrac-lbt/results/TEST_skipping_sort",
"_TRAIN_sort_SKIP3" : "/home/worklab/Documents/derek/detrac-lbt/results/TEST_skipping_sort",
"_TRAIN_sort_SKIP4" : "/home/worklab/Documents/derek/detrac-lbt/results/TEST_skipping_sort",
"_TRAIN_sort_SKIP5" : "/home/worklab/Documents/derek/detrac-lbt/results/TEST_skipping_sort",
}
all_results = dict([(item,{}) for item in directories.keys()])
for key in directories:
path = directories[key]
for file in os.listdir(path):
file = os.path.join(path,file)
if "PR" in key:
det_step = int(file.split("_")[-3])
track_id = int(file.split("_")[-4])
conf = float(file.split("_")[-1].split(".cpkl")[0])
if track_id in [40712,40774,40773,40772,40771,40711,40792,40775,39361,40901]:
continue
# add conf information
track_id = "{}_{}".format(track_id,conf)
#det_step = "{}-{}".format(det_step,conf)
elif "DOWNSAMPLE" in key:
track_id = int(file.split("_")[-3])
det_step = float(file.split("_")[-1].split(".cpkl")[0]) # put ds ratio in det_step field so we can use the same code below
elif "SKIP" in key:
det_step = int(file.split("_")[-3])
track_id = int(file.split("_")[-4])
skip_step = int(file.split("_")[-2].split(".cpkl")[0])
if skip_step-1 != int(key.split("SKIP")[1]):
continue
else:
# get det_step
det_step = int(file.split("_")[-2].split(".cpkl")[0])
track_id = int(file.split("_")[-3])
try:
with open(file,"rb") as f:
(tracklets,metrics,time_metrics) = pickle.load(f)
except:
try:
with open(file,"rb") as f:
(tracklets,metrics,time_metrics,_) = pickle.load(f)
except:
continue
print(file)
# add tracks
try:
all_results[key][det_step][track_id] = (tracklets,metrics,time_metrics)
except:
all_results[key][det_step] = {track_id:(tracklets,metrics,time_metrics)}
#%%
agg = {}
for key in all_results:
agg[key] = {}
for det_step in all_results[key]:
agg[key][det_step] = {}
n = 0
aggregator = {}
for track_id in all_results[key][det_step]:
n += 1
for metric in all_results[key][det_step][track_id][1]:
try:
aggregator[metric] += all_results[key][det_step][track_id][1][metric][0]
except:
aggregator[metric] = all_results[key][det_step][track_id][1][metric][0]
for item in aggregator:
aggregator[item] = aggregator[item]/n
agg[key][det_step] = aggregator
#%%
with open('tracking_results.csv', mode='w') as f:
writer = csv.writer(f, delimiter=',', quoting=csv.QUOTE_MINIMAL)
for key in agg:
#write test titles
writer.writerow([key])
results = agg[key]
# write metric titles
all_metrics = ["det step"]
first_key = list(results.keys())[0]
for metric in results[first_key].keys():
all_metrics.append(metric)
writer.writerow(all_metrics)
# write actual results
det_steps = list(results.keys())
det_steps.sort()
for det_step in det_steps:
result = results[det_step]
line = [result[metric] for metric in result.keys()]
line = [det_step] + line
writer.writerow(line)
# blank line between tests for clarity
writer.writerow([])