-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.py
84 lines (59 loc) · 1.83 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
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
from fire import Fire
from config_maker import get_config
from trainer import Trainer
from utils import *
from data_prepare import *
from model import SiameseNet
def print_status(string):
line = '*' * 40
print(line + " " + string + " " + line)
# only train and validation
def train(config=None, trainer=None):
if config is None or trainer is None:
print(config, trainer)
config = get_config()
trainer = Trainer(config)
# Make directory for save logs and model
prepare_dirs(config)
# Check resume data
if config.resume:
try:
print(f"load saved config data of model number {config.num_model}")
load_config(config)
except ValueError:
print("[!] config data already exist. Either change the model number, or delete the json file and rerun.")
return
else:
save_config(config)
# train model
print_status("Train Start")
trainer.train()
# only test
def test(config=None, trainer=None):
if config is None or trainer is None:
config = get_config()
trainer = Trainer(config)
# test model
print_status("Test Start")
trainer.test()
# running all process. download data, data set, data loader, train, validation, test
def run():
download_data()
# Make options
config = get_config()
# Make Trainer
trainer = Trainer(config)
# train
train(config, trainer)
# test
test(config, trainer)
def download_data():
print("Download omniglot dataset...", end="")
download_omniglot_data()
print("Prepare dataset...", end="")
prepare_data()
print("DONE")
def print_parameters():
count_parameters(SiameseNet())
if __name__ == '__main__':
Fire({"run": run, "download-data": download_data, "train": train, "test": test, "param": print_parameters})