forked from erdos-project/pylot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdata_gatherer.py
321 lines (281 loc) · 13.9 KB
/
data_gatherer.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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
import signal
from absl import app, flags
import erdos
import pylot.flags
import pylot.operator_creator
import pylot.simulation.utils
import pylot.utils
from pylot.drivers.sensor_setup import DepthCameraSetup, RGBCameraSetup, \
SegmentedCameraSetup
FLAGS = flags.FLAGS
# Flags that control what data is recorded.
flags.DEFINE_bool('log_rgb_camera', False,
'True to enable center camera RGB logging')
flags.DEFINE_bool('log_segmented_camera', False,
'True to enable center segmented camera logging')
flags.DEFINE_bool('log_left_right_cameras', False,
'Control whether we log left and right cameras.')
flags.DEFINE_bool('log_depth_camera', False,
'True to enable depth camera logging')
flags.DEFINE_bool('log_gnss', False, 'Enable logging of GNSS measurements.')
flags.DEFINE_bool('log_pose', False, 'Enable logging of pose measurements.')
flags.DEFINE_bool('log_imu', False, 'Enable logging of IMU measurements.')
flags.DEFINE_bool('log_lidar', False, 'True to enable lidar logging')
flags.DEFINE_bool('log_obstacles', False,
'True to enable obstacle bounding box logging')
flags.DEFINE_bool(
'log_traffic_lights', False,
'True to enable traffic lights bounding box and camera logging')
flags.DEFINE_bool('log_multiple_object_tracker', False,
'True to enable logging in the MOT format')
flags.DEFINE_bool('log_trajectories', False,
'True to enable trajectory logging')
flags.DEFINE_bool('log_chauffeur', False,
'True to log data in ChauffeurNet style.')
flags.DEFINE_bool('log_top_down_segmentation', False,
'True to enable logging of top down segmentation')
# The location of the center camera relative to the ego-vehicle.
CENTER_CAMERA_LOCATION = pylot.utils.Location(1.0, 0.0, 1.8)
def main(argv):
transform = pylot.utils.Transform(CENTER_CAMERA_LOCATION,
pylot.utils.Rotation())
control_loop_stream = erdos.LoopStream()
release_sensor_stream = erdos.IngestStream()
pipeline_finish_notify_stream = erdos.IngestStream()
# Create an operator that connects to the simulator.
(
pose_stream,
pose_stream_for_control,
ground_traffic_lights_stream,
ground_obstacles_stream,
ground_speed_limit_signs_stream,
ground_stop_signs_stream,
vehicle_id_stream,
open_drive_stream,
global_trajectory_stream,
) = pylot.operator_creator.add_simulator_bridge(
control_loop_stream, release_sensor_stream,
pipeline_finish_notify_stream)
# Add sensors.
rgb_camera_setup = RGBCameraSetup('center_camera',
FLAGS.camera_image_width,
FLAGS.camera_image_height, transform,
FLAGS.camera_fov)
(center_camera_stream, notify_rgb_stream) = \
pylot.operator_creator.add_camera_driver(
rgb_camera_setup, vehicle_id_stream, release_sensor_stream)
depth_camera_setup = DepthCameraSetup('depth_center_camera',
FLAGS.camera_image_width,
FLAGS.camera_image_height, transform,
FLAGS.camera_fov)
(depth_camera_stream,
_) = pylot.operator_creator.add_camera_driver(depth_camera_setup,
vehicle_id_stream,
release_sensor_stream)
seg_camera_setup = SegmentedCameraSetup('seg_center_camera',
FLAGS.camera_image_width,
FLAGS.camera_image_height,
transform, FLAGS.camera_fov)
(segmented_stream,
_) = pylot.operator_creator.add_camera_driver(seg_camera_setup,
vehicle_id_stream,
release_sensor_stream)
if FLAGS.log_rgb_camera:
pylot.operator_creator.add_camera_logging(
center_camera_stream, 'center_camera_logger_operator', 'center')
if FLAGS.log_segmented_camera:
pylot.operator_creator.add_camera_logging(
segmented_stream, 'center_segmented_camera_logger_operator',
'segmented')
if FLAGS.log_depth_camera:
pylot.operator_creator.add_camera_logging(
depth_camera_stream, 'depth_camera_logger_operator', 'depth')
imu_stream = None
if FLAGS.log_imu:
(imu_stream, _) = pylot.operator_creator.add_imu(
pylot.utils.Transform(location=pylot.utils.Location(),
rotation=pylot.utils.Rotation()),
vehicle_id_stream)
pylot.operator_creator.add_imu_logging(imu_stream)
gnss_stream = None
if FLAGS.log_gnss:
(gnss_stream, _) = pylot.operator_creator.add_gnss(
pylot.utils.Transform(location=pylot.utils.Location(),
rotation=pylot.utils.Rotation()),
vehicle_id_stream)
pylot.operator_creator.add_gnss_logging(gnss_stream)
if FLAGS.log_pose:
pylot.operator_creator.add_pose_logging(pose_stream)
traffic_lights_stream = None
traffic_light_camera_stream = None
if FLAGS.log_traffic_lights:
tl_camera_setup = RGBCameraSetup('traffic_light_camera',
FLAGS.camera_image_width,
FLAGS.camera_image_height, transform,
45)
(traffic_light_camera_stream, _) = \
pylot.operator_creator.add_camera_driver(
tl_camera_setup, vehicle_id_stream, release_sensor_stream)
pylot.operator_creator.add_camera_logging(
traffic_light_camera_stream,
'traffic_light_camera_logger_operator', 'traffic-light')
tl_seg_camera_setup = SegmentedCameraSetup(
'traffic_light_segmented_camera', FLAGS.camera_image_width,
FLAGS.camera_image_height, transform, 45)
(traffic_light_segmented_camera_stream, _) = \
pylot.operator_creator.add_camera_driver(
tl_seg_camera_setup,
vehicle_id_stream,
release_sensor_stream)
tl_depth_camera_setup = DepthCameraSetup('traffic_light_depth_camera',
FLAGS.camera_image_width,
FLAGS.camera_image_height,
transform, 45)
(traffic_light_depth_camera_stream, _) = \
pylot.operator_creator.add_camera_driver(
tl_depth_camera_setup, vehicle_id_stream,
release_sensor_stream)
traffic_lights_stream = \
pylot.operator_creator.add_perfect_traffic_light_detector(
ground_traffic_lights_stream,
traffic_light_camera_stream,
traffic_light_depth_camera_stream,
traffic_light_segmented_camera_stream,
pose_stream)
pylot.operator_creator.add_bounding_box_logging(
traffic_lights_stream, 'tl-bboxes')
if FLAGS.log_left_right_cameras:
(left_camera_stream, right_camera_stream, _,
_) = pylot.operator_creator.add_left_right_cameras(
transform, vehicle_id_stream, release_sensor_stream)
pylot.operator_creator.add_camera_logging(
left_camera_stream, 'left_camera_logger_operator', 'left')
pylot.operator_creator.add_camera_logging(
right_camera_stream, 'right_camera_logger_operator', 'right')
point_cloud_stream = None
if FLAGS.log_lidar:
(point_cloud_stream, _,
_) = pylot.operator_creator.add_lidar(transform, vehicle_id_stream,
release_sensor_stream)
pylot.operator_creator.add_lidar_logging(point_cloud_stream)
obstacles_stream = None
if FLAGS.log_obstacles:
obstacles_stream = pylot.operator_creator.add_perfect_detector(
depth_camera_stream, center_camera_stream, segmented_stream,
pose_stream, ground_obstacles_stream,
ground_speed_limit_signs_stream, ground_stop_signs_stream)
pylot.operator_creator.add_bounding_box_logging(
obstacles_stream, 'bboxes')
if FLAGS.log_multiple_object_tracker:
pylot.operator_creator.add_multiple_object_tracker_logging(
obstacles_stream)
obstacles_tracking_stream = None
if FLAGS.log_trajectories or FLAGS.log_chauffeur:
obstacles_tracking_stream = \
pylot.operator_creator.add_perfect_tracking(
vehicle_id_stream,
ground_obstacles_stream,
pose_stream)
if FLAGS.log_trajectories:
pylot.operator_creator.add_trajectory_logging(
obstacles_tracking_stream)
top_down_segmented_stream = None
top_down_camera_setup = None
if FLAGS.log_chauffeur or FLAGS.log_top_down_segmentation:
top_down_transform = pylot.utils.get_top_down_transform(
transform, FLAGS.top_down_camera_altitude)
top_down_seg_cs = SegmentedCameraSetup('top_down_segmented_camera',
FLAGS.camera_image_width,
FLAGS.camera_image_height,
top_down_transform, 90)
(top_down_segmented_stream, _) = \
pylot.operator_creator.add_camera_driver(
top_down_seg_cs,
vehicle_id_stream,
release_sensor_stream)
if FLAGS.log_top_down_segmentation:
pylot.operator_creator.add_camera_logging(
top_down_segmented_stream,
'top_down_segmented_logger_operator', 'top-down-segmented')
if FLAGS.log_chauffeur:
top_down_camera_setup = RGBCameraSetup('top_down_rgb_camera',
FLAGS.camera_image_width,
FLAGS.camera_image_height,
top_down_transform, 90)
(top_down_camera_stream,
_) = pylot.operator_creator.add_camera_driver(
top_down_camera_setup, vehicle_id_stream,
release_sensor_stream)
pylot.operator_creator.add_chauffeur_logging(
vehicle_id_stream, pose_stream, obstacles_tracking_stream,
top_down_camera_stream, top_down_segmented_stream,
top_down_camera_setup)
perfect_lane_stream = None
if FLAGS.log_lane_detection_camera:
perfect_lane_stream = pylot.operator_creator.add_perfect_lane_detector(
pose_stream, open_drive_stream, center_camera_stream)
# TODO: Hack! We synchronize on a single stream, based on a guesestimate
# of which stream is slowest. Instead, We should synchronize on all output
# streams, and we should ensure that even the operators without output
# streams complete.
if FLAGS.control == 'simulator_auto_pilot':
# We insert a synchronizing operator that sends back a command when
# the low watermark progresses on all input stream.
stream_to_sync_on = center_camera_stream
if obstacles_tracking_stream is not None:
stream_to_sync_on = obstacles_tracking_stream
if traffic_lights_stream is not None:
stream_to_sync_on = traffic_lights_stream
if perfect_lane_stream is not None:
stream_to_sync_on = perfect_lane_stream
if obstacles_stream is not None:
stream_to_sync_on = obstacles_stream
control_stream = pylot.operator_creator.add_synchronizer(
vehicle_id_stream, stream_to_sync_on)
control_loop_stream.set(control_stream)
else:
raise ValueError(
"Must be in auto pilot mode. Pass --control=simulator_auto_pilot")
control_display_stream = None
streams_to_send_top_on = []
if pylot.flags.must_visualize():
control_display_stream, ingest_streams = \
pylot.operator_creator.add_visualizer(
pose_stream=pose_stream,
camera_stream=center_camera_stream,
tl_camera_stream=traffic_light_camera_stream,
depth_stream=depth_camera_stream,
point_cloud_stream=point_cloud_stream,
segmentation_stream=segmented_stream,
imu_stream=imu_stream,
obstacles_stream=obstacles_stream,
traffic_lights_stream=traffic_lights_stream,
tracked_obstacles_stream=obstacles_tracking_stream)
streams_to_send_top_on += ingest_streams
# Connect an instance to the simulator to make sure that we can turn the
# synchronous mode off after the script finishes running.
client, world = pylot.simulation.utils.get_world(FLAGS.simulator_host,
FLAGS.simulator_port,
FLAGS.simulator_timeout)
# Run the data-flow.
node_handle = erdos.run_async()
signal.signal(signal.SIGINT, shutdown)
# Ask all sensors to release their data.
release_sensor_stream.send(
erdos.WatermarkMessage(erdos.Timestamp(is_top=True)))
for stream in streams_to_send_top_on:
stream.send(erdos.WatermarkMessage(erdos.Timestamp(is_top=True)))
try:
if pylot.flags.must_visualize():
pylot.utils.run_visualizer_control_loop(control_display_stream)
node_handle.wait()
except KeyboardInterrupt:
node_handle.shutdown()
pylot.simulation.utils.set_asynchronous_mode(world)
if pylot.flags.must_visualize():
import pygame
pygame.quit()
def shutdown(sig, frame):
raise KeyboardInterrupt
if __name__ == '__main__':
app.run(main)