This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtraining_utils.py
48 lines (39 loc) · 1.48 KB
/
training_utils.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
"""
General methods used during model trainings.
TODO: Refactoring...
"""
import sweaty_net_2_outputs
from conv_gru import ConvGruCellPreConv
import torch
from torch import nn
import utils as utils
def init_type2_sweaty_gru(device, load_path, load_gru=''):
model = sweaty_net_2_outputs.SweatyNet1()
model.to(device)
if load_path != '':
print("Loading Sweaty")
model.load_state_dict(torch.load(load_path))
else:
raise Exception('Fine tuning the model, there should be a loading path.')
convGruModel = ConvGruCellPreConv(89, 1, device=device)
convGruModel.to(device)
if load_gru != '':
print('Loading gru, continuing training ...')
convGruModel.load_state_dict(torch.load(load_gru))
return model, convGruModel
def init_sweaty(device, load_path):
from SweatyNet1 import SweatyNet1
model = SweatyNet1()
model.to(device)
print(model)
if load_path != '':
print("Loading Sweaty")
model.load_state_dict(torch.load(load_path))
return model
def init_training_configs_for_conv_gru(batch_size, alpha):
criterion = nn.MSELoss()
# exp_lr_scheduler = lr_scheduler.StepLR(optimizer, step_size=10, gamma=0.1)
trainset = utils.SoccerBallDataset("data/train/data.csv", "data/train", downsample=4, alpha=alpha)
trainloader = torch.utils.data.DataLoader(trainset, batch_size=batch_size, shuffle=False, num_workers=2)
print("# examples: ", len(trainset))
return criterion, trainloader, trainset