-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmodels.py
55 lines (47 loc) · 1.82 KB
/
models.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
47
48
49
50
51
52
53
54
55
import torch
import torch.nn as nn
import torch.nn.functional as F
from operator import itemgetter
class CNNModel1(nn.Module):
def __init__(self, fully_layer_1, fully_layer_2, drop_rate):
super(CNNModel1, self).__init__()
self.conv1 = nn.Conv2d(3, 32, 2)
self.bn1 = nn.BatchNorm2d(32)
self.conv2 = nn.Conv2d(32, 64, 2)
self.bn2 = nn.BatchNorm2d(64)
self.conv3 = nn.Conv2d(64, 128, 2)
self.bn3 = nn.BatchNorm2d(128)
self.conv4 = nn.Conv2d(128, 64, 2)
self.bn4 = nn.BatchNorm2d(64)
self.conv5 = nn.Conv2d(64, 32, 2)
self.bn5 = nn.BatchNorm2d(32)
self.pool = nn.MaxPool2d(2, 2)
self.drop_rate = drop_rate
#self.dropout = nn.Dropout(drop_rate)
self.fc1 = nn.Linear(#32*5*5,
32*8*8, fully_layer_1)
self.fc2 = nn.Linear(fully_layer_1, fully_layer_2)
self.fc3 = nn.Linear(fully_layer_2, 2)
def forward(self, x):
#print(x.shape)
x = self.pool(F.relu(self.bn1(self.conv1(x))))
#print(x.shape)
x = self.pool(F.relu(self.bn2(self.conv2(x))))
#print(x.shape)
x = self.pool(F.relu(self.bn3(self.conv3(x))))
#print(x.shape)
x = self.pool(F.relu(self.bn4(self.conv4(x))))
#print(x.shape)
x = self.pool(F.relu(self.bn5(self.conv5(x))))
#print(x.shape)
x = x.view(-1, #32*5*5) # For 200x200 images
32*8*8) # For 300x300 images
"""
x = self.dropout(F.relu(self.fc1(x))
x = self.dropout(F.relu(self.fc2(x))
x = self.dropout(x)"""
x = F.dropout(F.relu(self.fc1(x)), self.drop_rate, self.training)
x = F.dropout(F.relu(self.fc2(x)), self.drop_rate, self.training)
x = self.fc3(x)
return x
# TODO: Create other models