-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmynet.py
executable file
·95 lines (79 loc) · 2.41 KB
/
mynet.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
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.nn import Module
from torch.nn import Conv2d
from torch.nn import Linear
from torch.nn import MaxPool2d
from torch.nn import ReLU
from torch.nn import LogSoftmax
from torch import flatten
class deepAutoencoder(nn.Module):
def __init__(self, N, N1, N2, N3):
# N = input dim
super(deepAutoencoder, self).__init__()
self.flatten = nn.Flatten()
self.linear_relu_stack = nn.Sequential(
nn.Linear(N, N1),
nn.ReLU(),
nn.Linear(N1, N2),
nn.ReLU(),
nn.Linear(N2, N3),
nn.ReLU(),
nn.Linear(N3, N2),
nn.ReLU(),
nn.Linear(N2, N)
)
self.nonlinearity = nn.Sigmoid()
def forward(self, x):
x = self.flatten(x)
logits = self.linear_relu_stack(x)
#logits = self.nonlinearity(x)
return logits
class geomEncoder(nn.Module):
def __init__(self, N, N1, N2):
super(geomEncoder, self).__init__()
self.flatten = nn.Flatten()
self.linear_relu_stack = nn.Sequential(
nn.Linear(N, N1),
nn.ReLU(),
nn.Linear(N1, N2),
nn.ReLU(),
nn.Linear(N2, 4)
)
self.nonlinearity = nn.ReLU()
def forward(self, x):
x = self.flatten(x)
logits = self.linear_relu_stack(x)
#logits = self.nonlinearity(x)
return logits
class UnifiedNet(nn.Module):
def __init__(self, N, N1, N2, N3, M1, M2):
super(UnifiedNet, self).__init__()
self.flatten = nn.Flatten()
self.shape_encoder = nn.Sequential(
nn.Linear(N, N1),
nn.ReLU(),
nn.Linear(N1, N2),
nn.ReLU(),
nn.Linear(N2, N3),
)
self.geom_encoder = nn.Sequential(
nn.Linear(N, M1),
nn.ReLU(),
nn.Linear(M1, M2),
nn.ReLU(),
nn.Linear(M2, 4)
)
self.decoder = nn.Sequential(
nn.Linear(N3 + 4, N2),
nn.ReLU(),
nn.Linear(N2, N)
)
def forward(self, x):
x = self.flatten(x)
logits1 = self.shape_encoder(x)
logits2 = self.geom_encoder(x)
x = torch.cat((logits1, logits2), dim=1)
res = self.decoder(x).reshape(8,1,64,64)
return res