-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathmodel.py
58 lines (44 loc) · 2.73 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
import torch.nn as nn
import torch
import numpy as np
import torch.nn.functional as F
from util import PointNetSetAbstraction,PointNetFeaturePropogation,FlowEmbedding,PointNetSetUpConv
class FlowNet3D(nn.Module):
def __init__(self,args):
super(FlowNet3D,self).__init__()
self.sa1 = PointNetSetAbstraction(npoint=1024, radius=0.5, nsample=16, in_channel=3, mlp=[32,32,64], group_all=False)
self.sa2 = PointNetSetAbstraction(npoint=256, radius=1.0, nsample=16, in_channel=64, mlp=[64, 64, 128], group_all=False)
self.sa3 = PointNetSetAbstraction(npoint=64, radius=2.0, nsample=8, in_channel=128, mlp=[128, 128, 256], group_all=False)
self.sa4 = PointNetSetAbstraction(npoint=16, radius=4.0, nsample=8, in_channel=256, mlp=[256,256,512], group_all=False)
self.fe_layer = FlowEmbedding(radius=10.0, nsample=64, in_channel = 128, mlp=[128, 128, 128], pooling='max', corr_func='concat')
self.su1 = PointNetSetUpConv(nsample=8, radius=2.4, f1_channel = 256, f2_channel = 512, mlp=[], mlp2=[256, 256])
self.su2 = PointNetSetUpConv(nsample=8, radius=1.2, f1_channel = 128+128, f2_channel = 256, mlp=[128, 128, 256], mlp2=[256])
self.su3 = PointNetSetUpConv(nsample=8, radius=0.6, f1_channel = 64, f2_channel = 256, mlp=[128, 128, 256], mlp2=[256])
self.fp = PointNetFeaturePropogation(in_channel = 256+3, mlp = [256, 256])
self.conv1 = nn.Conv1d(256, 128, kernel_size=1, bias=False)
self.bn1 = nn.BatchNorm1d(128)
self.conv2=nn.Conv1d(128, 3, kernel_size=1, bias=True)
def forward(self, pc1, pc2, feature1, feature2):
l1_pc1, l1_feature1 = self.sa1(pc1, feature1)
l2_pc1, l2_feature1 = self.sa2(l1_pc1, l1_feature1)
l1_pc2, l1_feature2 = self.sa1(pc2, feature2)
l2_pc2, l2_feature2 = self.sa2(l1_pc2, l1_feature2)
_, l2_feature1_new = self.fe_layer(l2_pc1, l2_pc2, l2_feature1, l2_feature2)
l3_pc1, l3_feature1 = self.sa3(l2_pc1, l2_feature1_new)
l4_pc1, l4_feature1 = self.sa4(l3_pc1, l3_feature1)
l3_fnew1 = self.su1(l3_pc1, l4_pc1, l3_feature1, l4_feature1)
l2_fnew1 = self.su2(l2_pc1, l3_pc1, torch.cat([l2_feature1, l2_feature1_new], dim=1), l3_fnew1)
l1_fnew1 = self.su3(l1_pc1, l2_pc1, l1_feature1, l2_fnew1)
l0_fnew1 = self.fp(pc1, l1_pc1, feature1, l1_fnew1)
x = F.relu(self.bn1(self.conv1(l0_fnew1)))
sf = self.conv2(x)
return sf
if __name__ == '__main__':
import os
import torch
os.environ["CUDA_VISIBLE_DEVICES"] = '0'
input = torch.randn((8,3,2048))
label = torch.randn(8,16)
model = FlowNet3D()
output = model(input,input)
print(output.size())