-
Notifications
You must be signed in to change notification settings - Fork 18
/
bayesian_merger.py
38 lines (30 loc) · 1021 Bytes
/
bayesian_merger.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
from pathlib import Path
import hydra
from omegaconf import DictConfig
from sd_webui_bayesian_merger import ATPEOptimiser, BayesOptimiser, TPEOptimiser
from sd_webui_bayesian_merger.artist import draw_unet
@hydra.main(version_base=None, config_path="conf", config_name="config")
def main(cfg: DictConfig) -> None:
if cfg["draw_unet_weights"] and cfg["draw_unet_base_alpha"]:
weights = list(map(float, cfg["draw_unet_weights"].split(",")))
draw_unet(
cfg["draw_unet_base_alpha"],
weights,
Path(cfg["model_a"]).stem,
Path(cfg["model_b"]).stem,
"./unet.png",
)
return
if cfg["optimiser"] == "bayes":
cls = BayesOptimiser
elif cfg["optimiser"] == "tpe":
cls = TPEOptimiser
elif cfg["optimiser"] == "atpe":
cls = ATPEOptimiser
else:
exit(f"Invalid optimiser:{cfg['optimiser']}")
bo = cls(cfg)
bo.optimise()
bo.postprocess()
if __name__ == "__main__":
main()