carsten12 commited on
Commit
0e2593d
·
verified ·
1 Parent(s): bdf016c

Create joint_definitions.py

Browse files
Files changed (1) hide show
  1. joint_definitions.py +123 -0
joint_definitions.py ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import smplx
2
+ import torch
3
+ import os
4
+
5
+ #from https://meshcapade.wiki/SMPL
6
+
7
+ SMPL_NUM_JOINTS = 24
8
+
9
+ SMPL_IND2JOINT = {
10
+ 0: 'pelvis',
11
+ 1: 'left_hip',
12
+ 2: 'right_hip',
13
+ 3: 'spine1',
14
+ 4: 'left_knee',
15
+ 5: 'right_knee',
16
+ 6: 'spine2',
17
+ 7: 'left_ankle',
18
+ 8: 'right_ankle',
19
+ 9: 'spine3',
20
+ 10: 'left_foot',
21
+ 11: 'right_foot',
22
+ 12: 'neck',
23
+ 13: 'left_collar',
24
+ 14: 'right_collar',
25
+ 15: 'head',
26
+ 16: 'left_shoulder',
27
+ 17: 'right_shoulder',
28
+ 18: 'left_elbow',
29
+ 19: 'right_elbow',
30
+ 20: 'left_wrist',
31
+ 21: 'right_wrist',
32
+ 22: 'left_hand',
33
+ 23: 'right_hand'
34
+ }
35
+
36
+ SMPL_JOINT2IND = {name:ind for ind,name in SMPL_IND2JOINT.items()}
37
+
38
+
39
+
40
+
41
+ SMPLX_NUM_JOINTS = 55
42
+
43
+ SMPLX_IND2JOINT = {
44
+ 0: 'pelvis',
45
+ 1: 'left_hip',
46
+ 2: 'right_hip',
47
+ 3: 'spine1',
48
+ 4: 'left_knee',
49
+ 5: 'right_knee',
50
+ 6: 'spine2',
51
+ 7: 'left_ankle',
52
+ 8: 'right_ankle',
53
+ 9: 'spine3',
54
+ 10: 'left_foot',
55
+ 11: 'right_foot',
56
+ 12: 'neck',
57
+ 13: 'left_collar',
58
+ 14: 'right_collar',
59
+ 15: 'head',
60
+ 16: 'left_shoulder',
61
+ 17: 'right_shoulder',
62
+ 18: 'left_elbow',
63
+ 19: 'right_elbow',
64
+ 20: 'left_wrist',
65
+ 21: 'right_wrist',
66
+ 22: 'jaw',
67
+ 23: 'left_eye',
68
+ 24: 'right_eye',
69
+ 25: 'left_index1',
70
+ 26: 'left_index2',
71
+ 27: 'left_index3',
72
+ 28: 'left_middle1',
73
+ 29: 'left_middle2',
74
+ 30: 'left_middle3',
75
+ 31: 'left_pinky1',
76
+ 32: 'left_pinky2',
77
+ 33: 'left_pinky3',
78
+ 34: 'left_ring1',
79
+ 35: 'left_ring2',
80
+ 36: 'left_ring3',
81
+ 37: 'left_thumb1',
82
+ 38: 'left_thumb2',
83
+ 39: 'left_thumb3',
84
+ 40: 'right_index1',
85
+ 41: 'right_index2',
86
+ 42: 'right_index3',
87
+ 43: 'right_middle1',
88
+ 44: 'right_middle2',
89
+ 45: 'right_middle3',
90
+ 46: 'right_pinky1',
91
+ 47: 'right_pinky2',
92
+ 48: 'right_pinky3',
93
+ 49: 'right_ring1',
94
+ 50: 'right_ring2',
95
+ 51: 'right_ring3',
96
+ 52: 'right_thumb1',
97
+ 53: 'right_thumb2',
98
+ 54: 'right_thumb3'
99
+ }
100
+
101
+ SMPLX_JOINT2IND = {name:ind for ind,name in SMPLX_IND2JOINT.items()}
102
+
103
+ def get_joint_regressor(body_model_type, body_model_root, gender="MALE", num_thetas=24):
104
+ '''
105
+ Extract joint regressor from SMPL body model
106
+ :param body_model_type: str of body model type (smpl or smplx, etc.)
107
+ :param body_model_root: str of location of folders where smpl/smplx
108
+ inside which .pkl models
109
+
110
+ Return:
111
+ :param model.J_regressor: torch.tensor (23,N) used to
112
+ multiply with body model to get
113
+ joint locations
114
+ '''
115
+
116
+ model = smplx.create(model_path=body_model_root,
117
+ model_type=body_model_type,
118
+ gender=gender,
119
+ use_face_contour=False,
120
+ num_betas=10,
121
+ body_pose=torch.zeros((1, num_thetas-1 * 3)),
122
+ ext='pkl')
123
+ return model.J_regressor