forked from danieltan07/dagmm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
67 lines (51 loc) · 2.05 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
import os
import argparse
from solver import Solver
from data_loader import get_loader
from torch.backends import cudnn
from utils import *
def str2bool(v):
return v.lower() in ('true')
def main(config):
# For fast training
cudnn.benchmark = True
# Create directories if not exist
mkdir(config.log_path)
mkdir(config.model_save_path)
data_loader = get_loader(config.data_path, batch_size=config.batch_size, mode=config.mode)
# Solver
solver = Solver(data_loader, vars(config))
if config.mode == 'train':
solver.train()
elif config.mode == 'test':
solver.test()
return solver
if __name__ == '__main__':
parser = argparse.ArgumentParser()
# Model hyper-parameters
parser.add_argument('--lr', type=float, default=1e-4)
# Training settings
parser.add_argument('--num_epochs', type=int, default=200)
parser.add_argument('--batch_size', type=int, default=1024)
parser.add_argument('--gmm_k', type=int, default=4)
parser.add_argument('--lambda_energy', type=float, default=0.1)
parser.add_argument('--lambda_cov_diag', type=float, default=0.005)
parser.add_argument('--pretrained_model', type=str, default=None)
# Misc
parser.add_argument('--mode', type=str, default='train', choices=['train', 'test'])
parser.add_argument('--use_tensorboard', type=str2bool, default=True)
# Path
parser.add_argument('--data_path', type=str, default='kdd_cup.npz')
parser.add_argument('--log_path', type=str, default='./dagmm/logs')
parser.add_argument('--model_save_path', type=str, default='./dagmm/models')
# Step size
parser.add_argument('--log_step', type=int, default=10)
parser.add_argument('--sample_step', type=int, default=194)
parser.add_argument('--model_save_step', type=int, default=194)
config = parser.parse_args()
args = vars(config)
print('------------ Options -------------')
for k, v in sorted(args.items()):
print('%s: %s' % (str(k), str(v)))
print('-------------- End ----------------')
main(config)