forked from bradyz/2020_CARLA_challenge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcampaign_driver_mod.py
154 lines (139 loc) · 7.27 KB
/
campaign_driver_mod.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
import argparse
import os
import subprocess
WEATHER_CODENAME = {# Original weathers
"20 0 0 70 0 0 0 10 0": "clear-noon",
"100 100 100 70 0 100 10 70 0": "rain-noon",
"20 0 0 5 0 0 0 10 0": "clear-sunset",
"100 100 100 5 0 100 10 70 0": "rain-sunset",
"100 50 0 70 0 0 40 30 0": "haze-noon",
"100 50 0 5 0 0 40 30 0": "haze-sunset",
"20 0 0 -5 0 0 0 10 0": "clear-night",
"100 100 100 -5 0 100 10 70 0": "rain-night",
# Sun azimuth
"20 0 0 5 0 0 0 10 0": "clear-sunset-right",
"20 0 0 5 90 0 0 10 0": "clear-sunset-behind",
"20 0 0 5 180 0 0 10 0": "clear-sunset-left",
"20 0 0 5 270 0 0 10 0": "clear-sunset-front",
# Sun altitude
"20 0 0 50 0 0 0 10 0": "clear-50",
"20 0 0 30 0 0 0 10 0": "clear-30",
"20 0 0 10 0 0 0 10 0": "clear-10",
"20 0 0 5 0 0 0 10 0": "clear-sunset",
"20 0 0 3 0 0 0 10 0": "clear-3",
"20 0 0 1 0 0 0 10 0": "clear-1",
"20 0 0 -1 0 0 0 10 0": "clear--1",
"20 0 0 -3 0 0 0 10 0": "clear--3",
"20 0 0 -5 0 0 0 10 0": "clear-night",
# Rain
"20 20 20 5 0 20 5 20 0": "rain-sunset-20",
"40 40 40 5 0 40 10 30 0": "rain-sunset-40",
"60 60 60 5 0 60 15 40 0": "rain-sunset-60",
"80 80 80 5 0 80 20 50 0": "rain-sunset-80",
"100 100 100 5 0 100 25 60 0": "rain-sunset-100",
# Ice thickness
"20 0 0 70 0 10 0 10 10": "clear-noon-icy-10",
"20 0 0 70 0 30 0 10 30": "clear-noon-icy-30",
"20 0 0 70 0 70 0 10 70": "clear-noon-icy-70",
"20 0 0 70 0 100 0 10 100": "clear-noon-icy-100"}
def parse_routes(route_list_file):
ret = list()
if not os.path.isfile(route_list_file):
print("Abort, list of routes not found.")
return ret, ret
f = open(route_list_file, "r")
header = f.readline().strip().split(",")
for line in f:
line = line.strip().split(",")
ret.append(line)
return ret, header
def parse_weathers(weather_list_file):
ret = list()
if not os.path.isfile(weather_list_file):
print("Abort, list of weathers not found.")
return ret, ret
f = open(weather_list_file, "r")
header = f.readline().strip().split(",")
for line in f:
line = " ".join(line.strip().split(","))
ret.append(line)
return ret, header
def launch_subprocess(cmd):
print("launching command:", cmd)
try:
subprocess.check_output(cmd, shell=True)
except Exception as e:
print("error running cmd, exception {}".format(e))
def run_campaign(route_list_file, weather_list_file, output_folder):
routes, header = parse_routes(route_list_file)
weathers, wea_header = parse_weathers(weather_list_file)
if len(routes) == 0:
print("Abort, no routes to run.")
return
cmd_base = "python3 leaderboard/leaderboard/leaderboard_evaluator.py --track=SENSORS --agent=image_agent --port "+os.environ['PORT']+" --trafficManagerSeed=0"
if len(weathers) != 0:
for route_tuple in routes:
for weather in weathers:
for i in range(1):
agent_weight = route_tuple[1]
scenario = route_tuple[2]
route = route_tuple[0]
print("\n=====>starts running<=====")
for head, config in zip(header, route_tuple):
print("{}: {}".format(head, config))
for head, config in zip(wea_header, weather.split(" ")):
print("{}: {}".format(head, config))
subpath = "{}_{}_{}_{}_{}".format((route.split(".")[0]).split("/")[-1], agent_weight.split(".")[0],WEATHER_CODENAME[weather],scenario.split(".")[0],str(i))
suboutput_folder = os.path.join(output_folder, subpath)
if not os.path.isdir(suboutput_folder):
os.mkdir(suboutput_folder)
checkpoint = os.path.join(suboutput_folder, ((route.split("/")[-1]).split("."))[0]+".txt")
print("output folder:", suboutput_folder)
cmd = cmd_base + " --routes=leaderboard/data/{} --agent-config={} --checkpoint={} \
--weather_params {} --scenarios=leaderboard/data/{} --log_path={}".format(route, agent_weight, checkpoint, weather, scenario, suboutput_folder)
print(weather)
if not os.path.isdir(suboutput_folder):
os.mkdir(suboutput_folder)
if os.path.isfile(suboutput_folder + os.sep + "run.done"):
print("already finished continue, remove run.done file or output folder to force rerun")
continue
try:
launch_subprocess(cmd)
except:
continue
ofh = open(suboutput_folder + os.sep + "run.done", 'w')
ofh.close()
print("------done running------")
else:
for route_tuple in routes:
agent_weight = route_tuple[1]
scenario = route_tuple[2]
route = route_tuple[0]
print("\n=====>starts running<=====")
for head, config in zip(header, route_tuple):
print("{}: {}".format(head, config))
subpath = "{}_{}_{}".format((route.split(".")[0]).split("/")[-1], agent_weight.split(".")[0], scenario.split(".")[0])
suboutput_folder = os.path.join(output_folder, subpath)
print("output folder:", suboutput_folder)
checkpoint = os.path.join(suboutput_folder, ((route.split("/")[-1]).split("."))[0]+".txt")
cmd = cmd_base + " --routes=leaderboard/data/{} --agent-config={} --checkpoint={} \
--scenarios=leaderboard/data/{} --log_path={}".format(route, agent_weight, checkpoint, scenario, suboutput_folder)
if not os.path.isdir(suboutput_folder):
os.mkdir(suboutput_folder)
if os.path.isfile(suboutput_folder + os.sep + "run.done"):
print("already finished continue, remove run.done file to force rerun")
continue
try:
launch_subprocess(cmd)
except:
continue
ofh = open(suboutput_folder + os.sep + "run.done", 'w')
ofh.close()
print("------done running------")
if __name__ == "__main__":
parser = argparse.ArgumentParser("campaign launcher")
parser.add_argument("--routes_list", type=str, required=True)
parser.add_argument("--output_dir", type=str, required=True)
parser.add_argument("--weathers_list", type=str, required=False, default="")
args = parser.parse_args()
run_campaign(args.routes_list, args.weathers_list, args.output_dir)