-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.py
24 lines (22 loc) · 1 KB
/
model.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
class Net(nn.Module):
#This defines the structure of the NN.
def __init__(self): #init defines the model for each blocks
super(Net, self).__init__()
self.conv1 = nn.Conv2d(1, 32, kernel_size=3, bias=False)
self.conv2 = nn.Conv2d(32, 64, kernel_size=3, bias=False)
self.conv3 = nn.Conv2d(64, 128, kernel_size=3, bias=False)
self.conv4 = nn.Conv2d(128, 256, kernel_size=3, bias=False)
self.fc1 = nn.Linear(4096, 50)
self.fc2 = nn.Linear(50, 10)
#This defines the structure with activation functions
def forward(self, x):
x = F.relu(self.conv1(x), 2)
x = F.relu(F.max_pool2d(self.conv2(x), 2))
x = F.relu(self.conv3(x), 2)
x = F.relu(F.max_pool2d(self.conv4(x), 2))
x = x.view(-1, 4096)
x = F.relu(self.fc1(x))
x = self.fc2(x)
return F.log_softmax(x, dim=1)
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
#Checks for cuda and then gives the device