forked from bradyz/2020_CARLA_challenge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcampaign_driver.py
executable file
·121 lines (108 loc) · 5.42 KB
/
campaign_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
import argparse
import os
import subprocess
WEATHER_CODENAME = {"20 0 0 70 0 0 0 10": "clear-noon",
"100 100 100 70 0 100 10 70": "rain-noon",
"20 0 0 5 0 0 0 10": "clear-sunset",
"100 100 100 5 0 100 10 70": "rain-sunset",
"100 50 0 70 0 0 40 30": "haze-noon",
"100 50 0 5 0 0 40 30": "haze-sunset",
"20 0 0 -5 0 0 0 10": "clear-night",
"100 100 100 -5 0 100 10 70": "rain-night"}
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:
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])
suboutput_folder = os.path.join(output_folder, subpath)
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)
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)