forked from uwdb/visualroad
-
Notifications
You must be signed in to change notification settings - Fork 1
/
driver.py
executable file
·210 lines (157 loc) · 5.09 KB
/
driver.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
#!/usr/bin/python3
import random
import os
import glob
import argparse
import logging
from common import *
def remove_key(d, key):
del d[key]
return d
def get_license_plates(cache=[]):
if len(cache) == 0:
cache += map(lambda fn: os.path.splitext(os.path.basename(fn))[0],
glob.glob(os.path.join(os.path.expanduser(LICENSEPLATE_TEXTURE_PATH), '*.uasset')))
return cache
def get_all_traffic_video_paths(scale):
return ['traffic-%03d.mp4' % id for id in range(scale * TRAFFIC_CAMERAS_PER_TILE)]
def get_random_traffic_video_path(scale):
return random.choice(get_all_traffic_video_paths(scale))
def get_panoramic_video_paths(id):
return ['panoramic-%03d-%03d.mp4' % (id, index) for index in range(PANORAMIC_CAMERAS_PER_TILE)]
def get_random_caption_path():
return 'captions'
def get_random_license_plate():
return random.choice(get_license_plates()).strip()
def query1(scale, resolution, duration):
x1 = random.randint(0, resolution[0] - 1)
y1 = random.randint(0, resolution[1] - 1)
t1 = random.randint(0, duration - 1)
return {
'path': get_random_traffic_video_path(scale),
'x': (x1, random.randint(x1+1, resolution[0])),
'y': (y1, random.randint(y1+1, resolution[1])),
't': (t1, random.randint(t1+1, duration))
}
def query2a(scale, *args):
return {
'path': get_random_traffic_video_path(scale),
}
def query2b(scale, *args):
return {
'path': get_random_traffic_video_path(scale),
'd': random.randint(3, 20)
}
def query2c(scale, *args):
return {
'path': get_random_traffic_video_path(scale),
'A': 'YOLO',
'O': random.choice(['Pedestrian', 'Vehicle'])
}
def query2d(scale, *args):
return {
'path': get_random_traffic_video_path(scale),
'm': random.randint(2, 60),
'epsilon': random.random()
}
def query3(scale, resolution, *args):
return {
'path': get_random_traffic_video_path(scale),
'dx': int(resolution[0] / (2 ** random.randint(1, 3))),
'dy': int(resolution[1] / (2 ** random.randint(1, 3))),
'B': int(2 ** random.randint(16, 22)),
}
def query4(scale, *args):
return {
'path': get_random_traffic_video_path(scale),
'alpha': 2 ** random.randint(1, 5),
'beta': 2 ** random.randint(1, 5)
}
def query5(scale, *args):
return {
'path': get_random_traffic_video_path(scale),
'alpha': 2 ** random.randint(1, 5),
'beta': 2 ** random.randint(1, 5)
}
def query6a(scale, *args):
return query2c(scale)
def query6b(scale, *args):
return {
'path': get_random_traffic_video_path(scale),
'caption_path': get_random_caption_path()
}
def query7(scale, *args):
return {
'paths': get_all_traffic_video_paths(scale),
'q2c': remove_key(query2c(scale), "path"),
'q6a': remove_key(query6a(scale), "path"),
'q2d': remove_key(query2d(scale), "path")
}
def query8(scale, *args):
return {
'paths': get_all_traffic_video_paths(scale),
'l': get_random_license_plate(),
'L': 'OpenAPLR'
}
def query9(scale, *args):
return {
'panorama' + str(id): get_panoramic_video_paths(id)
for id in range(scale * PANORAMIC_CAMERAS_PER_TILE)
}
def query10(scale, *args):
bl = random.randint(16, 21)
return {**{'bl': bl,
'bh': random.randint(bl + 1, 22),
'q5': remove_key(query5(scale), "path")},
**{'panorama' + str(id): get_panoramic_video_paths(id)
for id in range(scale * PANORAMIC_CAMERAS_PER_TILE)}
}
queries = {
'1': query1,
'2a': query2a,
'2b': query2b,
'2c': query2c,
'2d': query2d,
'3': query3,
'4': query4,
'5': query5,
'6a': query6a,
'6b': query6b,
'7': query7,
'8': query8,
'9': query9,
'10': query10
}
def create_batch(id, scale, resolution, duration):
batch = {
'query': id,
'batch': [{'query': queries[id](scale, resolution, duration)}
for _ in range(scale * QUERIES_PER_TILE)]
}
return batch #{'batch': batch}
def benchmark(path, scale, resolution, duration):
result = {'source': path, 'batches': []}
for id in queries.keys():
result['batches'].append(create_batch(id, scale, resolution, duration))
return yaml.safe_dump(result)
if __name__ == '__main__':
logging.basicConfig(level=logging.INFO)
parser = argparse.ArgumentParser()
parser.add_argument(
'-r', '--seed',
metavar='R',
default=0,
type=int,
help='Random number generator seed')
parser.add_argument(
'path',
type=str,
help='Video dataset path')
args = parser.parse_args()
if args.seed:
random.seed(args.seed)
configuration = load_configuration(args.path)
print(benchmark(args.path,
configuration['scale'],
(configuration['resolution']['width'], configuration['resolution']['height']),
configuration['duration']))