-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConvNet.py
42 lines (32 loc) · 1.13 KB
/
ConvNet.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
39
40
41
42
from torch import nn
import torch
import torch.nn.functional as F
import sys
# directory reach
# sys.path.append('../kan_convolutional')
class ConvNet(nn.Module):
def __init__(self):
super(ConvNet, self).__init__()
self.conv1 = nn.Conv2d(1, 8, kernel_size=5, padding='same')
# self.conv2 = nn.Conv2d(8, 8, kernel_size=5, padding='same')
self.conv3 = nn.Conv2d(8, 16, kernel_size=3, padding='same')
# self.conv4 = nn.Conv2d(16, 16, kernel_size=3, padding='same')
self.maxpool = nn.MaxPool2d(kernel_size=2, stride=2)
self.dropout1 = nn.Dropout(0.25)
self.dropout2 = nn.Dropout(0.25)
self.dropout3 = nn.Dropout(0.5)
self.fc1 = nn.Linear(16*16*16, 256)
self.fc2 = nn.Linear(256, 2)
def forward(self, x):
x = F.relu(self.conv1(x))
x = self.maxpool(x)
x = self.dropout1(x)
x = F.relu(self.conv3(x))
x = self.maxpool(x)
x = self.dropout2(x)
x = torch.flatten(x, 1)
x = F.relu(self.fc1(x))
x = self.dropout3(x)
x = self.fc2(x)
x = F.log_softmax(x, dim=1)
return x