-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVFN.py
99 lines (96 loc) · 3.08 KB
/
VFN.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import argparse
import os
import shutil
import time
import numpy as np
import torch
import torch.nn as nn
import torch.optim as optim
from torch.autograd import Variable
import torch.nn.functional as F
class VFN(nn.Module):
def __init__(self):
super(VFN, self).__init__()
self.downsample1 = nn.Sequential(
nn.Conv3d(4, 16, kernel_size=3, stride=1, padding=1, bias=True),
nn.BatchNorm3d(16),
nn.ReLU(),
nn.Conv3d(16, 16, kernel_size=3, stride=1, padding=1, bias=True),
nn.BatchNorm3d(16),
nn.ReLU(),
nn.Conv3d(16, 16, kernel_size=3, stride=1, padding=1, bias=True),
nn.BatchNorm3d(16),
nn.ReLU(),
nn.MaxPool3d(2)
)
self.downsample2 = nn.Sequential(
nn.Conv3d(16, 32, kernel_size=3, stride=1, padding=1, bias=True),
nn.BatchNorm3d(32),
nn.ReLU(),
nn.Conv3d(32, 32, kernel_size=3, stride=1, padding=1, bias=True),
nn.BatchNorm3d(32),
nn.ReLU(),
nn.Conv3d(32, 32, kernel_size=3, stride=1, padding=1, bias=True),
nn.BatchNorm3d(32),
nn.ReLU(),
nn.MaxPool3d(2)
)
self.downsample3 = nn.Sequential(
nn.Conv3d(32, 64, kernel_size=3, stride=1, padding=1, bias=True),
nn.BatchNorm3d(64),
nn.ReLU(),
nn.Conv3d(64, 64, kernel_size=3, stride=1, padding=1, bias=True),
nn.BatchNorm3d(64),
nn.ReLU(),
nn.Conv3d(64, 64, kernel_size=3, stride=1, padding=1, bias=True),
nn.BatchNorm3d(64),
nn.ReLU(),
nn.MaxPool3d(2),
nn.Conv3d(64, 64, kernel_size=3, stride=1, padding=1, bias=True),
nn.BatchNorm3d(64),
nn.ReLU(),
)
self.upsample1 = nn.Sequential(
nn.ConvTranspose3d(64, 32, kernel_size=4, stride=2, padding=1, bias=True),
nn.BatchNorm3d(32),
nn.ReLU(),
nn.Conv3d(32, 32, kernel_size=3, stride=1, padding=1, bias=True),
nn.BatchNorm3d(32),
nn.ReLU(),
)
self.upsample2 = nn.Sequential(
nn.ConvTranspose3d(32, 16, kernel_size=4, stride=2, padding=1, bias=True),
nn.BatchNorm3d(16),
nn.ReLU(),
nn.Conv3d(16, 16, kernel_size=3, stride=1, padding=1, bias=True),
nn.BatchNorm3d(16),
nn.ReLU(),
)
self.upsample3 = nn.Sequential(
nn.ConvTranspose3d(16, 4, kernel_size=4, stride=2, padding=1, bias=True),
nn.BatchNorm3d(4),
nn.ReLU(),
nn.Conv3d(4, 4, kernel_size=3, stride=1, padding=1, bias=True),
nn.BatchNorm3d(4),
nn.ReLU(),
)
self.output = nn.Sequential(
nn.Conv3d(4, 1, kernel_size=1, stride=1, padding=0, bias=True),
nn.BatchNorm3d(1),
nn.Sigmoid()
)
def forward(self, x):
res0 = x
x = self.downsample1(x)
res1 = x
x = self.downsample2(x)
res2 = x
x = self.downsample3(x)
x = self.upsample1(x)
x = res2 + x
x = self.upsample2(x)
x = res1 + x
x = self.upsample3(x)
x = res0 + x
x = self.output(x)
return x