-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcnn_model.py
31 lines (28 loc) · 1.04 KB
/
cnn_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
25
26
27
28
29
30
31
import torch.nn as nn
import torch.nn.functional as F
import torch
class Net(nn.Module):
def __init__(self):
super(Net, self).__init__()
self.conv1 = nn.Conv2d(in_channels = 3,
out_channels = 6,
kernel_size = 3,
stride = 1,
padding = 0)
self.pool = nn.MaxPool2d(2, 2)
self.conv2 = nn.Conv2d(in_channels = 6,
out_channels = 16,
kernel_size = 3,
stride = 1,
padding = 0)
self.fc1 = nn.Linear(16 * 30 * 30, 128)
self.fc2 = nn.Linear(128, 64)
self.fc3 = nn.Linear(64, 2)
def forward(self, x):
x = self.pool(F.relu(self.conv1(x)))
x = self.pool(F.relu(self.conv2(x)))
x = x.view(-1, 16 * 30 * 30)
x = torch.sigmoid(self.fc1(x))
x = torch.sigmoid(self.fc2(x))
x = F.softmax(self.fc3(x))
return x