-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
59 lines (46 loc) · 1.46 KB
/
main.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
from __future__ import absolute_import, division, print_function, unicode_literals
import logging
import pathlib
import sys
import colored_traceback.always
import torch
import options
from git_utils import log_git_info
from deepgsb import DeepGSB
from mfg import MFG
from rich.console import Console
from rich.logging import RichHandler
from options import Options
def setup_logger(log_dir: pathlib.Path) -> None:
log_dir.mkdir(exist_ok=True, parents=True)
log_file = open(log_dir / "log.txt", "w")
file_console = Console(file=log_file, width=150)
logging.basicConfig(
level=logging.INFO,
format="%(message)s",
datefmt="[%X]",
force=True,
handlers=[RichHandler(), RichHandler(console=file_console)],
)
def run(opt: Options):
log = logging.getLogger(__name__)
log.info("=======================================================")
log.info(" Deep Generalized Schrodinger Bridge ")
log.info("=======================================================")
log.info("Command used:\n{}".format(" ".join(sys.argv)))
mfg = MFG(opt)
deepgsb = DeepGSB(opt, mfg)
deepgsb.train(opt)
def main():
print("setting configurations...")
opt = options.set()
run_dir = pathlib.Path("results") / opt.dir
setup_logger(run_dir)
log_git_info(run_dir)
if not opt.cpu:
with torch.cuda.device(opt.gpu):
run(opt)
else:
run(opt)
if __name__ == "__main__":
main()