-
Notifications
You must be signed in to change notification settings - Fork 0
/
cnn.py
40 lines (30 loc) · 1017 Bytes
/
cnn.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
import numpy as np
import torch
from torch import nn
from torchvision import transforms
import torchvision.datasets as dsets
from torch.autograd import Variable
train_dataset = dsets.MNIST(root='./mnist_data',
train=True,
transform=transforms.ToTensor(),
download=True)
test_dataset = dsets.MNIST(root='./mnist_data',
train=False,
transform=transforms.ToTensor(),
download=True)
batch_size = 100
n_iters = 3000
num_epochs = int(n_iters / (len(train_dataset) / batch_size))
train_loader = torch.utils.data.DataLoader(dataset=train_dataset,
batch_size=batch_size,
shuffle=True)
test_loader = torch.utils.data.DataLoader(dataset=test_dataset,
batch_size=batch_size,
shuffle=False)
class CNNModel(nn.Module):
def __init__(self, input_size, hidden_dim, num_classes):
super(CNNModel, self).__init__()
# Convolution 1
self.cnn1 = nn.Conv2d()
self.relu1= nn.ReLU()
# TODO: Remaining layers