-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathoffline_mapping_query.py
More file actions
187 lines (167 loc) · 9.3 KB
/
offline_mapping_query.py
File metadata and controls
187 lines (167 loc) · 9.3 KB
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 27 22:38:20 2022
@author: Tom Bu
"""
import os
import shutil
import pandas as pd
import matplotlib.pyplot as plt
from datetime import datetime
from utils.dynamic_obj_mask import generate_masks
from utils.automate_registration import sfm
from utils.offline_detections import get_det
from utils.offline_query_eval import get_eval
from utils.automate_observability import get_observability
from utils.automate_localization_check import get_well_localized_imgs
from utils.automate_change_gt import get_change_gt
from utils.eval_metrics import metrics
class dated_config:
def __init__(self, day = 'None'):
self.model_path = "./model/crosswalk_detector/model_final.pth"
self.sfm_path = 'dataset/'
self.sfm_query_path = self.sfm_path + '{}/query/' + day + '/'
self.sfm_img_path = self.sfm_query_path + 'images'
self.sfm_mask_path = self.sfm_query_path + 'mask'
self.sfm_sparse_path = self.sfm_query_path + 'sparse'
self.sfm_sparse_experiment = self.sfm_sparse_path + '/{}'
self.sfm_offline_path = self.sfm_path + '{}/sparse/plane_segmentation'
class exp_tracker:
def __init__(self):
self.metrics_any = {'ref':[], 'obs':[], 'loc':[], 'empty':[], 'precision':[], 'recall':[], 'accuracy':[], 'fpr':[], 'f1':[], 'no_c precision':[]}
self.metrics_int = {'ref':[], 'obs':[], 'loc':[], 'empty':[], 'precision':[], 'recall':[], 'accuracy':[], 'fpr':[], 'f1':[], 'no_c precision':[]}
def update(self, exp, result):
for metrics, category in [[self.metrics_any,'any_change_cw'], [self.metrics_int, 'any_change_intersection']]:
if exp['ref_polygon'] == 'map':
metrics['ref'].append('map')
else:
metrics['ref'].append('sensor')
if exp['observable_check']:
metrics['obs'].append('x')
else:
metrics['obs'].append(' ')
if exp['localization_check']:
metrics['loc'].append('x')
else:
metrics['loc'].append(' ')
if exp['pretend_empty_map']:
metrics['empty'].append('x')
else:
metrics['empty'].append(' ')
metrics['precision'].append(result[category]['precision'])
metrics['recall'].append(result[category]['recall'])
metrics['accuracy'].append(result[category]['accuracy'])
metrics['fpr'].append(result[category]['fpr'])
metrics['f1'].append(result[category]['f1'])
metrics['no_c precision'].append(result[category]['no change precision'])
def show(self):
df = pd.DataFrame.from_dict(self.metrics_any)
df = df.round(3)
print(df.to_latex(index=False))
df = pd.DataFrame.from_dict(self.metrics_existing)
df = df.round(3)
print(df.to_latex(index=False))
df = pd.DataFrame.from_dict(self.metrics_int)
df = df.round(3)
print(df.to_latex(index=False))
intersection_li = [
'cw_0_267',
'cw_0_87',
'cw_10_210',
'cw_10_87',
'cw_11_213',
'cw_11_33',
'cw_12_210',
'cw_12_31',
'cw_13_208',
'cw_13_30',
'cw_14_210',
'cw_14_22',
'cw_15_255',
'cw_15_31',
'cw_16_269',
'cw_16_73',
'cw_18_260',
'cw_19_251',
'cw_3_71',
'cw_4_72',
'cw_5_171',
'cw_5_36',
'cw_6_219',
'cw_6_327',
'cw_7_214',
'cw_7_291',
'cw_8_105',
'cw_8_290',
'cw_9_109',
'cw_9_217'
]
experiment_li = [
# {'ref_polygon':'sensor', 'observable_check':False, 'localization_check':False, 'pretend_empty_map':False},
# {'ref_polygon':'sensor', 'observable_check':True, 'localization_check':False, 'pretend_empty_map':False},
# {'ref_polygon':'sensor', 'observable_check':False, 'localization_check':True, 'pretend_empty_map':False},
{'ref_polygon':'sensor', 'observable_check':True, 'localization_check':True, 'pretend_empty_map':False},
# {'ref_polygon':'map', 'observable_check':False, 'localization_check':False, 'pretend_empty_map':False},
# {'ref_polygon':'map', 'observable_check':True, 'localization_check':False, 'pretend_empty_map':False},
# {'ref_polygon':'map', 'observable_check':False, 'localization_check':True, 'pretend_empty_map':False},
# {'ref_polygon':'map', 'observable_check':True, 'localization_check':True, 'pretend_empty_map':False},
# {'ref_polygon':'sensor', 'observable_check':False, 'localization_check':False, 'pretend_empty_map':True},
# {'ref_polygon':'sensor', 'observable_check':True, 'localization_check':False, 'pretend_empty_map':True},
# {'ref_polygon':'sensor', 'observable_check':False, 'localization_check':True, 'pretend_empty_map':True},
# {'ref_polygon':'sensor', 'observable_check':True, 'localization_check':True, 'pretend_empty_map':True},
# {'ref_polygon':'map', 'observable_check':False, 'localization_check':False, 'pretend_empty_map':True},
# {'ref_polygon':'map', 'observable_check':True, 'localization_check':False, 'pretend_empty_map':True},
# {'ref_polygon':'map', 'observable_check':False, 'localization_check':True, 'pretend_empty_map':True},
# {'ref_polygon':'map', 'observable_check':True, 'localization_check':True, 'pretend_empty_map':True},
]
#keep track of multiple experiments
tracker = exp_tracker()
failed = []
for x in experiment_li:
ref_polygon, observable_check, localization_check, pretend_empty_map = x['ref_polygon'], x['observable_check'], x['localization_check'], x['pretend_empty_map']
experiment = 'base'
experiment += '_' + ref_polygon
if observable_check:
experiment += '_obs'
if localization_check:
experiment += '_loc'
if pretend_empty_map:
experiment += '_pretendEmptyMap'
#keep track of one experiment
m = metrics()
for group in intersection_li:
days = sorted(os.listdir(os.path.join(dated_config().sfm_path, group, 'query')))
for date in days:
config = dated_config(date)
os.makedirs(os.path.join(config.sfm_sparse_experiment.format(group, experiment)), exist_ok=True)
#if the result exists, continue
if os.path.exists(os.path.join(config.sfm_sparse_experiment.format(group, experiment), 'change.pkl')):
print('succeed previously {} {} {}'.format(group, date, experiment))
continue
try:
#common across all experiments
if not os.path.exists(config.sfm_mask_path.format(group)) or len(os.listdir(config.sfm_mask_path.format(group))) != len(os.listdir(config.sfm_img_path.format(group))) or len(os.listdir(config.sfm_mask_path.format(group) + '/query')) != len(os.listdir(config.sfm_img_path.format(group) + '/query')):
generate_masks(config.sfm_img_path.format(group), config.sfm_mask_path.format(group))
if not os.path.exists(os.path.join(config.sfm_sparse_path.format(group), 'points3D.txt')):
sfm(config.sfm_img_path.format(group), config.sfm_mask_path.format(group), config.sfm_sparse_path.format(group), config.sfm_offline_path.format(group))
# do your verifications here (visibility, proper localization, detections outside of the intersection)
if localization_check:
percent = get_well_localized_imgs(config.sfm_img_path.format(group), config.sfm_sparse_path.format(group))
else:
percent = -1
get_change_gt(os.path.join(config.sfm_sparse_experiment.format(group, experiment)), group, ref_polygon, pretend_empty_map, query_time = datetime.strptime(date, '%Y_%m_%d').strftime("%m/%d/%y"))
#this will change the label based on observability
obs = get_observability(config.sfm_img_path.format(group), config.sfm_mask_path.format(group), config.sfm_sparse_path.format(group), config.sfm_offline_path.format(group), localization_check, experiment = experiment)
if (localization_check and not os.path.exists(os.path.join(config.sfm_sparse_path.format(group), 'localization_query_det.pkl'))) or (not localization_check and not os.path.exists(os.path.join(config.sfm_sparse_path.format(group), 'query_det.pkl'))):
get_det(config.sfm_sparse_path.format(group), config.sfm_sparse_path.format(group), config.sfm_img_path.format(group), config.model_path, ref = False, debug = True, localization_check = localization_check)
get_eval(config.sfm_sparse_path.format(group), experiment, localization_check)
plt.close('all')
m.update(os.path.join(config.sfm_sparse_experiment.format(group, experiment), 'change.pkl'))
print('succeed {} {} {}'.format(group, date, experiment))
except:
failed.append([group, date])
print('failed {} {} {}'.format(group, date, experiment))
result = m.show()
tracker.update(x, result)
tracker.show()