-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_run.py
53 lines (47 loc) · 1.51 KB
/
test_run.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
import os
import random
import torch
import torch.nn as nn
import torch.backends.cudnn as cudnn
import torch.optim as optim
import torch.utils.data
import torchvision
import datetime
from ts_dataset import TSDataset
from tensorboardX import SummaryWriter
from models.recurrent_models import LSTMGenerator, LSTMDiscriminator
from models.convolutional_models import CausalConvGenerator, CausalConvDiscriminator
from tsgan import TSGANSynthetiser
import yaml
#load config file
path_to_yaml = 'tsgan_configuration.yml'
try:
with open(path_to_yaml, 'r') as file:
config = yaml.safe_load(file)
except Exception:
print('Error reading the config file')
#Create writer for tensorboard
date = datetime.datetime.now().strftime("%d-%m-%y_%H:%M")
run_name = f"{config['run_tag']}_{date}" if config['run_tag'] != '' else date
#log_dir_name = os.path.join(config['logdir'], run_name)
log_dir_name = config['logdir']
writer = SummaryWriter(log_dir_name)
try:
os.makedirs(config['outf'])
except OSError:
pass
try:
os.makedirs(config['imf'])
except OSError:
pass
fit = config['fit']
sample_new_data = config['sample_new_data']
tsgan = TSGANSynthetiser(path_to_yaml, writer)
if fit:
print('****************************** Fitting ******************************')
tsgan.fit()
elif sample_new_data:
print('****************************** Sampling ******************************')
sample = tsgan.sample_data()
else:
print('****************************** No valid option selected ******************************')