-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCNNLearner.py
More file actions
34 lines (29 loc) · 898 Bytes
/
CNNLearner.py
File metadata and controls
34 lines (29 loc) · 898 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
28
29
30
31
32
33
34
import torch
import torch.nn as nn
import torch.nn.functional as F
# Using
class SubwayCNN(nn.Module):
def __init__(self):
super(SubwayCNN, self).__init__()
# Convolutional Features
self.features = nn.Sequential(
nn.Conv2d(1, 32, kernel_size=3, padding=1),
nn.Tanh(),
nn.AvgPool2d(kernel_size=2, stride=2),
nn.Conv2d(32, 16, kernel_size=3, padding=1),
nn.Tanh(),
nn.AvgPool2d(kernel_size=2, stride=2),
)
# Dense Neural Network
self.classifier = nn.Sequential(
nn.Linear(16 * 10 * 11, 128),
nn.ReLU(),
nn.Linear(128, 32),
nn.ReLU(),
nn.Linear(32, 5)
)
def forward(self, x):
x = self.features(x)
x = x.view(-1, 16 * 10 * 11) # Flatten
x = self.classifier(x)
return x