-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmodel.py
More file actions
47 lines (38 loc) · 1.36 KB
/
Copy pathmodel.py
File metadata and controls
47 lines (38 loc) · 1.36 KB
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
import torch
import torch.nn as nn
import torch.nn.functional as F
'''
PointNet AutoEncoder
Learning Representations and Generative Models For 3D Point Clouds
https://arxiv.org/abs/1707.02392
'''
class PointCloudAE(nn.Module):
def __init__(self, point_size, latent_size):
super(PointCloudAE, self).__init__()
self.latent_size = latent_size
self.point_size = point_size
self.conv1 = torch.nn.Conv1d(3, 64, 1)
self.conv2 = torch.nn.Conv1d(64, 128, 1)
self.conv3 = torch.nn.Conv1d(128, self.latent_size, 1)
self.bn1 = nn.BatchNorm1d(64)
self.bn2 = nn.BatchNorm1d(128)
self.bn3 = nn.BatchNorm1d(self.latent_size)
self.dec1 = nn.Linear(self.latent_size,256)
self.dec2 = nn.Linear(256,256)
self.dec3 = nn.Linear(256,self.point_size*3)
def encoder(self, x):
x = F.relu(self.bn1(self.conv1(x)))
x = F.relu(self.bn2(self.conv2(x)))
x = self.bn3(self.conv3(x))
x = torch.max(x, 2, keepdim=True)[0]
x = x.view(-1, self.latent_size)
return x
def decoder(self, x):
x = F.relu(self.dec1(x))
x = F.relu(self.dec2(x))
x = self.dec3(x)
return x.view(-1, self.point_size, 3)
def forward(self, x):
x = self.encoder(x)
x = self.decoder(x)
return x