-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
99 lines (81 loc) · 3 KB
/
models.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 torch
import torch.nn as nn
import torch.nn.functional as F
# ------ TO DO ------
class cls_model(nn.Module):
def __init__(self, num_classes=3):
super(cls_model, self).__init__()
self.conv1 = nn.Conv1d(3, 64, 1)
self.conv2 = nn.Conv1d(64, 64, 1)
self.conv3 = nn.Conv1d(64, 128, 1)
self.conv4 = nn.Conv1d(128, 1024, 1)
self.bn1 = nn.BatchNorm1d(64)
self.bn2 = nn.BatchNorm1d(64)
self.bn3 = nn.BatchNorm1d(128)
self.bn4 = nn.BatchNorm1d(1024)
self.fc = nn.Sequential(
nn.Linear(1024, 512),
nn.BatchNorm1d(512),
nn.ReLU(),
nn.Dropout(p=0.3),
nn.Linear(512, 256),
nn.BatchNorm1d(256),
nn.ReLU(),
nn.Dropout(p=0.3),
nn.Linear(256, num_classes)
)
def forward(self, points):
'''
points: tensor of size (B, N, 3)
, where B is batch size and N is the number of points per object (N=10000 by default)
output: tensor of size (B, num_classes)
'''
points = points.transpose(1, 2)
out = F.relu(self.bn1(self.conv1(points)))
out = F.relu(self.bn2(self.conv2(out)))
out = F.relu(self.bn3(self.conv3(out)))
out = F.relu(self.bn4(self.conv4(out)))
# max pool
out = torch.amax(out, dim=-1)
out = self.fc(out)
return out
# ------ TO DO ------
class seg_model(nn.Module):
def __init__(self, num_seg_classes = 6):
super(seg_model, self).__init__()
self.conv1 = nn.Conv1d(3, 64, 1)
self.conv2 = nn.Conv1d(64, 64, 1)
self.conv3 = nn.Conv1d(64, 128, 1)
self.conv4 = nn.Conv1d(128, 1024, 1)
self.bn1 = nn.BatchNorm1d(64)
self.bn2 = nn.BatchNorm1d(64)
self.bn3 = nn.BatchNorm1d(128)
self.bn4 = nn.BatchNorm1d(1024)
self.point_layer = nn.Sequential(
nn.Conv1d(1088, 512, 1),
nn.BatchNorm1d(512),
nn.ReLU(),
nn.Conv1d(512, 256, 1),
nn.BatchNorm1d(256),
nn.ReLU(),
nn.Conv1d(256, 128, 1),
nn.BatchNorm1d(128),
nn.ReLU(),
nn.Conv1d(128, num_seg_classes, 1),
)
def forward(self, points):
'''
points: tensor of size (B, N, 3)
, where B is batch size and N is the number of points per object (N=10000 by default)
output: tensor of size (B, N, num_seg_classes)
'''
N = points.shape[1]
points = points.transpose(1, 2)
local_out = F.relu(self.bn1(self.conv1(points)))
local_out = F.relu(self.bn2(self.conv2(local_out)))
global_out = F.relu(self.bn3(self.conv3(local_out)))
global_out = F.relu(self.bn4(self.conv4(global_out)))
global_out = torch.amax(global_out, dim=-1, keepdims=True).repeat(1, 1, N)
out = torch.cat((local_out, global_out), dim=1)
out = self.point_layer(out).transpose(1, 2)
return out