-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvolutional_nn.py
More file actions
30 lines (24 loc) · 874 Bytes
/
convolutional_nn.py
File metadata and controls
30 lines (24 loc) · 874 Bytes
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
import torch.nn as nn
import torch.nn.functional as F
class ConvolutionalNN(nn.Module):
def __init__(self):
super(ConvolutionalNN, self).__init__()
self.layer1 = nn.Sequential(
nn.Conv2d(1, 20, kernel_size=5, stride=1),
nn.ReLU(),
nn.MaxPool2d(kernel_size=2, stride=2))
self.layer2 = nn.Sequential(
nn.Conv2d(20, 20, kernel_size=5, stride=1),
nn.ReLU(),
nn.MaxPool2d(kernel_size=2, stride=2))
self.drop_out = nn.Dropout()
self.fc1 = nn.Linear(16280, 500)
self.fc2 = nn.Linear(500, 30)
def forward(self, x):
out = self.layer1(x)
out = self.layer2(out)
out = out.reshape(out.size(0), -1)
out = self.drop_out(out)
out = self.fc1(out)
out = self.fc2(out)
return F.log_softmax(out, dim=1)