Skip to content

Commit 7ce1a62

Browse files
committed
handle smplh
1 parent a7a3675 commit 7ce1a62

6 files changed

+88
-19
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
model_files/
2+
.vscode/
23
*.obj
34

45
# Byte-compiled / optimized / DLL files

armatures.py

+45-7
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
class MANOArmature:
44
n_joints = 16
55

6-
# indices of extended joints (finger tips)
7-
joints_ext = [333, 444, 672, 555, 744]
6+
# indices of extended keypoints
7+
keypoints_ext = [333, 444, 672, 555, 744]
88

9-
n_keypoints = n_joints + len(joints_ext)
9+
n_keypoints = n_joints + len(keypoints_ext)
1010

1111
root = 0
1212

@@ -19,18 +19,19 @@ class MANOArmature:
1919
'L0', 'L1', 'L2', #9
2020
'R0', 'R1', 'R2', #12
2121
'T0', 'T1', 'T2', #15
22-
'I3', 'M3', 'L3', 'R3', 'T3' #20, tips are manually added (not in MANO)
22+
# extended
23+
'I3', 'M3', 'L3', 'R3', 'T3' #20
2324
]
2425

2526

2627
class SMPLArmature:
2728
n_joints = 24
2829

29-
# indices of extended joints (limb ends)
30+
# indices of extended keypoints (limb ends)
3031
# lfinger, rfinger, ltoe, rtoe, head-top
31-
joints_ext = [2446, 5907, 3216, 6618, 411]
32+
keypoints_ext = [2446, 5907, 3216, 6618, 411]
3233

33-
n_keypoints = n_joints + len(joints_ext)
34+
n_keypoints = n_joints + len(keypoints_ext)
3435

3536
labels = [
3637
'pelvis',
@@ -48,4 +49,41 @@ class SMPLArmature:
4849
'lelbow', 'relbow',
4950
'lwrist', 'rwrist',
5051
'lhand', 'rhand'
52+
# extended
53+
'lfinger_tip', 'rfinger_tip', 'ltoe_tip', 'r_toe_tip', 'head_top'
54+
]
55+
56+
57+
class SMPLHArmature:
58+
n_joints = 52
59+
60+
# indices of extended keypoints (limb ends)
61+
keypoints_ext = [
62+
2746, 2320, 2446, 2557, 2674,
63+
6191, 5781, 5907, 6018, 6135,
64+
3216, 6618, 411
65+
]
66+
67+
n_keypoints = n_joints + len(keypoints_ext)
68+
69+
labels = [
70+
'pelvis',
71+
'llegroot', 'rlegroot',
72+
'lowerback',
73+
'lknee', 'rknee',
74+
'upperback',
75+
'lankle', 'rankle',
76+
'thorax',
77+
'ltoes', 'rtoes',
78+
'lowerneck',
79+
'lclavicle', 'rclavicle',
80+
'upperneck',
81+
'larmroot', 'rarmroot',
82+
'lelbow', 'relbow',
83+
'lwrist', 'rwrist',
84+
'lhand', 'rhand'
85+
# extended
86+
'left-thumb', 'li', 'lm', 'lr', 'll',
87+
'rt', 'ri', 'rm', 'rr', 'rl',
88+
'ltoe-tip', 'rtoe-tip', 'heat-top'
5189
]

config.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
MANO_MODEL_PATH = './model_files/mano_left.pkl'
22
SMPL_MODEL_PATH = './model_files/smpl_female.pkl'
3+
SMPLH_MODEL_PATH = './model_files/smplh_neutral'
34

45
OFFICIAL_MANO_PATH = './model_files/mano_v1_2/mano_v1_2/models/MANO_LEFT.pkl'
56
OFFICIAL_SMPL_PATH = './model_files/SMPL_python_v.1.0.0/smpl/models/basicModel_f_lbs_10_207_0_v1.0.0.pkl'
7+
OFFICIAL_SMPLH_PATH = './model_files/smplh/neutral/model.npz'

example.py

+16-8
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,33 @@
44
import numpy as np
55
import config
66

7-
n_shape = 10
7+
88
np.random.seed(20160923)
9+
pose_glb = np.zeros([1, 3])
10+
911

