-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
62 lines (47 loc) · 2.37 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
import argparse
import torch
from torch import nn
from modules.data_preparation import load_data, prepare_data
from modules.model import Model, load_model
from modules.train import training_loop
from torch.utils.data import DataLoader
# from torch.utils.data import Dataset
# from torchvision.transforms import Compose, RandomHorizontalFlip, RandomVerticalFlip, Lambda, ToTensor
# import numpy as np
def main(num_epochs):
loss_fn = nn.CrossEntropyLoss()
learning_rate = 0.0001
batch_size = 1150
patience = 4
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
print("Using ", device)
boards, labels = load_data()
train_boards, train_labels, validation_boards, validation_labels = prepare_data(boards, labels)
train_boards = torch.from_numpy(train_boards)
train_labels = torch.from_numpy(train_labels)
validation_boards = torch.from_numpy(validation_boards)
validation_labels = torch.from_numpy(validation_labels)
train_loader = DataLoader(list(zip(train_boards, train_labels)), shuffle=True, batch_size=batch_size)
validation_loader = DataLoader(list(zip(validation_boards, validation_labels)), shuffle=True, batch_size=batch_size)
GoBot = load_model("model.pth", device)
optim = torch.optim.Adam(GoBot.parameters(), learning_rate)
training_loop(GoBot, device, train_loader, validation_loader, optim, loss_fn, num_epochs, patience)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('--num_epochs', type=int, default=10, help='number of epochs')
args = parser.parse_args()
main(args.num_epochs)
else:
loss_fn = nn.CrossEntropyLoss()
learning_rate = 0.0001
batch_size = 1150
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
print("Using ", device)
boards, labels = load_data()
train_boards, train_labels, validation_boards, validation_labels = prepare_data(boards, labels)
train_boards = torch.from_numpy(train_boards)
train_labels = torch.from_numpy(train_labels)
validation_boards = torch.from_numpy(validation_boards)
validation_labels = torch.from_numpy(validation_labels)
train_loader = DataLoader(list(zip(train_boards, train_labels)), shuffle=True, batch_size=batch_size)
validation_loader = DataLoader(list(zip(validation_boards, validation_labels)), shuffle=True, batch_size=batch_size)