-
Notifications
You must be signed in to change notification settings - Fork 1
/
training.py
49 lines (39 loc) · 1.25 KB
/
training.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
# to train and save a model
import random
import numpy as np
import pandas as pd
import torch
import utils
from dataset import data_prep
import encoding_utils as eutils
import VAE
import warnings
warnings.filterwarnings("ignore")
config = utils.get_config(print_dict = False)
seed = config["seed"]
torch.manual_seed(seed)
torch.cuda.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
np.random.seed(seed)
random.seed(seed)
torch.backends.cudnn.benchmark = False
torch.backends.cudnn.deterministic = True
# for dataloader
def seed_worker(seed):
worker_seed = torch.manual_seed(seed)
np.random.seed(worker_seed)
random.seed(worker_seed)
G = torch.Generator()
G.manual_seed(seed)
# loading of supervised learning dataset
dataset = pd.read_csv(config["original_dataset"])
# loading of unsupervised learning dataset
undataset = pd.read_csv(config["augmented_dataset"])
train_dataloader, test_dataloader = data_prep(dataset, undataset)
# VAE
model = VAE.load_VAE(pretrained = False)
optimizer = torch.optim.Adam(model.parameters(), lr=0.0001)
model.train()
VAE.train(model = model, optimizer = optimizer,
train_dataloader = train_dataloader, test_dataloader = test_dataloader,
figures = False)