-
Notifications
You must be signed in to change notification settings - Fork 110
/
main.py
executable file
·39 lines (32 loc) · 967 Bytes
/
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
#!/usr/bin/env python3
import sys
import os
from core.Engine import Engine
from core.Config import Config
from core.Log import log
import tensorflow as tf
def init_log(config):
log_dir = config.dir("log_dir", "logs")
model = config.string("model")
filename = log_dir + model + ".log"
verbosity = config.int("log_verbosity", 3)
log.initialize([filename], [verbosity], [])
def main(_):
assert len(sys.argv)==2 or len(sys.argv)==3, "usage: main.py <config> <optional_config_string>"
config_path = sys.argv[1]
assert os.path.exists(config_path), config_path
try:
if len(sys.argv)==3:
config = Config(config_path, sys.argv[2])
else:
config = Config(config_path)
except ValueError as e:
print("Malformed config file:", e)
return -1
init_log(config)
# dump the config into the log
print(open(config_path).read(), file=log.v4)
engine = Engine(config)
engine.run()
if __name__ == '__main__':
tf.app.run(main)