1012
########################## mano settings #########################
1113
# n_pose = 12
1214
# n_shape = 10
13-
# np.random.seed(20160923)
1415
# pose_pca = np.random.normal(size=n_pose)
15-
# pose_glb = np.zeros([1, 3])
1616
# shape = np.random.normal(size=n_shape)
1717
# mesh = KinematicModel(config.MANO_MODEL_PATH, MANOArmature, scale=1000)
1818

1919

2020
########################## smpl settings ##########################
21-
n_pose = 23 * 3
21+
# n_pose = 23 * 3
22+
# n_shape = 10
23+
# pose_pca = np.random.uniform(-0.2, 0.2, size=n_pose)
24+
# shape = np.random.normal(size=n_shape)
25+
# mesh = KinematicModel(config.SMPL_MODEL_PATH, SMPLArmature, scale=10)
26+
27+
28+
########################## smpl-h settings ##########################
29+
n_pose = 51 * 3
30+
n_shape = 16
2231
pose_pca = np.random.uniform(-0.2, 0.2, size=n_pose)
23-
pose_glb = np.zeros([1, 3])
2432
shape = np.random.normal(size=n_shape)
25-
mesh = KinematicModel(config.SMPL_MODEL_PATH, SMPLArmature, scale=10)
33+
mesh = KinematicModel(config.SMPLH_MODEL_PATH, SMPLHArmature, scale=10)
2634

2735

2836
########################## solving example ############################
@@ -36,13 +44,13 @@
3644

3745
shape_est, pose_pca_est, pose_glb_est = wrapper.decode(params_est)
3846

39-
print('-----------------------------------------------------------------------')
47+
print('----------------------------------------------------------------------')
4048
print('ground truth parameters')
4149
print('pose pca coefficients:', pose_pca)
4250
print('pose global rotation:', pose_glb)
4351
print('shape: pca coefficients:', shape)
4452

45-
print('-----------------------------------------------------------------------')
53+
print('----------------------------------------------------------------------')
4654
print('estimated parameters')
4755
print('pose pca coefficients:', pose_pca_est)
4856
print('pose global rotation:', pose_glb_est)

models.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def __init__(self, model_path, armature, scale=1):
2222

2323
self.parents = params['parents']
2424

25-
self.n_shape_params = 10
25+
self.n_shape_params = self.mesh_shape_basis.shape[-1]
2626
self.scale = scale
2727

2828
self.armature = armature
@@ -37,7 +37,7 @@ def __init__(self, model_path, armature, scale=1):
3737
self.J_regressor_ext = \
3838
np.zeros([self.armature.n_keypoints, self.J_regressor.shape[1]])
3939
self.J_regressor_ext[:self.armature.n_joints] = self.J_regressor
40-
for i, v in enumerate(self.armature.joints_ext):
40+
for i, v in enumerate(self.armature.keypoints_ext):
4141
self.J_regressor_ext[i + self.armature.n_joints, v] = 1
4242

4343
self.update()
@@ -170,7 +170,7 @@ class KinematicPCAWrapper():
170170
def __init__(self, core, n_pose=12):
171171
self.core = core
172172
self.n_pose = n_pose
173-
self.n_shape = 10
173+
self.n_shape = core.n_shape_params
174174
self.n_glb = 3
175175
self.n_params = self.n_pose + self.n_shape + self.n_glb
176176

prepare_model.py

+21-1
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,25 @@ def prepare_smpl_model():
4444
pickle.dump(params, f)
4545

4646

47+
def prepare_smplh_model():
48+
data = np.load(OFFICIAL_SMPLH_PATH)
49+
params = {
50+
# SMPL does not provide pose PCA
51+
'pose_pca_basis': np.eye(51 * 3),
52+
'pose_pca_mean': np.zeros(51 * 3),
53+
'J_regressor': data['J_regressor'],
54+
'skinning_weights': np.array(data['weights']),
55+
# pose blend shape
56+
'mesh_pose_basis': np.array(data['posedirs']),
57+
'mesh_shape_basis': np.array(data['shapedirs']),
58+
'mesh_template': np.array(data['v_template']),
59+
'faces': np.array(data['f']),
60+
'parents': data['kintree_table'][0].tolist(),
61+
}
62+
params['parents'][0] = None
63+
with open(SMPLH_MODEL_PATH, 'wb') as f:
64+
pickle.dump(params, f)
65+
66+
4767
if __name__ == '__main__':
48-
prepare_smpl_model()
68+
prepare_smplh_model()

0 commit comments

Comments
 (0)