-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptim_nbv_params.py
More file actions
35 lines (26 loc) · 1.03 KB
/
Copy pathoptim_nbv_params.py
File metadata and controls
35 lines (26 loc) · 1.03 KB
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
import subprocess
import optuna
from gcngrasp import Path
from gcngrasp.api.utils.bayes_opt import BayesOpt
CFG_SRC = Path("config/system/params.yaml")
CFG_DST = Path("runs/tmp.yaml")
def objective(trial: optuna.Trial):
cfg = CFG_SRC.yaml()
for name in ["occ", "elev"]:
cfg["planner"]["loss_weight"][name] = trial.suggest_float(name, 0, 2, step=.1)
if trial.should_prune(): raise optuna.TrialPruned()
CFG_DST.yaml(cfg)
result = subprocess.run(
["python", "main_nbv.py", "--config", CFG_DST], # , "--n-seed", "1"],
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL
)
if result.returncode: return
folder = sorted(Path("runs/nbv_logs").iterdir())[-1]
ret = sum([f.yaml()["avg"]["AP"][1:3] for f in folder.rglob("results.yaml")], [])
return sum(ret) / len(ret)
if __name__ == '__main__':
opt = BayesOpt(Path("runs/bayes.bin"), next_param={'occ': 0.6, 'elev': 0.2})
print(opt.dataframe)
print(opt.best)
opt(objective, 100)
opt.dataframe.to_csv("runs/bayes.csv")