-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfcnet.py
More file actions
79 lines (69 loc) · 1.6 KB
/
fcnet.py
File metadata and controls
79 lines (69 loc) · 1.6 KB
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
75
76
77
78
79
import torch.nn as nn
import torch
import torch.nn.functional as F
torch.set_printoptions(profile='full')
def conv_block1(inChannels):
return nn.Sequential(
nn.Conv3d(inChannels, 128, 2),
nn.BatchNorm3d(128),
nn.ReLU(),
nn.Dropout(p=0.4))
def conv_block2(inChannels):
return nn.Sequential(
nn.Conv3d(inChannels, 128, 2),
nn.BatchNorm3d(128),
nn.ReLU())
def conv_block3(inChannels):
return nn.Sequential(
nn.Conv3d(inChannels, 128, 2),
nn.BatchNorm3d(128),
nn.ReLU(),
nn.MaxPool3d(2),
nn.Dropout(p=0.2))
class FNet(nn.Module):
def __init__(self):
super(FNet, self).__init__()
self.encoder = nn.Sequential(
conv_block1(1),
conv_block2(128),
conv_block1(128),
conv_block2(128))
def forward(self, x):
x = self.encoder(x)
#return x.view(x.size(0), -1)
return x
class CNet(nn.Module):
def __init__(self):
super(CNet, self).__init__()
'''
self.cnet = nn.Sequential(
conv_block3(256),
conv_block3(128))
'''
self.layer1 = nn.Sequential(
nn.Conv3d(256, 128, 2),
nn.BatchNorm3d(128),
nn.ReLU(),
nn.MaxPool3d(2),
nn.Dropout(p=0.2))
self.layer2 = nn.Sequential(
nn.Conv3d(128, 128, 2),
nn.BatchNorm3d(128),
nn.ReLU(),
nn.MaxPool3d(2),
nn.Dropout(p=0.2))
self.fc1 = nn.Linear(1024, 64)
self.fc2 = nn.Linear(64, 1)
def forward(self, x):
#x = self.cnet(x)
#print(next(self.fc1.parameters()).is_cuda)
#print(next(self.fc2.parameters()).is_cuda)
x = self.layer1(x)
x = self.layer2(x)
#x = x.view(80, -1)
x = x.view(160, -1) #For 10 shot
#print(x.device)
x = self.fc1(x)
x = self.fc2(x)
x = torch.sigmoid(x)
return x