-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
63 lines (58 loc) · 2.05 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
56
57
58
59
60
61
62
63
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Jan 17 01:10:42 2020
@author: aims
"""
import torch.nn as nn
import torch.nn.functional as F
class CNN(nn.Module):
def __init__(self, input_size, n_feature, output_size):
super(CNN, self).__init__()
self.n_feature = n_feature
self.conv1 = nn.Conv2d(in_channels=3, out_channels=n_feature, kernel_size=5)
self.conv2 = nn.Conv2d(n_feature, n_feature, kernel_size=5)
self.fc1 = nn.Linear(n_feature*53*53, 50)
self.fc2 = nn.Linear(50, 2)
def forward(self, x, verbose=False):
x = self.conv1(x)
x = F.relu(x)
x = F.max_pool2d(x, kernel_size=2)
x = self.conv2(x)
x = F.relu(x)
x = F.max_pool2d(x, kernel_size=2)
x = x.view(-1, self.n_feature*53*53)
x = self.fc1(x)
x = F.relu(x)
x = self.fc2(x)
x = F.log_softmax(x, dim=1)
return x
class deepCNN(nn.Module):
def __init__(self, input_size, n_feature, output_size):
super(deepCNN, self).__init__()
self.n_feature = n_feature
self.conv1 = nn.Conv2d(in_channels=3, out_channels=n_feature, kernel_size=5)
self.conv2 = nn.Conv2d(n_feature, 2**2*n_feature, kernel_size=7)
self.conv3 = nn.Conv2d(2**2*n_feature, 2**2*n_feature, kernel_size=2)
self.conv4 = nn.Conv2d(2**2*n_feature, n_feature, kernel_size=5)
self.fc1 = nn.Linear(n_feature*10*10, 50)
self.fc2 = nn.Linear(50, 2)
def forward(self, x, verbose=False):
x = self.conv1(x)
x = F.relu(x)
x = F.max_pool2d(x, kernel_size=2)
x = self.conv2(x)
x = F.relu(x)
x = F.max_pool2d(x, kernel_size=2)
x = self.conv3(x)
x = F.relu(x)
x = F.max_pool2d(x, kernel_size=2)
x = self.conv4(x)
x = F.relu(x)
x = F.max_pool2d(x, kernel_size=2)
x = x.view(-1, self.n_feature*10*10)
x = self.fc1(x)
x = F.relu(x)
x = self.fc2(x)
x = F.log_softmax(x, dim=1)
return x