-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnet.py
54 lines (49 loc) · 1.57 KB
/
net.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
from torch import nn
import torch
class MyNet(nn.Module):
def __init__(self):
super(MyNet, self).__init__()
self.layers = nn.Sequential(
nn.Conv2d(3, 11, 3),
nn.ReLU(),
nn.MaxPool2d(3),
nn.Conv2d(11, 22, 3),
nn.ReLU(),
nn.MaxPool2d(2),
nn.Conv2d(22, 32, 3),
nn.ReLU(),
nn.MaxPool2d(2),
nn.Conv2d(32, 64, 3),
nn.ReLU(),
nn.Conv2d(64, 128, 3),
nn.ReLU(),
)
self.label_layer = nn.Sequential( # 二分类 是否
nn.Conv2d(128, 1, 19),
nn.ReLU()
)
self.position_layer = nn.Sequential( # 位置回归
nn.Conv2d(128, 4, 19),
nn.ReLU()
)
self.sort_layer = nn.Sequential( # 多分类
nn.Conv2d(128, 20, 19),
nn.ReLU()
)
def forward(self, x):
out = self.layers(x)
label = self.label_layer(out)
label = torch.squeeze(label, dim=2)
label = torch.squeeze(label, dim=2)
label = torch.squeeze(label, dim=1)
position = self.position_layer(out)
position= torch.squeeze(position, dim=2)
position = torch.squeeze(position, dim=2)
sort = self.sort_layer(out)
sort = torch.squeeze(sort, dim=2)
sort = torch.squeeze(sort, dim=2)
return label, position, sort
if __name__ == '__main__':
net = MyNet()
x = torch.randn(3, 3, 300, 300)
print(net(x)[2].shape)