jstetina commited on
Commit
da34ece
1 Parent(s): 05cd0b4

Add: training script

Browse files
Files changed (1) hide show
  1. train.py +26 -0
train.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import torch.nn as nn
3
+ import torch.optim as optim
4
+ from torch.utils.data import DataLoader, Dataset
5
+ from torchvision import datasets, transforms
6
+ import matplotlib.pyplot as plt
7
+ import numpy as np
8
+
9
+ from model import ColorNet
10
+
11
+
12
+ transform = transforms.Compose([
13
+ transforms.ToTensor()
14
+ ])
15
+
16
+ train_dataset = datasets.CIFAR10(root='./data', train=True, transform=transform, download=True)
17
+ test_dataset = datasets.CIFAR10(root='./data', train=False, transform=transform, download=True)
18
+
19
+ train_loader = DataLoader(train_dataset, batch_size=64, shuffle=True)
20
+ test_loader = DataLoader(test_dataset, batch_size=64, shuffle=False)
21
+
22
+ model = ColorNet()
23
+ criterion = nn.MSELoss()
24
+ optimizer = optim.Adam(model.parameters(), lr=1e-3)
25
+
26
+ model.train_model(model, train_loader, criterion, optimizer, num_epochs=10)