-
Notifications
You must be signed in to change notification settings - Fork 1
/
models_def.py
58 lines (44 loc) · 1.8 KB
/
models_def.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
class res_block(nn.Module):
def __init__(self, num_neurons: int = 1024, use_batchnorm: bool = False):
super(res_block, self).__init__()
self.use_batchnorm = use_batchnorm
self.l1 = nn.Linear(num_neurons, num_neurons)
self.bn1 = nn.BatchNorm1d(num_neurons)
self.l2 = nn.Linear(num_neurons, num_neurons)
self.bn2 = nn.BatchNorm1d(num_neurons)
def forward(self, x):
inp = x
x = nn.LeakyReLU()(self.l1(x))
if self.use_batchnorm:
x = self.bn1(x)
x = nn.LeakyReLU()(self.l2(x))
if self.use_batchnorm:
x = self.bn2(x)
x += inp
return x
class DepthAngleEstimator(nn.Module):
def __init__(self, use_batchnorm=False, num_joints=16):
super(DepthAngleEstimator, self).__init__()
self.upscale = nn.Linear(2*num_joints, 1024)
self.res_common = res_block(use_batchnorm=use_batchnorm)
self.res_pose1 = res_block(use_batchnorm=use_batchnorm)
self.res_pose2 = res_block(use_batchnorm=use_batchnorm)
self.res_angle1 = res_block(use_batchnorm=use_batchnorm)
self.res_angle2 = res_block(use_batchnorm=use_batchnorm)
self.depth = nn.Linear(1024, num_joints)
self.angles = nn.Linear(1024, 1)
#self.angles.bias.data[1] = 10.0
def forward(self, x):
x_inp = x
x = self.upscale(x)
x = nn.LeakyReLU()(self.res_common(x))
# pose path
xd = nn.LeakyReLU()(self.res_pose1(x))
xd = nn.LeakyReLU()(self.res_pose2(xd))
xd = self.depth(xd)
# depth path
xa = nn.LeakyReLU()(self.res_angle1(x))
xa = nn.LeakyReLU()(self.res_angle2(xa))
xa = self.angles(xa)
return xd, xa