-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbackbone.py
67 lines (58 loc) · 1.84 KB
/
backbone.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
import torch.nn as nn
class mnist_net(nn.Module):
def __init__(self):
super(mnist_net, self).__init__()
self.conv1 = nn.Conv2d(3, 64, kernel_size=5)
self.bn1 = nn.BatchNorm2d(64)
self.relu1 = nn.ReLU()
self.mp1 = nn.MaxPool2d(2,stride=2)
self.conv2 = nn.Conv2d(64, 48, kernel_size=5)
self.relu2 = nn.ReLU()
self.mp2= nn.MaxPool2d(2,stride=2)
self.__in_features = 48*4*4
def forward(self, x):
x = self.conv1(x)
x = self.relu1(x)
x = self.mp1(x)
x = self.conv2(x)
x = self.relu2(x)
x = self.mp2(x)
x = x.view(x.size(0), -1)
return x
def output_num(self):
return self.__in_features
class dbbhm_net(nn.Module):
def __init__(self):
super(dbbhm_net, self).__init__()
self.conv1 = nn.Conv2d(4, 64, kernel_size=5)
self.bn1 = nn.BatchNorm2d(64)
self.lrelu1 = nn.LeakyReLU()
self.mp1 = nn.MaxPool2d(2)
self.conv2 = nn.Conv2d(64, 50, kernel_size=5)
self.bn2 = nn.BatchNorm2d(50)
self.lrelu2 = nn.LeakyReLU()
self.mp2= nn.MaxPool2d(2)
self.conv3 = nn.Conv2d(50, 50, kernel_size=3)
self.bn3 = nn.BatchNorm2d(50)
self.lrelu3 = nn.LeakyReLU()
self.mp3= nn.MaxPool2d(2)
self.__in_features = 50*5*5
def forward(self, x):
x = self.conv1(x)
x = self.bn1(x)
x = self.lrelu1(x)
x = self.mp1(x)
x = self.conv2(x)
x = self.bn2(x)
x = self.lrelu2(x)
x = self.mp2(x)
x = self.conv3(x)
x = self.bn3(x)
x = self.lrelu3(x)
x = self.mp3(x)
x = x.view(x.size(0), -1)
return x
def output_num(self):
return self.__in_features
network_dict = {"mnist_net": mnist_net,
"dbbhm_net": dbbhm_net}