-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCNN.py
60 lines (53 loc) · 1.55 KB
/
CNN.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
import torch.nn as nn
class CNN(nn.Module):
def __init__(
self,
num_input_channels=15,
conv_filters1=4,
conv_filters2=8,
conv_filters3=4,
):
super(CNN, self).__init__()
self.conv1 = nn.Conv2d(
in_channels=num_input_channels,
out_channels=conv_filters1,
kernel_size=3,
padding=1,
)
self.relu1 = nn.ReLU()
self.pool1 = nn.MaxPool2d(kernel_size=2, stride=2)
self.conv2 = nn.Conv2d(
in_channels=conv_filters1,
out_channels=conv_filters2,
kernel_size=3,
padding=1,
)
self.relu2 = nn.ReLU()
self.pool2 = nn.MaxPool2d(kernel_size=2, stride=2)
self.conv3 = nn.Conv2d(
in_channels=conv_filters2,
out_channels=conv_filters3,
kernel_size=3,
padding=1,
)
self.relu3 = nn.ReLU()
self.pool3 = nn.MaxPool2d(kernel_size=2, stride=2)
self.conv4 = nn.Conv2d(
in_channels=conv_filters3, out_channels=1, kernel_size=3, padding=1
)
self.upsample = nn.Upsample(
size=(256, 256), mode="bilinear", align_corners=False
)
def forward(self, x):
c = self.conv1(x)
x = self.relu1(c)
x = self.pool1(x)
x = self.conv2(x)
x = self.relu2(x)
x = self.pool2(x)
x = self.conv3(x)
x = self.relu3(x)
x = self.pool3(x)
x = self.conv4(x)
x = self.upsample(x)
return x