-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.py
68 lines (55 loc) · 2.62 KB
/
model.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
""" USIN model definition.
Author: Rui Cao
"""
import torch.nn as nn
import MinkowskiEngine as ME
import torch.nn.functional as F
from models.resunet14 import MinkUNet14D
class SuctionNet(nn.Module):
def __init__(self, feature_dim=256):
super().__init__()
self.feature_dim = feature_dim
self.backbone = MinkUNet14D(in_channels=3, out_channels=self.feature_dim, D=3)
self.suction_scoring = SuctionScoringNet(feature_dim=self.feature_dim)
def forward(self, end_points):
seed_xyz = end_points['point_clouds'] # use all sampled point cloud, B*Ns*3
B, point_num, _ = seed_xyz.shape # batch _size
# point-wise features
coordinates_batch = end_points['coors']
features_batch = end_points['feats']
mink_input = ME.SparseTensor(features_batch, coordinates=coordinates_batch)
seed_features = self.backbone(mink_input).F
seed_features = seed_features[end_points['quantize2original']].view(B, point_num, -1).transpose(1, 2)
end_points = self.suction_scoring(seed_features, end_points)
return end_points
class SuctionScoringNet(nn.Module):
def __init__(self, feature_dim):
super().__init__()
self.in_dim = feature_dim
self.conv_scoring = nn.Conv1d(self.in_dim, 1, 1)
def forward(self, seed_features, end_points):
suction_score = self.conv_scoring(seed_features) # (B, 3, num_seed)
end_points['score_pred'] = suction_score[:, 0]
return end_points
class SuctionNet_prob(nn.Module):
def __init__(self, feature_dim=256):
super().__init__()
self.feature_dim = feature_dim
self.backbone = MinkUNet14D(in_channels=3, out_channels=self.feature_dim, D=3)
self.score_head = nn.Conv1d(self.feature_dim, 1, 1)
self.sigma_head = nn.Conv1d(self.feature_dim, 1, 1)
def forward(self, end_points):
seed_xyz = end_points['point_clouds'] # use all sampled point cloud, B*Ns*3
B, point_num, _ = seed_xyz.shape # batch _size
# point-wise features
coordinates_batch = end_points['coors']
features_batch = end_points['feats']
mink_input = ME.SparseTensor(features_batch, coordinates=coordinates_batch)
seed_features = self.backbone(mink_input).F
seed_features = seed_features[end_points['quantize2original']].view(B, point_num, -1).transpose(1, 2)
score = self.score_head(seed_features)
sigma = self.sigma_head(seed_features)
sigma = F.softplus(sigma)
end_points['score_pred'] = score.squeeze(1)
end_points['sigma_pred'] = sigma.squeeze(1)
return end_points