-
Notifications
You must be signed in to change notification settings - Fork 20
/
carla_data_gen.py
138 lines (116 loc) · 3.97 KB
/
carla_data_gen.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
import argparse
import logging
import carla
import pygame
from data_generation.data_generator import DataGenerator
from data_generation.keyboard_control import KeyboardControl
def game_loop(args):
pygame.init()
pygame.font.init()
data_generator = None
try:
client = carla.Client(args.host, args.port)
client.set_timeout(5.0)
logging.info('Load Map %s', args.map)
carla_world = client.load_world(args.map)
carla_world.unload_map_layer(carla.MapLayer.ParkedVehicles)
data_generator = DataGenerator(carla_world, args)
controller = KeyboardControl(data_generator.world)
display = pygame.display.set_mode(
(args.width, args.height),
pygame.HWSURFACE | pygame.DOUBLEBUF)
clock = pygame.time.Clock()
while True:
data_generator.world_tick()
clock.tick_busy_loop(60)
if controller.parse_events(client, data_generator.world, clock):
return
data_generator.tick(clock)
data_generator.render(display)
pygame.display.flip()
finally:
if data_generator:
client.stop_recorder()
if data_generator is not None:
data_generator.destroy()
pygame.quit()
def str2bool(v):
if v.lower() in ('yes', 'true', 'True', 't', 'y', '1'):
return True
elif v.lower() in ('no', 'false', 'False', 'f', 'n', '0'):
return False
else:
raise argparse.ArgumentTypeError('Unsupported value encountered.')
def main():
argparser = argparse.ArgumentParser(
description='CARLA Data Generation')
argparser.add_argument(
'-v', '--verbose',
action='store_true',
dest='debug',
help='print debug information')
argparser.add_argument(
'--host',
metavar='H',
default='127.0.0.1',
help='IP of the host server (default: 127.0.0.1)')
argparser.add_argument(
'-p', '--port',
metavar='P',
default=2000,
type=int,
help='TCP port to listen to (default: 2000)')
argparser.add_argument(
'--res',
metavar='WIDTHxHEIGHT',
default='860x480',
help='window resolution (default: 860x480)')
argparser.add_argument(
'--gamma',
default=0.0,
type=float,
help='Gamma correction of the camera (default: 0.0)')
argparser.add_argument(
'--save_path',
default='./e2e_parking/',
help='path to save sensor data (default: ./e2e_parking/)')
argparser.add_argument(
'--task_num',
default=16,
type=int,
help='number of parking task (default: 16')
argparser.add_argument(
'--map',
default='Town04_Opt',
help='map of carla (default: Town04_Opt)',
choices=['Town04_Opt', 'Town05_Opt'])
argparser.add_argument(
'--shuffle_veh',
default=True,
type=str2bool,
help='shuffle static vehicles between tasks (default: True)')
argparser.add_argument(
'--shuffle_weather',
default=False,
type=str2bool,
help='shuffle weather between tasks (default: False)')
argparser.add_argument(
'--random_seed',
default=0,
help='random seed to initialize env; if sets to 0, use current timestamp as seed (default: 0)')
argparser.add_argument(
'--bev_render_device',
default='cpu',
help='device used for BEV Rendering (default: cpu)',
choices=['cpu', 'cuda'])
args = argparser.parse_args()
args.width, args.height = [int(x) for x in args.res.split('x')]
log_level = logging.DEBUG if args.debug else logging.INFO
logging.basicConfig(format='%(levelname)s: %(message)s', level=log_level)
logging.info('listening to server %s:%s', args.host, args.port)
try:
game_loop(args)
except KeyboardInterrupt:
logging.info('Cancelled by user. Bye!')
if __name__ == '__main__':
main()