-
Notifications
You must be signed in to change notification settings - Fork 7
/
model.py
51 lines (46 loc) · 1.74 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
from torch import nn
import torch
class ClassificationModel3D(nn.Module):
"""The model we use in the paper."""
def __init__(self, dropout=0.4, dropout2=0.4):
nn.Module.__init__(self)
self.Conv_1 = nn.Conv3d(1, 8, 3)
self.Conv_1_bn = nn.BatchNorm3d(8)
self.Conv_1_mp = nn.MaxPool3d(2)
self.Conv_2 = nn.Conv3d(8, 16, 3)
self.Conv_2_bn = nn.BatchNorm3d(16)
self.Conv_2_mp = nn.MaxPool3d(3)
self.Conv_3 = nn.Conv3d(16, 32, 3)
self.Conv_3_bn = nn.BatchNorm3d(32)
self.Conv_3_mp = nn.MaxPool3d(2)
self.Conv_4 = nn.Conv3d(32, 64, 3)
self.Conv_4_bn = nn.BatchNorm3d(64)
self.Conv_4_mp = nn.MaxPool3d(3)
self.dense_1 = nn.Linear(4800, 128)
# self.dense_1 = nn.Linear(5120, 128)
self.dense_2 = nn.Linear(128, 5)
# self.dense_2 = nn.Linear(128, 4)
self.relu = nn.ReLU()
self.dropout = nn.Dropout(dropout)
self.dropout2 = nn.Dropout(dropout2)
def forward(self, x):
x = self.relu(self.Conv_1_bn(self.Conv_1(x)))
x = self.Conv_1_mp(x)
x = self.relu(self.Conv_2_bn(self.Conv_2(x)))
x = self.Conv_2_mp(x)
x = self.relu(self.Conv_3_bn(self.Conv_3(x)))
x = self.Conv_3_mp(x)
x = self.relu(self.Conv_4_bn(self.Conv_4(x)))
x = self.Conv_4_mp(x)
x = x.view(x.size(0), -1)
x = self.dropout(x)
x = self.relu(self.dense_1(x))
x = self.dropout2(x)
x = self.dense_2(x)
return x
if __name__ == "__main__":
model = ClassificationModel3D()
test_tensor = torch.ones(4, 1, 166, 256, 256)
# 用形状和实际数据集相同的tenser测试网络是否可用
output = model(test_tensor)
print(output.shape)