-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclassificatorCNN.py
46 lines (37 loc) · 1.25 KB
/
classificatorCNN.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
43
44
45
46
import torch.nn as nn
class CustomClassifier(nn.Module):
def __init__(self):
super(CustomClassifier, self).__init__()
self.conv1 = nn.Conv2d(in_channels=3, out_channels=64, kernel_size=3)
self.relu1 = nn.ReLU()
self.pool1 = nn.MaxPool2d(2)
self.dropout1 = nn.Dropout(0.15)
self.conv2 = nn.Conv2d(in_channels=64, out_channels=64, kernel_size=3)
self.relu2 = nn.ReLU()
self.pool2 = nn.MaxPool2d(2)
self.conv3 = nn.Conv2d(in_channels=64, out_channels=128, kernel_size=3)
self.relu3 = nn.ReLU()
self.fc1 = nn.Linear(100352, 128)
self.relu4 = nn.ReLU()
self.fc2 = nn.Linear(128, 256)
self.relu5 = nn.ReLU()
self.fc3 = nn.Linear(256, 1)
self.sigmoid = nn.Sigmoid()
def forward(self, x):
x = self.conv1(x)
x = self.relu1(x)
x = self.pool1(x)
x = self.dropout1(x)
x = self.conv2(x)
x = self.relu2(x)
x = self.pool2(x)
x = self.conv3(x)
x = self.relu3(x)
x = x.view(x.size(0), -1) # Flatten
x = self.fc1(x)
x = self.relu4(x)
x = self.fc2(x)
x = self.relu5(x)
x = self.fc3(x)
x = self.sigmoid(x)
return x