-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.py
74 lines (49 loc) · 1.62 KB
/
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
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
64
65
66
67
68
69
70
71
72
73
74
import torch
import torch.nn as nn
class resnet18(nn.Module):
def __init__(self):
super(resnet18, self).__init__()
self.backbone = torch.hub.load('pytorch/vision:v0.9.0', 'resnet18', pretrained=True)
self.ending_layer = nn.Sequential(
nn.Linear(1000,3),
nn.Softmax()
)
def forward(self, x):
x = self.backbone(x)
x = self.ending_layer(x)
return x
class resnext50(nn.Module):
def __init__(self):
super(resnext50, self).__init__()
self.backbone = torch.hub.load('pytorch/vision:v0.9.0', 'resnext50_32x4d', pretrained=True)
self.ending_layer = nn.Sequential(
nn.Linear(1000,3),
nn.Softmax()
)
def forward(self, x):
x = self.backbone(x)
x = self.ending_layer(x)
return x
class cnn(nn.Module):
def __init__(self):
super(cnn, self).__init__()
self.cnn_layers = nn.Sequential(
nn.Conv2d(3, 64, 3, 1, 1), #[32,128,128]
nn.ReLU(),
nn.MaxPool2d(2, 2, 0), #[32,128,128]
nn.Conv2d(64, 128, 3, 1, 1),
nn.ReLU(),
nn.MaxPool2d(2, 2, 0), #[64,64,64]
nn.Conv2d(128, 256, 3, 1, 1),
nn.ReLU(),
nn.MaxPool2d(2, 2, 0), #[128,32,32]
nn.AdaptiveAvgPool2d((1, 1)),
)
self.fc_layers = nn.Sequential(
nn.Linear(256,3)
)
def forward(self, x):
x = self.cnn_layers(x)
x = x.flatten(1)
x = self.fc_layers(x)
return x